[OPENJPA-2754] maxActive -> maxTotal (#24)

* [OPENJPA-2754] maxActive -> maxTotal

* commons-pool2 and commons-dbcp2 versions are updated, setMaxActive is deprecated with warn being logged

* DBCPDriverDataSource and AutoDriverDataSource are removed

* BasicDataSource is being loaded in case jdbc.DriverDataSource is set to 'dbcp'

* Normal call is replaced with reflection
This commit is contained in:
Maxim Solodovnik 2018-11-16 13:48:40 +07:00 committed by GitHub
parent 7f4997b68a
commit d874cbf6d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 120 additions and 456 deletions

View File

@ -39,11 +39,11 @@
<checkstyle.config.location>${project.basedir}${file.separator}..${file.separator}..${file.separator}openjpa-project${file.separator}checkstyle.xml</checkstyle.config.location>
<checkstyle.suppressions.location>${project.basedir}${file.separator}..${file.separator}..${file.separator}openjpa-project${file.separator}suppressions.xml</checkstyle.suppressions.location>
<daytrader.version>2.2-SNAPSHOT</daytrader.version>
<dbcp.maxActive>10</dbcp.maxActive>
<dbcp.maxTotal>10</dbcp.maxTotal>
<dbcp.maxIdle>5</dbcp.maxIdle>
<dbcp.minIdle>2</dbcp.minIdle>
<dbcp.maxWait>10000</dbcp.maxWait>
<dbcp.args>MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
<dbcp.args>MaxTotal=${dbcp.maxTotal},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
</properties>
<dependencies>

View File

@ -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

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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<Object> 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<Object> 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
}
}

View File

@ -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.
*/

View File

@ -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<String, TCPPortListener> 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<BroadcastWorkerThread> _broadcastThreads = Collections.synchronizedList(
new LinkedList<>());
private ArrayList _addresses = new ArrayList();
private List<HostAddress> _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<HostAddress> 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<HostAddress> 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<HostAddress> 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<HostAddress> 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<byte[]> _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<Thread> _receiverThreads = new HashSet<>();
private final Set<TCPRemoteCommitProvider> _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<Thread> 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<TCPRemoteCommitProvider> 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<Socket> 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) {

View File

@ -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,

View File

@ -70,7 +70,7 @@
<property name="openjpa.ConnectionDriverName"
value="org.apache.commons.dbcp.BasicDataSource"/>
<property name="openjpa.ConnectionProperties"
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxTotal=100,MaxWait=10000,TestOnBorrow=true"/>
-->
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
@ -526,7 +526,7 @@
<class>org.apache.openjpa.persistence.cascade.pudefault.AnEmbeddable</class>
<class>org.apache.openjpa.persistence.cascade.pudefault.EmbeddableWithRelationships</class>
<properties>
<property name="openjpa.ConnectionFactoryProperties" value="MaxActive=110, MaxIdle=10, ValidationTimeout=50000,
<property name="openjpa.ConnectionFactoryProperties" value="MaxTotal=110, MaxIdle=10, ValidationTimeout=50000,
MaxCachedStatements=10, ValidationSQL='', MaxWait=10000, TestOnBorrow=true" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>

View File

@ -37,7 +37,7 @@
<class>org.apache.openjpa.persistence.common.apps.Address</class>
<class>org.apache.openjpa.persistence.common.apps.FemaleUser</class>
<properties>
<property name="openjpa.ConnectionFactoryProperties" value="MaxActive=110, MaxIdle=10, ValidationTimeout=50000,
<property name="openjpa.ConnectionFactoryProperties" value="MaxTotal=110, MaxIdle=10, ValidationTimeout=50000,
MaxCachedStatements=10, ValidationSQL='', MaxWait=10000, TestOnBorrow=true" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>

View File

@ -28,7 +28,7 @@
<property name="openjpa.ConnectionDriverName"
value="org.apache.commons.dbcp.BasicDataSource"/>
<property name="openjpa.ConnectionProperties"
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxTotal=100,MaxWait=10000,TestOnBorrow=true"/>
-->
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>

View File

@ -3665,9 +3665,8 @@ the
<ulink url="../../apidocs/org/apache/openjpa/jdbc/schema/DriverDataSource.html">
<classname>org.apache.openjpa.jdbc.schema.DriverDataSource</classname></ulink>
implementation to use to wrap JDBC Driver classes with javax.sql.DataSource
instances. The <classname>org.apache.openjpa.jdbc.schema.AutoDriverDataSource</classname> implementation is the default and will select either the DBCPDriverDataSource or SimpleDriverDataSource based on if Apache Commons DBCP is available
on the classpath.
The <classname>org.apache.openjpa.jdbc.schema.DBCPDriverDataSource</classname> implementation requires Apache Commons DBCP to be available on the classpath and uses <classname>org.apache.commons.dbcp.BasicDataSource</classname> to provide connection pooling.
instances.
The <classname>org.apache.commons.dbcp2.BasicDataSource</classname> Apache Commons DBCP2 to be available on the classpath and provides connection pooling.
</para>
</section>
<section id="openjpa.jdbc.EagerFetchMode">

View File

@ -79,27 +79,14 @@ provided implementations.
</seealso>
</indexterm>
<para>
Starting with OpenJPA 2.1, a new <classname>org.apache.openjpa.jdbc.schema.AutoDriverDataSource</classname> is provided as the default, which will automatically
select between the old <classname>SimpleDriverDataSource</classname> and a new
<classname>DBCPDriverDataSource</classname> implementation based on if
<ulink url="http://commons.apache.org/dbcp/">Apache Commons DBCP</ulink>
has been provided on the classpath and OpenJPA is not running in a container
managed mode or with managed transactions. Note, that only the
<literal>openjpa-all.jar</literal> includes Commons DBCP, so you will need to
include the <literal>commons-dbcp2.jar</literal> from the OpenJPA binary
distribution if you are using the normal <literal>openjpa.jar</literal>.
<literal>openjpa.jdbc.DriverDataSource=simple</literal>, will make
OpenJPA to use <classname>org.apache.openjpa.jdbc.schema.SimpleDriverDataSource</classname>
</para>
<para>
To disable the automatic usage of Apache Commons DBCP when it is discovered
on the classpath, set
<literal>openjpa.jdbc.DriverDataSource=simple</literal>, which will revert
OpenJPA to the prior behavior of using <classname>org.apache.openjpa.jdbc.schema.SimpleDriverDataSource</classname>
</para>
<para>
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
<literal>openjpa.jdbc.DriverDataSource=dbcp</literal>, which will cause
OpenJPA to use <classname>org.apache.openjpa.jdbc.schema.DBCPDriverDataSource</classname>
OpenJPA to use <classname>org.apache.commons.dbcp2.BasicDataSource</classname>
</para>
</section>
<section id="ref_guide_dbsetup_config">
@ -290,7 +277,7 @@ false.
Additional Commons DBCP arguments can be provided in
<literal>openjpa.connectionProperties</literal>, such as:
<programlisting>
MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000
MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000
</programlisting>
Please visit the Commons DBCP website for the entire list of
<ulink url="http://commons.apache.org/dbcp/configuration.html">configuration options</ulink> and explanations.

View File

@ -544,7 +544,7 @@ The <link linkend="ref_guide_dbsetup_thirdparty">JDBC DataSource configuration o
</programlisting>
Additional Commons DBCP arguments can be provided in the connectionProperties value, such as:
<programlisting>
MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000
MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000
</programlisting>
Please visit the Commons DBCP website for the entire list of <ulink url="http://commons.apache.org/dbcp/configuration.html">configuration options</ulink> and explanations.
</para>

View File

@ -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
<literal>MaxActive</literal> property of <literal>
<literal>MaxTotal</literal> property of <literal>
openjpa.ConnectionFactoryProperties</literal> in
<xref linkend="ref_guide_dbsetup_builtin"/>. Setting a value of 0 will
result in behavior where the thread invoking <methodname>commit</methodname>
@ -700,7 +700,7 @@ to each peer in the cluster for the transmission of events. Defaults to 2.
</listitem>
<listitem>
<para>
<literal>MaxActive</literal>: The maximum allowed number of TCP sockets
<literal>MaxTotal</literal>: Total allowed number of TCP sockets
(channels) to open simultaneously between each peer in the cluster. Defaults to
2.
</para>

View File

@ -288,10 +288,10 @@
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.slice.S1.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S1,MaxActive=4"/>
<property name="openjpa.slice.S2.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S2,MaxActive=4"/>
<property name="openjpa.slice.S3.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S3,MaxActive=4"/>
<property name="openjpa.slice.S4.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S4,MaxActive=4"/>
<property name="openjpa.slice.S1.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S1,MaxTotal=4"/>
<property name="openjpa.slice.S2.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S2,MaxTotal=4"/>
<property name="openjpa.slice.S3.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S3,MaxTotal=4"/>
<property name="openjpa.slice.S4.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S4,MaxTotal=4"/>
<property name="openjpa.jdbc.DBDictionary" value="mysql"/>
<property name="openjpa.Multithreaded" value="false"/>
@ -311,7 +311,7 @@
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S,MaxActive=4"/>
<property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S,MaxTotal=4"/>
<property name="openjpa.jdbc.DBDictionary" value="mysql"/>
<property name="openjpa.Multithreaded" value="false"/>
@ -335,10 +335,10 @@
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.slice.S1.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S1,MaxActive=4"/>
<property name="openjpa.slice.S2.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S2,MaxActive=4"/>
<property name="openjpa.slice.S3.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S3,MaxActive=4"/>
<property name="openjpa.slice.S4.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S4,MaxActive=4"/>
<property name="openjpa.slice.S1.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S1,MaxTotal=4"/>
<property name="openjpa.slice.S2.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S2,MaxTotal=4"/>
<property name="openjpa.slice.S3.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S3,MaxTotal=4"/>
<property name="openjpa.slice.S4.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S4,MaxTotal=4"/>
<property name="openjpa.jdbc.DBDictionary" value="mariadb"/>
<property name="openjpa.Multithreaded" value="false"/>
@ -358,7 +358,7 @@
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S,MaxActive=4"/>
<property name="openjpa.ConnectionProperties" value="DriverClassName=org.mariadb.jdbc.Driver,Url=jdbc:mysql://localhost/S,MaxTotal=4"/>
<property name="openjpa.jdbc.DBDictionary" value="mariadb"/>
<property name="openjpa.Multithreaded" value="false"/>

View File

@ -57,11 +57,11 @@
<!-- Setting for openjpa.DynamicEnhancementAgent usage -->
<openjpa.DynamicEnhancementAgent>false</openjpa.DynamicEnhancementAgent>
<!-- Commons DBCP settings passed in as openjpa.ConnectionProperties -->
<dbcp.maxActive>10</dbcp.maxActive>
<dbcp.maxTotal>10</dbcp.maxTotal>
<dbcp.maxIdle>5</dbcp.maxIdle>
<dbcp.minIdle>2</dbcp.minIdle>
<dbcp.maxWait>10000</dbcp.maxWait>
<dbcp.args>MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
<dbcp.args>MaxTotal=${dbcp.maxTotal},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
<derby.locks.waitTimeout>10</derby.locks.waitTimeout>
<derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout>
<!-- Testcase @AllowFailure options: ignore = silently skip test,
@ -672,7 +672,7 @@
<!-- DBCP overrides -->
<dbcp.maxIdle>0</dbcp.maxIdle>
<dbcp.minIdle>0</dbcp.minIdle>
<dbcp.maxActive>20</dbcp.maxActive>
<dbcp.maxTotal>20</dbcp.maxTotal>
</properties>
</profile>