mirror of https://github.com/apache/openjpa.git
[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:
parent
7f4997b68a
commit
d874cbf6d3
|
@ -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.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>
|
<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>
|
<daytrader.version>2.2-SNAPSHOT</daytrader.version>
|
||||||
<dbcp.maxActive>10</dbcp.maxActive>
|
<dbcp.maxTotal>10</dbcp.maxTotal>
|
||||||
<dbcp.maxIdle>5</dbcp.maxIdle>
|
<dbcp.maxIdle>5</dbcp.maxIdle>
|
||||||
<dbcp.minIdle>2</dbcp.minIdle>
|
<dbcp.minIdle>2</dbcp.minIdle>
|
||||||
<dbcp.maxWait>10000</dbcp.maxWait>
|
<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>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -486,7 +486,7 @@ public interface JDBCConfiguration
|
||||||
* Create an instance of the {@link DriverDataSource} to use
|
* Create an instance of the {@link DriverDataSource} to use
|
||||||
* for creating a {@link DataSource} from a JDBC {@link Driver}.
|
* 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
|
* The plugin string for the {@link SchemaFactory} to use to provide
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.apache.openjpa.jdbc.kernel.UpdateManager;
|
||||||
import org.apache.openjpa.jdbc.meta.MappingDefaults;
|
import org.apache.openjpa.jdbc.meta.MappingDefaults;
|
||||||
import org.apache.openjpa.jdbc.meta.MappingRepository;
|
import org.apache.openjpa.jdbc.meta.MappingRepository;
|
||||||
import org.apache.openjpa.jdbc.schema.DataSourceFactory;
|
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.schema.SchemaFactory;
|
||||||
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||||
import org.apache.openjpa.jdbc.sql.DBDictionaryFactory;
|
import org.apache.openjpa.jdbc.sql.DBDictionaryFactory;
|
||||||
|
@ -246,9 +245,8 @@ public class JDBCConfigurationImpl
|
||||||
|
|
||||||
driverDataSourcePlugin = addPlugin("jdbc.DriverDataSource", false);
|
driverDataSourcePlugin = addPlugin("jdbc.DriverDataSource", false);
|
||||||
aliases = new String[]{
|
aliases = new String[]{
|
||||||
"auto", "org.apache.openjpa.jdbc.schema.AutoDriverDataSource",
|
|
||||||
"simple", "org.apache.openjpa.jdbc.schema.SimpleDriverDataSource",
|
"simple", "org.apache.openjpa.jdbc.schema.SimpleDriverDataSource",
|
||||||
"dbcp", "org.apache.openjpa.jdbc.schema.DBCPDriverDataSource",
|
"dbcp", "org.apache.commons.dbcp2.BasicDataSource"
|
||||||
};
|
};
|
||||||
driverDataSourcePlugin.setAliases(aliases);
|
driverDataSourcePlugin.setAliases(aliases);
|
||||||
driverDataSourcePlugin.setDefault(aliases[0]);
|
driverDataSourcePlugin.setDefault(aliases[0]);
|
||||||
|
@ -688,9 +686,9 @@ public class JDBCConfigurationImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DriverDataSource newDriverDataSourceInstance() {
|
public DataSource newDriverDataSourceInstance() {
|
||||||
return (DriverDataSource) driverDataSourcePlugin.
|
return (DataSource) driverDataSourcePlugin.
|
||||||
instantiate(DriverDataSource.class, this);
|
instantiate(DataSource.class, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.jdbc.schema;
|
package org.apache.openjpa.jdbc.schema;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
|
@ -56,7 +57,7 @@ import org.apache.openjpa.util.UserException;
|
||||||
* @author Abe White
|
* @author Abe White
|
||||||
*/
|
*/
|
||||||
public class DataSourceFactory {
|
public class DataSourceFactory {
|
||||||
|
private static final String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp2.BasicDataSource";
|
||||||
private static final Localizer _loc = Localizer.forPackage(DataSourceFactory.class);
|
private static final Localizer _loc = Localizer.forPackage(DataSourceFactory.class);
|
||||||
protected static Localizer _eloc = Localizer.forPackage(DelegatingDataSource.class);
|
protected static Localizer _eloc = Localizer.forPackage(DelegatingDataSource.class);
|
||||||
|
|
||||||
|
@ -85,27 +86,42 @@ public class DataSourceFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Driver.class.isAssignableFrom(driverClass)) {
|
if (Driver.class.isAssignableFrom(driverClass)) {
|
||||||
DriverDataSource ds = conf.newDriverDataSourceInstance();
|
DataSource rawDs = conf.newDriverDataSourceInstance();
|
||||||
ds.setClassLoader(loader);
|
if (rawDs instanceof DriverDataSource) {
|
||||||
ds.setConnectionDriverName(driver);
|
DriverDataSource ds = (DriverDataSource)rawDs;
|
||||||
ds.setConnectionProperties(Configurations.
|
ds.setClassLoader(loader);
|
||||||
parseProperties(props));
|
ds.setConnectionDriverName(driver);
|
||||||
|
ds.setConnectionProperties(Configurations.
|
||||||
|
parseProperties(props));
|
||||||
|
|
||||||
if (!factory2) {
|
if (!factory2) {
|
||||||
ds.setConnectionFactoryProperties(Configurations.
|
ds.setConnectionFactoryProperties(Configurations.
|
||||||
parseProperties(conf.getConnectionFactoryProperties()));
|
parseProperties(conf.getConnectionFactoryProperties()));
|
||||||
ds.setConnectionURL(conf.getConnectionURL());
|
ds.setConnectionURL(conf.getConnectionURL());
|
||||||
ds.setConnectionUserName(conf.getConnectionUserName());
|
ds.setConnectionUserName(conf.getConnectionUserName());
|
||||||
ds.setConnectionPassword(conf.getConnectionPassword());
|
ds.setConnectionPassword(conf.getConnectionPassword());
|
||||||
} else {
|
} else {
|
||||||
ds.setConnectionFactoryProperties
|
ds.setConnectionFactoryProperties
|
||||||
(Configurations.parseProperties(conf.
|
(Configurations.parseProperties(conf.
|
||||||
getConnectionFactory2Properties()));
|
getConnectionFactory2Properties()));
|
||||||
ds.setConnectionURL(conf.getConnection2URL());
|
ds.setConnectionURL(conf.getConnection2URL());
|
||||||
ds.setConnectionUserName(conf.getConnection2UserName());
|
ds.setConnectionUserName(conf.getConnection2UserName());
|
||||||
ds.setConnectionPassword(conf.getConnection2Password());
|
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
|
// 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);
|
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.
|
* Install listeners and base decorators.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,20 +82,20 @@ public class TCPRemoteCommitProvider
|
||||||
// A map of listen ports to listeners in this JVM. We might
|
// A map of listen ports to listeners in this JVM. We might
|
||||||
// want to look into allowing same port, different interface --
|
// want to look into allowing same port, different interface --
|
||||||
// that is not currently possible in a single JVM.
|
// 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 long _id;
|
||||||
private byte[] _localhost;
|
private byte[] _localhost;
|
||||||
private int _port = DEFAULT_PORT;
|
private int _port = DEFAULT_PORT;
|
||||||
private int _maxActive = 2;
|
private int _maxTotal = 2;
|
||||||
private int _maxIdle = 2;
|
private int _maxIdle = 2;
|
||||||
private int _recoveryTimeMillis = 15000;
|
private int _recoveryTimeMillis = 15000;
|
||||||
private TCPPortListener _listener;
|
private TCPPortListener _listener;
|
||||||
private BroadcastQueue _broadcastQueue = new BroadcastQueue();
|
private BroadcastQueue _broadcastQueue = new BroadcastQueue();
|
||||||
private final List _broadcastThreads = Collections.synchronizedList(
|
private final List<BroadcastWorkerThread> _broadcastThreads = Collections.synchronizedList(
|
||||||
new LinkedList());
|
new LinkedList<>());
|
||||||
|
|
||||||
private ArrayList _addresses = new ArrayList();
|
private List<HostAddress> _addresses = new ArrayList<>();
|
||||||
private ReentrantLock _addressesLock;
|
private ReentrantLock _addressesLock;
|
||||||
|
|
||||||
public TCPRemoteCommitProvider()
|
public TCPRemoteCommitProvider()
|
||||||
|
@ -144,17 +144,29 @@ public class TCPRemoteCommitProvider
|
||||||
/**
|
/**
|
||||||
* The maximum number of sockets that this provider can
|
* The maximum number of sockets that this provider can
|
||||||
* simetaneously open to each peer in the cluster.
|
* simetaneously open to each peer in the cluster.
|
||||||
|
*
|
||||||
|
* @deprecated please use {@link TCPRemoteCommitProvider#setMaxTotal(int)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setMaxActive(int maxActive) {
|
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
|
* The maximum number of sockets that this provider can
|
||||||
* simetaneously open to each peer in the cluster.
|
* simetaneously open to each peer in the cluster.
|
||||||
*/
|
*/
|
||||||
public int getMaxActive() {
|
public int getMaxTotal() {
|
||||||
return _maxActive;
|
return _maxTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,8 +196,7 @@ public class TCPRemoteCommitProvider
|
||||||
// Notify the extra worker threads so they stop themselves
|
// Notify the extra worker threads so they stop themselves
|
||||||
// Threads will not end until they send another pk.
|
// Threads will not end until they send another pk.
|
||||||
for (int i = numBroadcastThreads; i < cur; i++) {
|
for (int i = numBroadcastThreads; i < cur; i++) {
|
||||||
BroadcastWorkerThread worker = (BroadcastWorkerThread)
|
BroadcastWorkerThread worker = _broadcastThreads.remove(0);
|
||||||
_broadcastThreads.remove(0);
|
|
||||||
worker.setRunning(false);
|
worker.setRunning(false);
|
||||||
}
|
}
|
||||||
} else if (cur < numBroadcastThreads) {
|
} else if (cur < numBroadcastThreads) {
|
||||||
|
@ -220,11 +231,11 @@ public class TCPRemoteCommitProvider
|
||||||
|
|
||||||
_addressesLock.lock();
|
_addressesLock.lock();
|
||||||
try {
|
try {
|
||||||
for (Iterator iter = _addresses.iterator(); iter.hasNext();) {
|
for (Iterator<HostAddress> iter = _addresses.iterator(); iter.hasNext();) {
|
||||||
((HostAddress) iter.next()).close();
|
iter.next().close();
|
||||||
}
|
}
|
||||||
String[] toks = StringUtil.split(names, ";", 0);
|
String[] toks = StringUtil.split(names, ";", 0);
|
||||||
_addresses = new ArrayList(toks.length);
|
_addresses = new ArrayList<>(toks.length);
|
||||||
|
|
||||||
InetAddress localhost = InetAddress.getLocalHost();
|
InetAddress localhost = InetAddress.getLocalHost();
|
||||||
String localhostName = localhost.getHostName();
|
String localhostName = localhost.getHostName();
|
||||||
|
@ -285,7 +296,7 @@ public class TCPRemoteCommitProvider
|
||||||
super.endConfiguration();
|
super.endConfiguration();
|
||||||
synchronized (s_portListenerMap) {
|
synchronized (s_portListenerMap) {
|
||||||
// see if a listener exists for this port.
|
// see if a listener exists for this port.
|
||||||
_listener = (TCPPortListener) s_portListenerMap.get
|
_listener = s_portListenerMap.get
|
||||||
(String.valueOf(_port));
|
(String.valueOf(_port));
|
||||||
|
|
||||||
if (_listener == null ||
|
if (_listener == null ||
|
||||||
|
@ -314,10 +325,10 @@ public class TCPRemoteCommitProvider
|
||||||
_addressesLock.lock();
|
_addressesLock.lock();
|
||||||
try {
|
try {
|
||||||
HostAddress curAddress;
|
HostAddress curAddress;
|
||||||
for (Iterator iter = _addresses.iterator();
|
for (Iterator<HostAddress> iter = _addresses.iterator();
|
||||||
iter.hasNext();) {
|
iter.hasNext();) {
|
||||||
curAddress = (HostAddress) iter.next();
|
curAddress = iter.next();
|
||||||
curAddress.setMaxActive(_maxActive);
|
curAddress.setMaxTotal(_maxTotal);
|
||||||
curAddress.setMaxIdle(_maxIdle);
|
curAddress.setMaxIdle(_maxIdle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,8 +379,8 @@ public class TCPRemoteCommitProvider
|
||||||
private void sendUpdatePacket(byte[] bytes) {
|
private void sendUpdatePacket(byte[] bytes) {
|
||||||
_addressesLock.lock();
|
_addressesLock.lock();
|
||||||
try {
|
try {
|
||||||
for (Iterator iter = _addresses.iterator(); iter.hasNext();) {
|
for (Iterator<HostAddress> iter = _addresses.iterator(); iter.hasNext();) {
|
||||||
((HostAddress) iter.next()).sendUpdatePacket(bytes);
|
iter.next().sendUpdatePacket(bytes);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
_addressesLock.unlock();
|
_addressesLock.unlock();
|
||||||
|
@ -396,8 +407,8 @@ public class TCPRemoteCommitProvider
|
||||||
|
|
||||||
_addressesLock.lock();
|
_addressesLock.lock();
|
||||||
try {
|
try {
|
||||||
for (Iterator iter = _addresses.iterator(); iter.hasNext();) {
|
for (Iterator<HostAddress> iter = _addresses.iterator(); iter.hasNext();) {
|
||||||
((HostAddress) iter.next()).close();
|
iter.next().close();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
_addressesLock.unlock();
|
_addressesLock.unlock();
|
||||||
|
@ -411,7 +422,7 @@ public class TCPRemoteCommitProvider
|
||||||
*/
|
*/
|
||||||
private static class BroadcastQueue {
|
private static class BroadcastQueue {
|
||||||
|
|
||||||
private LinkedList _packetQueue = new LinkedList();
|
private LinkedList<byte[]> _packetQueue = new LinkedList<>();
|
||||||
private boolean _closed = false;
|
private boolean _closed = false;
|
||||||
|
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
|
@ -443,7 +454,7 @@ public class TCPRemoteCommitProvider
|
||||||
if (_packetQueue.isEmpty()) {
|
if (_packetQueue.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return (byte[]) _packetQueue.removeFirst();
|
return _packetQueue.removeFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,8 +505,8 @@ public class TCPRemoteCommitProvider
|
||||||
private final Log _log;
|
private final Log _log;
|
||||||
private ServerSocket _receiveSocket;
|
private ServerSocket _receiveSocket;
|
||||||
private Thread _acceptThread;
|
private Thread _acceptThread;
|
||||||
private Set _receiverThreads = new HashSet();
|
private Set<Thread> _receiverThreads = new HashSet<>();
|
||||||
private final Set _providers = new HashSet();
|
private final Set<TCPRemoteCommitProvider> _providers = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache the local IP address
|
* Cache the local IP address
|
||||||
|
@ -633,9 +644,9 @@ public class TCPRemoteCommitProvider
|
||||||
|
|
||||||
// We are done listening. Interrupt any worker threads.
|
// We are done listening. Interrupt any worker threads.
|
||||||
Thread worker;
|
Thread worker;
|
||||||
for (Iterator iter = _receiverThreads.iterator();
|
for (Iterator<Thread> iter = _receiverThreads.iterator();
|
||||||
iter.hasNext();) {
|
iter.hasNext();) {
|
||||||
worker = (Thread) iter.next();
|
worker = iter.next();
|
||||||
// FYI, the worker threads are blocked
|
// FYI, the worker threads are blocked
|
||||||
// reading from the socket's InputStream. InputStreams
|
// reading from the socket's InputStream. InputStreams
|
||||||
// aren't interruptable, so this interrupt isn't
|
// aren't interruptable, so this interrupt isn't
|
||||||
|
@ -768,9 +779,9 @@ public class TCPRemoteCommitProvider
|
||||||
synchronized (_providers) {
|
synchronized (_providers) {
|
||||||
// bleair: We're iterating, but currenlty there can really
|
// bleair: We're iterating, but currenlty there can really
|
||||||
// only be a single provider.
|
// only be a single provider.
|
||||||
for (Iterator iter = _providers.iterator();
|
for (Iterator<TCPRemoteCommitProvider> iter = _providers.iterator();
|
||||||
iter.hasNext();) {
|
iter.hasNext();) {
|
||||||
provider = (TCPRemoteCommitProvider) iter.next();
|
provider = iter.next();
|
||||||
if (senderId != provider._id || !fromSelf) {
|
if (senderId != provider._id || !fromSelf) {
|
||||||
provider.eventManager.fireEvent(rce);
|
provider.eventManager.fireEvent(rce);
|
||||||
}
|
}
|
||||||
|
@ -817,7 +828,7 @@ public class TCPRemoteCommitProvider
|
||||||
throw (UnknownHostException) pae.getException();
|
throw (UnknownHostException) pae.getException();
|
||||||
}
|
}
|
||||||
GenericObjectPoolConfig<Socket> cfg = new GenericObjectPoolConfig<>();
|
GenericObjectPoolConfig<Socket> cfg = new GenericObjectPoolConfig<>();
|
||||||
cfg.setMaxTotal(_maxActive);
|
cfg.setMaxTotal(_maxTotal);
|
||||||
cfg.setBlockWhenExhausted(true);
|
cfg.setBlockWhenExhausted(true);
|
||||||
cfg.setMaxWaitMillis(-1L);
|
cfg.setMaxWaitMillis(-1L);
|
||||||
// -1 max wait == as long as it takes
|
// -1 max wait == as long as it takes
|
||||||
|
@ -825,8 +836,8 @@ public class TCPRemoteCommitProvider
|
||||||
_isAvailable = true;
|
_isAvailable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMaxActive(int maxActive) {
|
private void setMaxTotal(int maxTotal) {
|
||||||
_socketPool.setMaxTotal(maxActive);
|
_socketPool.setMaxTotal(maxTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMaxIdle(int maxIdle) {
|
private void setMaxIdle(int maxIdle) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class TestTCPRemoteEventsDuration
|
||||||
// transactions
|
// transactions
|
||||||
OpenJPAEntityManagerFactory senderFactory1TCP =
|
OpenJPAEntityManagerFactory senderFactory1TCP =
|
||||||
createDistinctFactory(TCPRemoteCommitProvider.class,
|
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");
|
"Addresses=127.0.0.1:5636;127.0.0.1:6636");
|
||||||
OpenJPAEntityManagerFactory factory2TCP = createDistinctFactory(
|
OpenJPAEntityManagerFactory factory2TCP = createDistinctFactory(
|
||||||
TCPRemoteCommitProvider.class,
|
TCPRemoteCommitProvider.class,
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
<property name="openjpa.ConnectionDriverName"
|
<property name="openjpa.ConnectionDriverName"
|
||||||
value="org.apache.commons.dbcp.BasicDataSource"/>
|
value="org.apache.commons.dbcp.BasicDataSource"/>
|
||||||
<property name="openjpa.ConnectionProperties"
|
<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"
|
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||||
value="buildSchema(ForeignKeys=true)"/>
|
value="buildSchema(ForeignKeys=true)"/>
|
||||||
|
@ -526,7 +526,7 @@
|
||||||
<class>org.apache.openjpa.persistence.cascade.pudefault.AnEmbeddable</class>
|
<class>org.apache.openjpa.persistence.cascade.pudefault.AnEmbeddable</class>
|
||||||
<class>org.apache.openjpa.persistence.cascade.pudefault.EmbeddableWithRelationships</class>
|
<class>org.apache.openjpa.persistence.cascade.pudefault.EmbeddableWithRelationships</class>
|
||||||
<properties>
|
<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" />
|
MaxCachedStatements=10, ValidationSQL='', MaxWait=10000, TestOnBorrow=true" />
|
||||||
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
|
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<class>org.apache.openjpa.persistence.common.apps.Address</class>
|
<class>org.apache.openjpa.persistence.common.apps.Address</class>
|
||||||
<class>org.apache.openjpa.persistence.common.apps.FemaleUser</class>
|
<class>org.apache.openjpa.persistence.common.apps.FemaleUser</class>
|
||||||
<properties>
|
<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" />
|
MaxCachedStatements=10, ValidationSQL='', MaxWait=10000, TestOnBorrow=true" />
|
||||||
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
|
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<property name="openjpa.ConnectionDriverName"
|
<property name="openjpa.ConnectionDriverName"
|
||||||
value="org.apache.commons.dbcp.BasicDataSource"/>
|
value="org.apache.commons.dbcp.BasicDataSource"/>
|
||||||
<property name="openjpa.ConnectionProperties"
|
<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"
|
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||||
value="buildSchema(ForeignKeys=true)"/>
|
value="buildSchema(ForeignKeys=true)"/>
|
||||||
|
|
|
@ -3665,9 +3665,8 @@ the
|
||||||
<ulink url="../../apidocs/org/apache/openjpa/jdbc/schema/DriverDataSource.html">
|
<ulink url="../../apidocs/org/apache/openjpa/jdbc/schema/DriverDataSource.html">
|
||||||
<classname>org.apache.openjpa.jdbc.schema.DriverDataSource</classname></ulink>
|
<classname>org.apache.openjpa.jdbc.schema.DriverDataSource</classname></ulink>
|
||||||
implementation to use to wrap JDBC Driver classes with javax.sql.DataSource
|
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
|
instances.
|
||||||
on the classpath.
|
The <classname>org.apache.commons.dbcp2.BasicDataSource</classname> Apache Commons DBCP2 to be available on the classpath and provides connection pooling.
|
||||||
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.
|
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
<section id="openjpa.jdbc.EagerFetchMode">
|
<section id="openjpa.jdbc.EagerFetchMode">
|
||||||
|
|
|
@ -79,27 +79,14 @@ provided implementations.
|
||||||
</seealso>
|
</seealso>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<para>
|
<para>
|
||||||
Starting with OpenJPA 2.1, a new <classname>org.apache.openjpa.jdbc.schema.AutoDriverDataSource</classname> is provided as the default, which will automatically
|
<literal>openjpa.jdbc.DriverDataSource=simple</literal>, will make
|
||||||
select between the old <classname>SimpleDriverDataSource</classname> and a new
|
OpenJPA to use <classname>org.apache.openjpa.jdbc.schema.SimpleDriverDataSource</classname>
|
||||||
<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>.
|
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
To disable the automatic usage of Apache Commons DBCP when it is discovered
|
To force usage of Apache Commons DBCP2, which will cause a fatal exception to
|
||||||
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
|
|
||||||
be thrown if it cannot be loaded from the classpath, set
|
be thrown if it cannot be loaded from the classpath, set
|
||||||
<literal>openjpa.jdbc.DriverDataSource=dbcp</literal>, which will cause
|
<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>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
<section id="ref_guide_dbsetup_config">
|
<section id="ref_guide_dbsetup_config">
|
||||||
|
@ -290,7 +277,7 @@ false.
|
||||||
Additional Commons DBCP arguments can be provided in
|
Additional Commons DBCP arguments can be provided in
|
||||||
<literal>openjpa.connectionProperties</literal>, such as:
|
<literal>openjpa.connectionProperties</literal>, such as:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000
|
MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Please visit the Commons DBCP website for the entire list of
|
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.
|
<ulink url="http://commons.apache.org/dbcp/configuration.html">configuration options</ulink> and explanations.
|
||||||
|
|
|
@ -544,7 +544,7 @@ The <link linkend="ref_guide_dbsetup_thirdparty">JDBC DataSource configuration o
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Additional Commons DBCP arguments can be provided in the connectionProperties value, such as:
|
Additional Commons DBCP arguments can be provided in the connectionProperties value, such as:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=60000
|
MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000
|
||||||
</programlisting>
|
</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.
|
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>
|
</para>
|
||||||
|
|
|
@ -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
|
purpose of transmitting events to peers. You should increase this value as the
|
||||||
number of concurrent transactions increases. The maximum number of concurrent
|
number of concurrent transactions increases. The maximum number of concurrent
|
||||||
transactions is a function of the size of the connection pool. See the
|
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
|
openjpa.ConnectionFactoryProperties</literal> in
|
||||||
<xref linkend="ref_guide_dbsetup_builtin"/>. Setting a value of 0 will
|
<xref linkend="ref_guide_dbsetup_builtin"/>. Setting a value of 0 will
|
||||||
result in behavior where the thread invoking <methodname>commit</methodname>
|
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>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<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
|
(channels) to open simultaneously between each peer in the cluster. Defaults to
|
||||||
2.
|
2.
|
||||||
</para>
|
</para>
|
||||||
|
|
|
@ -288,10 +288,10 @@
|
||||||
|
|
||||||
<property name="openjpa.ConnectionUserName" value="root"/>
|
<property name="openjpa.ConnectionUserName" value="root"/>
|
||||||
<property name="openjpa.ConnectionPassword" value=""/>
|
<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.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,MaxActive=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,MaxActive=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,MaxActive=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.jdbc.DBDictionary" value="mysql"/>
|
||||||
<property name="openjpa.Multithreaded" value="false"/>
|
<property name="openjpa.Multithreaded" value="false"/>
|
||||||
|
@ -311,7 +311,7 @@
|
||||||
|
|
||||||
<property name="openjpa.ConnectionUserName" value="root"/>
|
<property name="openjpa.ConnectionUserName" value="root"/>
|
||||||
<property name="openjpa.ConnectionPassword" value=""/>
|
<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.jdbc.DBDictionary" value="mysql"/>
|
||||||
<property name="openjpa.Multithreaded" value="false"/>
|
<property name="openjpa.Multithreaded" value="false"/>
|
||||||
|
@ -335,10 +335,10 @@
|
||||||
|
|
||||||
<property name="openjpa.ConnectionUserName" value="root"/>
|
<property name="openjpa.ConnectionUserName" value="root"/>
|
||||||
<property name="openjpa.ConnectionPassword" value=""/>
|
<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.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,MaxActive=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,MaxActive=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,MaxActive=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.jdbc.DBDictionary" value="mariadb"/>
|
||||||
<property name="openjpa.Multithreaded" value="false"/>
|
<property name="openjpa.Multithreaded" value="false"/>
|
||||||
|
@ -358,7 +358,7 @@
|
||||||
|
|
||||||
<property name="openjpa.ConnectionUserName" value="root"/>
|
<property name="openjpa.ConnectionUserName" value="root"/>
|
||||||
<property name="openjpa.ConnectionPassword" value=""/>
|
<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.jdbc.DBDictionary" value="mariadb"/>
|
||||||
<property name="openjpa.Multithreaded" value="false"/>
|
<property name="openjpa.Multithreaded" value="false"/>
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -57,11 +57,11 @@
|
||||||
<!-- Setting for openjpa.DynamicEnhancementAgent usage -->
|
<!-- Setting for openjpa.DynamicEnhancementAgent usage -->
|
||||||
<openjpa.DynamicEnhancementAgent>false</openjpa.DynamicEnhancementAgent>
|
<openjpa.DynamicEnhancementAgent>false</openjpa.DynamicEnhancementAgent>
|
||||||
<!-- Commons DBCP settings passed in as openjpa.ConnectionProperties -->
|
<!-- Commons DBCP settings passed in as openjpa.ConnectionProperties -->
|
||||||
<dbcp.maxActive>10</dbcp.maxActive>
|
<dbcp.maxTotal>10</dbcp.maxTotal>
|
||||||
<dbcp.maxIdle>5</dbcp.maxIdle>
|
<dbcp.maxIdle>5</dbcp.maxIdle>
|
||||||
<dbcp.minIdle>2</dbcp.minIdle>
|
<dbcp.minIdle>2</dbcp.minIdle>
|
||||||
<dbcp.maxWait>10000</dbcp.maxWait>
|
<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.waitTimeout>10</derby.locks.waitTimeout>
|
||||||
<derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout>
|
<derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout>
|
||||||
<!-- Testcase @AllowFailure options: ignore = silently skip test,
|
<!-- Testcase @AllowFailure options: ignore = silently skip test,
|
||||||
|
@ -672,7 +672,7 @@
|
||||||
<!-- DBCP overrides -->
|
<!-- DBCP overrides -->
|
||||||
<dbcp.maxIdle>0</dbcp.maxIdle>
|
<dbcp.maxIdle>0</dbcp.maxIdle>
|
||||||
<dbcp.minIdle>0</dbcp.minIdle>
|
<dbcp.minIdle>0</dbcp.minIdle>
|
||||||
<dbcp.maxActive>20</dbcp.maxActive>
|
<dbcp.maxTotal>20</dbcp.maxTotal>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue