diff --git a/openjpa-integration/daytrader/pom.xml b/openjpa-integration/daytrader/pom.xml index 7d888a608..14b5b6459 100644 --- a/openjpa-integration/daytrader/pom.xml +++ b/openjpa-integration/daytrader/pom.xml @@ -39,11 +39,11 @@ ${project.basedir}${file.separator}..${file.separator}..${file.separator}openjpa-project${file.separator}checkstyle.xml ${project.basedir}${file.separator}..${file.separator}..${file.separator}openjpa-project${file.separator}suppressions.xml 2.2-SNAPSHOT - 10 + 10 5 2 10000 - MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait} + MaxTotal=${dbcp.maxTotal},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait} diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java index 34ee5ebf2..6808f460d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java @@ -486,7 +486,7 @@ public interface JDBCConfiguration * Create an instance of the {@link DriverDataSource} to use * for creating a {@link DataSource} from a JDBC {@link Driver}. */ - DriverDataSource newDriverDataSourceInstance(); + DataSource newDriverDataSourceInstance(); /** * The plugin string for the {@link SchemaFactory} to use to provide diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java index 178c680a6..9fdb6dd3f 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java @@ -36,7 +36,6 @@ import org.apache.openjpa.jdbc.kernel.UpdateManager; import org.apache.openjpa.jdbc.meta.MappingDefaults; import org.apache.openjpa.jdbc.meta.MappingRepository; import org.apache.openjpa.jdbc.schema.DataSourceFactory; -import org.apache.openjpa.jdbc.schema.DriverDataSource; import org.apache.openjpa.jdbc.schema.SchemaFactory; import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.jdbc.sql.DBDictionaryFactory; @@ -246,9 +245,8 @@ public class JDBCConfigurationImpl driverDataSourcePlugin = addPlugin("jdbc.DriverDataSource", false); aliases = new String[]{ - "auto", "org.apache.openjpa.jdbc.schema.AutoDriverDataSource", "simple", "org.apache.openjpa.jdbc.schema.SimpleDriverDataSource", - "dbcp", "org.apache.openjpa.jdbc.schema.DBCPDriverDataSource", + "dbcp", "org.apache.commons.dbcp2.BasicDataSource" }; driverDataSourcePlugin.setAliases(aliases); driverDataSourcePlugin.setDefault(aliases[0]); @@ -688,9 +686,9 @@ public class JDBCConfigurationImpl } @Override - public DriverDataSource newDriverDataSourceInstance() { - return (DriverDataSource) driverDataSourcePlugin. - instantiate(DriverDataSource.class, this); + public DataSource newDriverDataSourceInstance() { + return (DataSource) driverDataSourcePlugin. + instantiate(DataSource.class, this); } @Override diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java deleted file mode 100644 index 90b828fbd..000000000 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openjpa.jdbc.schema; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Properties; - -/** - * Automatic Commons DBCP pooling or Simple non-pooling driver data source. - * If the commons-dbcp packages are on the class path, then they will be used, - * else it will fall back to non-DBCP mode. - */ -public class AutoDriverDataSource - extends DBCPDriverDataSource { - - @Override - public Connection getConnection(Properties props) throws SQLException { - // if we're using managed transactions, or user specified a DBCP driver - // or DBCP is not on the classpath, then use SimpleDriver - if (conf == null || conf.isTransactionModeManaged() || conf.isConnectionFactoryModeManaged() || - !isDBCPLoaded(getClassLoader())) { - return getSimpleConnection(props); - } else { - // use DBCPDriverDataSource - return getDBCPConnection(props); - } - } -} diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java deleted file mode 100644 index c2d28e442..000000000 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openjpa.jdbc.schema; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Iterator; -import java.util.Locale; -import java.util.Properties; - -import javax.sql.DataSource; - -import org.apache.openjpa.jdbc.conf.JDBCConfiguration; -import org.apache.openjpa.lib.conf.Configurable; -import org.apache.openjpa.lib.conf.Configuration; -import org.apache.openjpa.lib.conf.Configurations; -import org.apache.openjpa.lib.util.Closeable; - -/** - * Commons DBCP basic pooling driver data source. - * The commons-dbcp packages must be on the class path for this plugin to work, - * as it WILL NOT fall back to non-DBCP mode if they are missing. For automatic - * usage of Commons DBCP when available, use AutoDriverDataSource instead. - */ -public class DBCPDriverDataSource -extends SimpleDriverDataSource implements Configurable, Closeable { - - private static String DBCPPACKAGENAME = "org.apache.commons.dbcp2"; - private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp2.BasicDataSource"; - private static Class _dbcpClass; - private static Boolean _dbcpAvail; - private static RuntimeException _dbcpEx; - - protected JDBCConfiguration conf; - private DataSource _ds; - - @Override - public Connection getConnection(Properties props) throws SQLException { - return getDBCPConnection(props); - } - - @Override - public void close() throws SQLException { - try { - if (_ds != null) { - if (isDBCPLoaded(getClassLoader())) { - ((org.apache.commons.dbcp2.BasicDataSource)_dbcpClass.cast(_ds)).close(); - } - } - } catch (Exception e) { - // no-op - } catch (Throwable t) { - // no-op - } finally { - _ds = null; - } - } - - protected Connection getDBCPConnection(Properties props) throws SQLException { - Connection con = getDBCPDataSource(props).getConnection(); - if (con == null) { - throw new SQLException(_eloc.get("dbcp-ds-null", - DBCPBASICDATASOURCENAME, getConnectionDriverName(), getConnectionURL()).getMessage()); - } - return con; - } - - protected DataSource getDBCPDataSource(Properties props) { - if (isDBCPLoaded(getClassLoader())) { - if (_ds == null) { - try { - Properties dbcpProps = updateDBCPProperties(props); - _ds = (DataSource) Configurations.newInstance(DBCPBASICDATASOURCENAME, conf, - dbcpProps, getClassLoader()); - } catch (Exception e) { - _dbcpEx = new RuntimeException(_eloc.get("driver-null", DBCPBASICDATASOURCENAME).getMessage(), e); - } - return _ds; - } else { - return _ds; - } - } else { - // user choose DBCP, so fail if it isn't on the classpath - if (_dbcpEx == null) - _dbcpEx = new RuntimeException(_eloc.get("driver-null", DBCPBASICDATASOURCENAME).getMessage()); - throw _dbcpEx; - } - } - - /** - * This method should not throw an exception, as it is called by - * AutoDriverDataSource to determine if user already specified - * to use Commons DBCP. - * @return true if ConnectionDriverName contains org.apache.commons.dbcp2, - * otherwise false - */ - protected boolean isDBCPDataSource() { - return (getConnectionDriverName() != null && - getConnectionDriverName().toLowerCase(Locale.ENGLISH).indexOf(DBCPPACKAGENAME) >= 0); - } - - /** - * This method should not throw an exception, as it is called by - * AutoDriverDataSource to determine if it should use DBCP or not - * based on if org.apache.commons.dbcp2.BasicDataSource can be loaded. - * @return true if Commons DBCP was found on the classpath, otherwise false - */ - static protected boolean isDBCPLoaded(ClassLoader cl) { - if (Boolean.TRUE.equals(_dbcpAvail) && (_dbcpClass != null)) { - return true; - } else if (Boolean.FALSE.equals(_dbcpAvail)) { - return false; - } else { - // first time checking, so try to load it - try { - _dbcpClass = Class.forName(DBCPBASICDATASOURCENAME, true, cl); - _dbcpAvail = Boolean.TRUE; - return true; - } catch (Exception e) { - _dbcpAvail = Boolean.FALSE; - // save exception details for later instead of throwing here - _dbcpEx = new RuntimeException(_eloc.get("driver-null", DBCPBASICDATASOURCENAME).getMessage(), e); - } - return _dbcpAvail.booleanValue(); - } - } - - /** - * Normalize properties for Commons DBCP. This should be done for every call from DataSourceFactory, - * as we do not have a pre-configured Driver to reuse. - * @param props - * @return updated properties - */ - private Properties updateDBCPProperties(Properties props) { - Properties dbcpProps = mergeConnectionProperties(props); - - // only perform the following check for the first connection attempt (_driverClassName == null), - // as multiple connections could be requested (like from SchemaTool) and isDBCPDriver() will be true - if (isDBCPDataSource()) { - String propDriver = hasProperty(dbcpProps, "driverClassName"); - if (propDriver == null || propDriver.trim().isEmpty()) { - // if user specified DBCP for the connectionDriverName, then make sure they supplied a DriverClassName - throw new RuntimeException(_eloc.get("connection-property-invalid", "DriverClassName", - propDriver).getMessage()); - } - propDriver = hasProperty(dbcpProps, "url"); - if (propDriver == null || propDriver.trim().isEmpty()) { - // if user specified DBCP for the connectionDriverName, then make sure they supplied a Url - throw new RuntimeException(_eloc.get("connection-property-invalid", "URL", - propDriver).getMessage()); - } - } else { - // set Commons DBCP expected DriverClassName to the original connection driver name - dbcpProps.setProperty(hasKey(dbcpProps, "driverClassName", "driverClassName"), getConnectionDriverName()); - // set Commons DBCP expected URL property - dbcpProps.setProperty(hasKey(dbcpProps, "url", "url"), getConnectionURL()); - } - - // Commons DBCP requires non-Null username/password values in the connection properties - if (hasKey(dbcpProps, "username") == null) { - if (getConnectionUserName() != null) - dbcpProps.setProperty("username", getConnectionUserName()); - else - dbcpProps.setProperty("username", ""); - } - // Commons DBCP requires non-Null username/password values in the connection properties - if (hasKey(dbcpProps, "password") == null) { - if (getConnectionPassword() != null) - dbcpProps.setProperty("password", getConnectionPassword()); - else - dbcpProps.setProperty("password", ""); - } - - // set some default properties for DBCP - if (hasKey(dbcpProps, "maxIdle") == null) { - dbcpProps.setProperty("maxIdle", "1"); - } - if (hasKey(dbcpProps, "minIdle") == null) { - dbcpProps.setProperty("minIdle", "0"); - } - if (hasKey(dbcpProps, "maxActive") == null) { - dbcpProps.setProperty("maxActive", "10"); - } - - return dbcpProps; - } - - /** - * Merge the passed in properties with a copy of the existing _connectionProperties - * @param props - * @return Merged properties - */ - private Properties mergeConnectionProperties(final Properties props) { - Properties mergedProps = new Properties(); - mergedProps.putAll(getConnectionProperties()); - - // need to map "user" to "username" for Commons DBCP - String uid = removeProperty(mergedProps, "user"); - if (uid != null) { - mergedProps.setProperty("username", uid); - } - - // now, merge in any passed in properties - if (props != null && !props.isEmpty()) { - for (Iterator itr = props.keySet().iterator(); itr.hasNext();) { - String key = (String)itr.next(); - String value = props.getProperty(key); - // need to map "user" to "username" for Commons DBCP - if ("user".equalsIgnoreCase(key)) { - key = "username"; - } - // case-insensitive search for existing key - String existingKey = hasKey(mergedProps, key); - if (existingKey != null) { - // update existing entry - mergedProps.setProperty(existingKey, value); - } else { - // add property to the merged set - mergedProps.setProperty(key, value); - } - } - } - return mergedProps; - } - - /** - * Case-insensitive search of the given properties for the given key. - * @param props - * @param key - * @return Key name as found in properties or null if it was not found. - */ - private String hasKey(Properties props, String key) { - return hasKey(props, key, null); - } - - /** - * Case-insensitive search of the given properties for the given key. - * @param props - * @param key - * @param defaultKey - * @return Key name as found in properties or the given defaultKey if it was not found. - */ - private String hasKey(Properties props, String key, String defaultKey) - { - if (props != null && key != null) { - for (Iterator itr = props.keySet().iterator(); itr.hasNext();) { - String entry = (String)itr.next(); - if (key.equalsIgnoreCase(entry)) - return entry; - } - } - return defaultKey; - } - - private String hasProperty(Properties props, String key) { - if (props != null && key != null) { - String entry = hasKey(props, key); - if (entry != null) - return props.getProperty(entry); - } - return null; - - } - - private String removeProperty(Properties props, String key) { - if (props != null && key != null) { - String entry = hasKey(props, key); - if (entry != null) - return (String)props.remove(entry); - } - return null; - } - - // Configurable interface methods - @Override - public void setConfiguration(Configuration conf) { - if (conf instanceof JDBCConfiguration) - this.conf = (JDBCConfiguration)conf; - } - - @Override - public void startConfiguration() { - // no-op - } - - @Override - public void endConfiguration() { - // no-op - } - -} - diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java index faae13fc7..d41f154d6 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java @@ -18,6 +18,7 @@ */ package org.apache.openjpa.jdbc.schema; +import java.lang.reflect.Method; import java.security.AccessController; import java.sql.Connection; import java.sql.Driver; @@ -56,7 +57,7 @@ import org.apache.openjpa.util.UserException; * @author Abe White */ public class DataSourceFactory { - + private static final String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp2.BasicDataSource"; private static final Localizer _loc = Localizer.forPackage(DataSourceFactory.class); protected static Localizer _eloc = Localizer.forPackage(DelegatingDataSource.class); @@ -85,27 +86,42 @@ public class DataSourceFactory { } if (Driver.class.isAssignableFrom(driverClass)) { - DriverDataSource ds = conf.newDriverDataSourceInstance(); - ds.setClassLoader(loader); - ds.setConnectionDriverName(driver); - ds.setConnectionProperties(Configurations. - parseProperties(props)); + DataSource rawDs = conf.newDriverDataSourceInstance(); + if (rawDs instanceof DriverDataSource) { + DriverDataSource ds = (DriverDataSource)rawDs; + ds.setClassLoader(loader); + ds.setConnectionDriverName(driver); + ds.setConnectionProperties(Configurations. + parseProperties(props)); - if (!factory2) { - ds.setConnectionFactoryProperties(Configurations. - parseProperties(conf.getConnectionFactoryProperties())); - ds.setConnectionURL(conf.getConnectionURL()); - ds.setConnectionUserName(conf.getConnectionUserName()); - ds.setConnectionPassword(conf.getConnectionPassword()); - } else { - ds.setConnectionFactoryProperties - (Configurations.parseProperties(conf. - getConnectionFactory2Properties())); - ds.setConnectionURL(conf.getConnection2URL()); - ds.setConnectionUserName(conf.getConnection2UserName()); - ds.setConnectionPassword(conf.getConnection2Password()); + if (!factory2) { + ds.setConnectionFactoryProperties(Configurations. + parseProperties(conf.getConnectionFactoryProperties())); + ds.setConnectionURL(conf.getConnectionURL()); + ds.setConnectionUserName(conf.getConnectionUserName()); + ds.setConnectionPassword(conf.getConnectionPassword()); + } else { + ds.setConnectionFactoryProperties + (Configurations.parseProperties(conf. + getConnectionFactory2Properties())); + ds.setConnectionURL(conf.getConnection2URL()); + ds.setConnectionUserName(conf.getConnection2UserName()); + ds.setConnectionPassword(conf.getConnection2Password()); + } + return ds; + } else if (DBCPBASICDATASOURCENAME.equals(rawDs.getClass().getName())) { + reflectiveCall(rawDs, "setDriverClassLoader", ClassLoader.class, loader); + reflectiveCall(rawDs, "setDriverClassName", String.class, driver); + reflectiveCall(rawDs, "setConnectionProperties", String.class, props); + + reflectiveCall(rawDs, "setUrl", String.class, factory2 + ? conf.getConnection2URL() : conf.getConnectionURL()); + reflectiveCall(rawDs, "setUsername", String.class, factory2 + ? conf.getConnection2UserName() : conf.getConnectionUserName()); + reflectiveCall(rawDs, "setPassword", String.class, factory2 + ? conf.getConnection2Password() : conf.getConnectionPassword()); + return rawDs; } - return ds; } // see if their driver name is actually a data source @@ -126,6 +142,12 @@ public class DataSourceFactory { throw new UserException(_loc.get("bad-driver", driver)).setFatal(true); } + private static void reflectiveCall(Object obj, String meth, Class valClass, Object value) throws Exception { + Class clazz = obj.getClass(); + Method method = clazz.getMethod(meth, valClass); + method.invoke(obj, value); + } + /** * Install listeners and base decorators. */ diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/event/TCPRemoteCommitProvider.java b/openjpa-kernel/src/main/java/org/apache/openjpa/event/TCPRemoteCommitProvider.java index 293dcf949..b7f8b9f92 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/event/TCPRemoteCommitProvider.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/event/TCPRemoteCommitProvider.java @@ -82,20 +82,20 @@ public class TCPRemoteCommitProvider // A map of listen ports to listeners in this JVM. We might // want to look into allowing same port, different interface -- // that is not currently possible in a single JVM. - private static final Map s_portListenerMap = new HashMap(); + private static final Map s_portListenerMap = new HashMap<>(); private long _id; private byte[] _localhost; private int _port = DEFAULT_PORT; - private int _maxActive = 2; + private int _maxTotal = 2; private int _maxIdle = 2; private int _recoveryTimeMillis = 15000; private TCPPortListener _listener; private BroadcastQueue _broadcastQueue = new BroadcastQueue(); - private final List _broadcastThreads = Collections.synchronizedList( - new LinkedList()); + private final List _broadcastThreads = Collections.synchronizedList( + new LinkedList<>()); - private ArrayList _addresses = new ArrayList(); + private List _addresses = new ArrayList<>(); private ReentrantLock _addressesLock; public TCPRemoteCommitProvider() @@ -144,17 +144,29 @@ public class TCPRemoteCommitProvider /** * The maximum number of sockets that this provider can * simetaneously open to each peer in the cluster. + * + * @deprecated please use {@link TCPRemoteCommitProvider#setMaxTotal(int)} instead */ + @Deprecated public void setMaxActive(int maxActive) { - _maxActive = maxActive; + log.warn("This method should not be used"); + _maxTotal = maxActive; + } + + /** + * The maximum total number of sockets that this provider can + * simetaneously open to each peer in the cluster. + */ + public void setMaxTotal(int maxTotal) { + _maxTotal = maxTotal; } /** * The maximum number of sockets that this provider can * simetaneously open to each peer in the cluster. */ - public int getMaxActive() { - return _maxActive; + public int getMaxTotal() { + return _maxTotal; } /** @@ -184,8 +196,7 @@ public class TCPRemoteCommitProvider // Notify the extra worker threads so they stop themselves // Threads will not end until they send another pk. for (int i = numBroadcastThreads; i < cur; i++) { - BroadcastWorkerThread worker = (BroadcastWorkerThread) - _broadcastThreads.remove(0); + BroadcastWorkerThread worker = _broadcastThreads.remove(0); worker.setRunning(false); } } else if (cur < numBroadcastThreads) { @@ -220,11 +231,11 @@ public class TCPRemoteCommitProvider _addressesLock.lock(); try { - for (Iterator iter = _addresses.iterator(); iter.hasNext();) { - ((HostAddress) iter.next()).close(); + for (Iterator iter = _addresses.iterator(); iter.hasNext();) { + iter.next().close(); } String[] toks = StringUtil.split(names, ";", 0); - _addresses = new ArrayList(toks.length); + _addresses = new ArrayList<>(toks.length); InetAddress localhost = InetAddress.getLocalHost(); String localhostName = localhost.getHostName(); @@ -285,7 +296,7 @@ public class TCPRemoteCommitProvider super.endConfiguration(); synchronized (s_portListenerMap) { // see if a listener exists for this port. - _listener = (TCPPortListener) s_portListenerMap.get + _listener = s_portListenerMap.get (String.valueOf(_port)); if (_listener == null || @@ -314,10 +325,10 @@ public class TCPRemoteCommitProvider _addressesLock.lock(); try { HostAddress curAddress; - for (Iterator iter = _addresses.iterator(); + for (Iterator iter = _addresses.iterator(); iter.hasNext();) { - curAddress = (HostAddress) iter.next(); - curAddress.setMaxActive(_maxActive); + curAddress = iter.next(); + curAddress.setMaxTotal(_maxTotal); curAddress.setMaxIdle(_maxIdle); } } @@ -368,8 +379,8 @@ public class TCPRemoteCommitProvider private void sendUpdatePacket(byte[] bytes) { _addressesLock.lock(); try { - for (Iterator iter = _addresses.iterator(); iter.hasNext();) { - ((HostAddress) iter.next()).sendUpdatePacket(bytes); + for (Iterator iter = _addresses.iterator(); iter.hasNext();) { + iter.next().sendUpdatePacket(bytes); } } finally { _addressesLock.unlock(); @@ -396,8 +407,8 @@ public class TCPRemoteCommitProvider _addressesLock.lock(); try { - for (Iterator iter = _addresses.iterator(); iter.hasNext();) { - ((HostAddress) iter.next()).close(); + for (Iterator iter = _addresses.iterator(); iter.hasNext();) { + iter.next().close(); } } finally { _addressesLock.unlock(); @@ -411,7 +422,7 @@ public class TCPRemoteCommitProvider */ private static class BroadcastQueue { - private LinkedList _packetQueue = new LinkedList(); + private LinkedList _packetQueue = new LinkedList<>(); private boolean _closed = false; public synchronized void close() { @@ -443,7 +454,7 @@ public class TCPRemoteCommitProvider if (_packetQueue.isEmpty()) { return null; } else { - return (byte[]) _packetQueue.removeFirst(); + return _packetQueue.removeFirst(); } } } @@ -494,8 +505,8 @@ public class TCPRemoteCommitProvider private final Log _log; private ServerSocket _receiveSocket; private Thread _acceptThread; - private Set _receiverThreads = new HashSet(); - private final Set _providers = new HashSet(); + private Set _receiverThreads = new HashSet<>(); + private final Set _providers = new HashSet<>(); /** * Cache the local IP address @@ -633,9 +644,9 @@ public class TCPRemoteCommitProvider // We are done listening. Interrupt any worker threads. Thread worker; - for (Iterator iter = _receiverThreads.iterator(); + for (Iterator iter = _receiverThreads.iterator(); iter.hasNext();) { - worker = (Thread) iter.next(); + worker = iter.next(); // FYI, the worker threads are blocked // reading from the socket's InputStream. InputStreams // aren't interruptable, so this interrupt isn't @@ -768,9 +779,9 @@ public class TCPRemoteCommitProvider synchronized (_providers) { // bleair: We're iterating, but currenlty there can really // only be a single provider. - for (Iterator iter = _providers.iterator(); + for (Iterator iter = _providers.iterator(); iter.hasNext();) { - provider = (TCPRemoteCommitProvider) iter.next(); + provider = iter.next(); if (senderId != provider._id || !fromSelf) { provider.eventManager.fireEvent(rce); } @@ -817,7 +828,7 @@ public class TCPRemoteCommitProvider throw (UnknownHostException) pae.getException(); } GenericObjectPoolConfig cfg = new GenericObjectPoolConfig<>(); - cfg.setMaxTotal(_maxActive); + cfg.setMaxTotal(_maxTotal); cfg.setBlockWhenExhausted(true); cfg.setMaxWaitMillis(-1L); // -1 max wait == as long as it takes @@ -825,8 +836,8 @@ public class TCPRemoteCommitProvider _isAvailable = true; } - private void setMaxActive(int maxActive) { - _socketPool.setMaxTotal(maxActive); + private void setMaxTotal(int maxTotal) { + _socketPool.setMaxTotal(maxTotal); } private void setMaxIdle(int maxIdle) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestTCPRemoteEventsDuration.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestTCPRemoteEventsDuration.java index 5980f1a57..3e5daa549 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestTCPRemoteEventsDuration.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestTCPRemoteEventsDuration.java @@ -69,7 +69,7 @@ public class TestTCPRemoteEventsDuration // transactions OpenJPAEntityManagerFactory senderFactory1TCP = createDistinctFactory(TCPRemoteCommitProvider.class, - "MaxActive=4, RecoveryTimeMillis=1000, Port=5636, " + + "MaxTotal=4, RecoveryTimeMillis=1000, Port=5636, " + "Addresses=127.0.0.1:5636;127.0.0.1:6636"); OpenJPAEntityManagerFactory factory2TCP = createDistinctFactory( TCPRemoteCommitProvider.class, diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml index b37c4386b..7fd9093b0 100644 --- a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml +++ b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml @@ -70,7 +70,7 @@ + value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxTotal=100,MaxWait=10000,TestOnBorrow=true"/> --> @@ -526,7 +526,7 @@ org.apache.openjpa.persistence.cascade.pudefault.AnEmbeddable org.apache.openjpa.persistence.cascade.pudefault.EmbeddableWithRelationships - diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/common/apps/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/common/apps/META-INF/persistence.xml index 1e0f22f12..92d6bdfa3 100644 --- a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/common/apps/META-INF/persistence.xml +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/common/apps/META-INF/persistence.xml @@ -37,7 +37,7 @@ org.apache.openjpa.persistence.common.apps.Address org.apache.openjpa.persistence.common.apps.FemaleUser - diff --git a/openjpa-persistence-locking/src/test/resources/META-INF/persistence.xml b/openjpa-persistence-locking/src/test/resources/META-INF/persistence.xml index b382cadb9..ee975305f 100644 --- a/openjpa-persistence-locking/src/test/resources/META-INF/persistence.xml +++ b/openjpa-persistence-locking/src/test/resources/META-INF/persistence.xml @@ -28,7 +28,7 @@ + value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxTotal=100,MaxWait=10000,TestOnBorrow=true"/> --> diff --git a/openjpa-project/src/doc/manual/ref_guide_conf.xml b/openjpa-project/src/doc/manual/ref_guide_conf.xml index a6fafabaa..e8358ad20 100644 --- a/openjpa-project/src/doc/manual/ref_guide_conf.xml +++ b/openjpa-project/src/doc/manual/ref_guide_conf.xml @@ -3665,9 +3665,8 @@ the org.apache.openjpa.jdbc.schema.DriverDataSource implementation to use to wrap JDBC Driver classes with javax.sql.DataSource -instances. The org.apache.openjpa.jdbc.schema.AutoDriverDataSource implementation is the default and will select either the DBCPDriverDataSource or SimpleDriverDataSource based on if Apache Commons DBCP is available -on the classpath. -The org.apache.openjpa.jdbc.schema.DBCPDriverDataSource implementation requires Apache Commons DBCP to be available on the classpath and uses org.apache.commons.dbcp.BasicDataSource to provide connection pooling. +instances. +The org.apache.commons.dbcp2.BasicDataSource Apache Commons DBCP2 to be available on the classpath and provides connection pooling.
diff --git a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml index 2ef334e0a..5d5b8c143 100644 --- a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml +++ b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml @@ -79,27 +79,14 @@ provided implementations. -Starting with OpenJPA 2.1, a new org.apache.openjpa.jdbc.schema.AutoDriverDataSource is provided as the default, which will automatically -select between the old SimpleDriverDataSource and a new -DBCPDriverDataSource implementation based on if -Apache Commons DBCP -has been provided on the classpath and OpenJPA is not running in a container -managed mode or with managed transactions. Note, that only the -openjpa-all.jar includes Commons DBCP, so you will need to -include the commons-dbcp2.jar from the OpenJPA binary -distribution if you are using the normal openjpa.jar. +openjpa.jdbc.DriverDataSource=simple, will make +OpenJPA to use org.apache.openjpa.jdbc.schema.SimpleDriverDataSource -To disable the automatic usage of Apache Commons DBCP when it is discovered -on the classpath, set -openjpa.jdbc.DriverDataSource=simple, which will revert -OpenJPA to the prior behavior of using org.apache.openjpa.jdbc.schema.SimpleDriverDataSource - - -To force usage of Apache Commons DBCP, which will cause a fatal exception to +To force usage of Apache Commons DBCP2, which will cause a fatal exception to be thrown if it cannot be loaded from the classpath, set openjpa.jdbc.DriverDataSource=dbcp, which will cause -OpenJPA to use org.apache.openjpa.jdbc.schema.DBCPDriverDataSource +OpenJPA to use org.apache.commons.dbcp2.BasicDataSource
@@ -290,7 +277,7 @@ false. Additional Commons DBCP arguments can be provided in openjpa.connectionProperties, such as: - MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000 + MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000 Please visit the Commons DBCP website for the entire list of configuration options and explanations. diff --git a/openjpa-project/src/doc/manual/ref_guide_integration.xml b/openjpa-project/src/doc/manual/ref_guide_integration.xml index 794eb3eb2..81de985d4 100644 --- a/openjpa-project/src/doc/manual/ref_guide_integration.xml +++ b/openjpa-project/src/doc/manual/ref_guide_integration.xml @@ -544,7 +544,7 @@ The JDBC DataSource configuration o Additional Commons DBCP arguments can be provided in the connectionProperties value, such as: - MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000 + MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000 Please visit the Commons DBCP website for the entire list of configuration options and explanations. diff --git a/openjpa-project/src/doc/manual/ref_guide_remote.xml b/openjpa-project/src/doc/manual/ref_guide_remote.xml index 177a01553..6b84fbcb0 100644 --- a/openjpa-project/src/doc/manual/ref_guide_remote.xml +++ b/openjpa-project/src/doc/manual/ref_guide_remote.xml @@ -678,7 +678,7 @@ which notifications should be sent. No default value. purpose of transmitting events to peers. You should increase this value as the number of concurrent transactions increases. The maximum number of concurrent transactions is a function of the size of the connection pool. See the -MaxActive property of +MaxTotal property of openjpa.ConnectionFactoryProperties in . Setting a value of 0 will result in behavior where the thread invoking commit @@ -700,7 +700,7 @@ to each peer in the cluster for the transmission of events. Defaults to 2. -MaxActive: The maximum allowed number of TCP sockets +MaxTotal: Total allowed number of TCP sockets (channels) to open simultaneously between each peer in the cluster. Defaults to 2. diff --git a/openjpa-slice/src/test/resources/META-INF/persistence.xml b/openjpa-slice/src/test/resources/META-INF/persistence.xml index 83a6578d0..543b6bde3 100644 --- a/openjpa-slice/src/test/resources/META-INF/persistence.xml +++ b/openjpa-slice/src/test/resources/META-INF/persistence.xml @@ -288,10 +288,10 @@ - - - - + + + + @@ -311,7 +311,7 @@ - + @@ -335,10 +335,10 @@ - - - - + + + + @@ -358,7 +358,7 @@ - + diff --git a/pom.xml b/pom.xml index 46e6c2b54..939e8fdb2 100644 --- a/pom.xml +++ b/pom.xml @@ -57,11 +57,11 @@ false - 10 + 10 5 2 10000 - MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait} + MaxTotal=${dbcp.maxTotal},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait} 10 5 0 0 - 20 + 20