| Method from org.apache.commons.dbcp.BasicDataSource Detail: |
public void addConnectionProperty(String name,
String value) {
connectionProperties.put(name, value);
this.restartNeeded = true;
}
Add a custom connection property to the set that will be passed to our
JDBC driver. This MUST be called before the first
connection is retrieved (along with all the other configuration
property setters). Calls to this method after the connection pool
has been initialized have no effect. |
public synchronized void close() throws SQLException {
closed = true;
GenericObjectPool oldpool = connectionPool;
connectionPool = null;
dataSource = null;
try {
if (oldpool != null) {
oldpool.close();
}
} catch(SQLException e) {
throw e;
} catch(RuntimeException e) {
throw e;
} catch(Exception e) {
throw new SQLNestedException("Cannot close connection pool", e);
}
}
Closes and releases all idle connections that are currently stored in the connection pool
associated with this data source.
Connections that are checked out to clients when this method is invoked are not affected.
When client applications subsequently invoke Connection#close() to return
these connections to the pool, the underlying JDBC connections are closed.
Attempts to acquire connections using #getConnection() after this method has been
invoked result in SQLExceptions.
This method is idempotent - i.e., closing an already closed BasicDataSource has no effect
and does not generate exceptions.
|
protected ConnectionFactory createConnectionFactory() throws SQLException {
// Load the JDBC driver class
Class driverFromCCL = null;
if (driverClassName != null) {
try {
try {
if (driverClassLoader == null) {
Class.forName(driverClassName);
} else {
Class.forName(driverClassName, true, driverClassLoader);
}
} catch (ClassNotFoundException cnfe) {
driverFromCCL = Thread.currentThread(
).getContextClassLoader().loadClass(
driverClassName);
}
} catch (Throwable t) {
String message = "Cannot load JDBC driver class '" +
driverClassName + "'";
logWriter.println(message);
t.printStackTrace(logWriter);
throw new SQLNestedException(message, t);
}
}
// Create a JDBC driver instance
Driver driver = null;
try {
if (driverFromCCL == null) {
driver = DriverManager.getDriver(url);
} else {
// Usage of DriverManager is not possible, as it does not
// respect the ContextClassLoader
driver = (Driver) driverFromCCL.newInstance();
if (!driver.acceptsURL(url)) {
throw new SQLException("No suitable driver", "08001");
}
}
} catch (Throwable t) {
String message = "Cannot create JDBC driver of class '" +
(driverClassName != null ? driverClassName : "") +
"' for connect URL '" + url + "'";
logWriter.println(message);
t.printStackTrace(logWriter);
throw new SQLNestedException(message, t);
}
// Can't test without a validationQuery
if (validationQuery == null) {
setTestOnBorrow(false);
setTestOnReturn(false);
setTestWhileIdle(false);
}
// Set up the driver connection factory we will use
String user = username;
if (user != null) {
connectionProperties.put("user", user);
} else {
log("DBCP DataSource configured without a 'username'");
}
String pwd = password;
if (pwd != null) {
connectionProperties.put("password", pwd);
} else {
log("DBCP DataSource configured without a 'password'");
}
ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, url, connectionProperties);
return driverConnectionFactory;
}
Creates a JDBC connection factory for this datasource. This method only
exists so subclasses can replace the implementation class. |
protected void createConnectionPool() {
// Create an object pool to contain our active connections
GenericObjectPool gop;
if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) {
gop = new AbandonedObjectPool(null,abandonedConfig);
}
else {
gop = new GenericObjectPool();
}
gop.setMaxActive(maxActive);
gop.setMaxIdle(maxIdle);
gop.setMinIdle(minIdle);
gop.setMaxWait(maxWait);
gop.setTestOnBorrow(testOnBorrow);
gop.setTestOnReturn(testOnReturn);
gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
gop.setTestWhileIdle(testWhileIdle);
connectionPool = gop;
}
Creates a connection pool for this datasource. This method only exists
so subclasses can replace the implementation class. |
protected synchronized DataSource createDataSource() throws SQLException {
if (closed) {
throw new SQLException("Data source is closed");
}
// Return the pool if we have already created it
if (dataSource != null) {
return (dataSource);
}
// create factory which returns raw physical connections
ConnectionFactory driverConnectionFactory = createConnectionFactory();
// create a pool for our connections
createConnectionPool();
// Set up statement pool, if desired
GenericKeyedObjectPoolFactory statementPoolFactory = null;
if (isPoolPreparedStatements()) {
statementPoolFactory = new GenericKeyedObjectPoolFactory(null,
-1, // unlimited maxActive (per key)
GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
0, // maxWait
1, // maxIdle (per key)
maxOpenPreparedStatements);
}
// Set up the poolable connection factory
createPoolableConnectionFactory(driverConnectionFactory, statementPoolFactory, abandonedConfig);
// Create and return the pooling data source to manage the connections
createDataSourceInstance();
try {
for (int i = 0 ; i < initialSize ; i++) {
connectionPool.addObject();
}
} catch (Exception e) {
throw new SQLNestedException("Error preloading the connection pool", e);
}
return dataSource;
}
Create (if necessary) and return the internal data source we are
using to manage our connections.
IMPLEMENTATION NOTE - It is tempting to use the
"double checked locking" idiom in an attempt to avoid synchronizing
on every single call to this method. However, this idiom fails to
work correctly in the face of some optimizations that are legal for
a JVM to perform.
|
protected void createDataSourceInstance() throws SQLException {
PoolingDataSource pds = new PoolingDataSource(connectionPool);
pds.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
pds.setLogWriter(logWriter);
dataSource = pds;
}
Creates the actual data source instance. This method only exists so
subclasses can replace the implementation class. |
protected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
KeyedObjectPoolFactory statementPoolFactory,
AbandonedConfig configuration) throws SQLException {
PoolableConnectionFactory connectionFactory = null;
try {
connectionFactory =
new PoolableConnectionFactory(driverConnectionFactory,
connectionPool,
statementPoolFactory,
validationQuery,
validationQueryTimeout,
connectionInitSqls,
defaultReadOnly,
defaultAutoCommit,
defaultTransactionIsolation,
defaultCatalog,
configuration);
validateConnectionFactory(connectionFactory);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new SQLNestedException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
}
}
Creates the PoolableConnectionFactory and attaches it to the connection pool. This method only exists
so subclasses can replace the default implementation. |
public Connection getConnection() throws SQLException {
return createDataSource().getConnection();
}
Create (if necessary) and return a connection to the database. |
public Connection getConnection(String user,
String pass) throws SQLException {
// This method isn't supported by the PoolingDataSource returned by
// the createDataSource
throw new UnsupportedOperationException("Not supported by BasicDataSource");
// return createDataSource().getConnection(username, password);
}
BasicDataSource does NOT support this method. |
public Collection getConnectionInitSqls() {
Collection result = connectionInitSqls;
if (result == null) {
return Collections.EMPTY_LIST;
}
return result;
}
Returns the list of SQL statements executed when a physical connection
is first created. Returns an empty list if there are no initialization
statements configured. |
public boolean getDefaultAutoCommit() {
return this.defaultAutoCommit;
}
Returns the default auto-commit property. |
public String getDefaultCatalog() {
return this.defaultCatalog;
}
Returns the default catalog. |
public boolean getDefaultReadOnly() {
Boolean val = defaultReadOnly;
if (val != null) {
return val.booleanValue();
}
return false;
}
Returns the default readOnly property. |
public int getDefaultTransactionIsolation() {
return this.defaultTransactionIsolation;
}
Returns the default transaction isolation state of returned connections. |
public synchronized ClassLoader getDriverClassLoader() {
return this.driverClassLoader;
}
Returns the class loader specified for loading the JDBC driver. Returns
null if no class loader has been explicitly specified. |
public synchronized String getDriverClassName() {
return this.driverClassName;
}
Returns the jdbc driver class name. |
public synchronized int getInitialSize() {
return this.initialSize;
}
Returns the initial size of the connection pool. |
public boolean getLogAbandoned() {
if (abandonedConfig != null) {
return abandonedConfig.getLogAbandoned();
}
return false;
}
Flag to log stack traces for application code which abandoned
a Statement or Connection.
Defaults to false.
Logging of abandoned Statements and Connections adds overhead
for every Connection open or new Statement because a stack
trace has to be generated.
|
public PrintWriter getLogWriter() throws SQLException {
return createDataSource().getLogWriter();
}
Returns the log writer being used by this data source.
Calls #createDataSource() , so has the side effect
of initializing the connection pool.
|
public int getLoginTimeout() throws SQLException {
// This method isn't supported by the PoolingDataSource returned by
// the createDataSource
throw new UnsupportedOperationException("Not supported by BasicDataSource");
//return createDataSource().getLoginTimeout();
}
BasicDataSource does NOT support this method.
Returns the login timeout (in seconds) for connecting to the database.
Calls #createDataSource() , so has the side effect
of initializing the connection pool. |
public synchronized int getMaxActive() {
return this.maxActive;
}
Returns the maximum number of active connections that can be
allocated at the same time.
A negative number means that there is no limit.
|
public synchronized int getMaxIdle() {
return this.maxIdle;
}
Returns the maximum number of connections that can remain idle in the
pool.
A negative value indicates that there is no limit
|
public synchronized int getMaxOpenPreparedStatements() {
return this.maxOpenPreparedStatements;
}
|
public synchronized long getMaxWait() {
return this.maxWait;
}
Returns the maximum number of milliseconds that the pool will wait
for a connection to be returned before throwing an exception.
A value less than or equal to zero means the pool is set to wait
indefinitely.
|
public synchronized long getMinEvictableIdleTimeMillis() {
return this.minEvictableIdleTimeMillis;
}
|
public synchronized int getMinIdle() {
return this.minIdle;
}
Returns the minimum number of idle connections in the pool |
public synchronized int getNumActive() {
if (connectionPool != null) {
return connectionPool.getNumActive();
} else {
return 0;
}
}
[Read Only] The current number of active connections that have been
allocated from this data source. |
public synchronized int getNumIdle() {
if (connectionPool != null) {
return connectionPool.getNumIdle();
} else {
return 0;
}
}
[Read Only] The current number of idle connections that are waiting
to be allocated from this data source. |
public synchronized int getNumTestsPerEvictionRun() {
return this.numTestsPerEvictionRun;
}
|
public String getPassword() {
return this.password;
}
Returns the password passed to the JDBC driver to establish connections. |
public boolean getRemoveAbandoned() {
if (abandonedConfig != null) {
return abandonedConfig.getRemoveAbandoned();
}
return false;
}
Flag to remove abandoned connections if they exceed the
removeAbandonedTimout.
Set to true or false, default false.
If set to true a connection is considered abandoned and eligible
for removal if it has been idle longer than the removeAbandonedTimeout.
Setting this to true can recover db connections from poorly written
applications which fail to close a connection.
Abandonded connections are identified and removed when
#getConnection() is invoked and the following conditions hold
|
public int getRemoveAbandonedTimeout() {
if (abandonedConfig != null) {
return abandonedConfig.getRemoveAbandonedTimeout();
}
return 300;
}
Timeout in seconds before an abandoned connection can be removed.
Defaults to 300 seconds. |
public synchronized boolean getTestOnBorrow() {
return this.testOnBorrow;
}
|
public synchronized boolean getTestOnReturn() {
return this.testOnReturn;
}
|
public synchronized boolean getTestWhileIdle() {
return this.testWhileIdle;
}
|
public synchronized long getTimeBetweenEvictionRunsMillis() {
return this.timeBetweenEvictionRunsMillis;
}
|
public synchronized String getUrl() {
return this.url;
}
Returns the JDBC connection #url property. |
public String getUsername() {
return this.username;
}
Returns the JDBC connection #username property. |
public String getValidationQuery() {
return this.validationQuery;
}
Returns the validation query used to validate connections before
returning them. |
public int getValidationQueryTimeout() {
return validationQueryTimeout;
}
Returns the validation query timeout. |
public synchronized boolean isAccessToUnderlyingConnectionAllowed() {
return this.accessToUnderlyingConnectionAllowed;
}
Returns the value of the accessToUnderlyingConnectionAllowed property. |
public synchronized boolean isClosed() {
return closed;
}
If true, this data source is closed and no more connections can be retrieved from this datasource. |
public synchronized boolean isPoolPreparedStatements() {
return this.poolPreparedStatements;
}
Returns true if we are pooling statements. |
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
|
protected void log(String message) {
if (logWriter != null) {
logWriter.println(message);
}
}
|
public void removeConnectionProperty(String name) {
connectionProperties.remove(name);
this.restartNeeded = true;
}
Remove a custom connection property. |
public synchronized void setAccessToUnderlyingConnectionAllowed(boolean allow) {
this.accessToUnderlyingConnectionAllowed = allow;
this.restartNeeded = true;
}
Sets the value of the accessToUnderlyingConnectionAllowed property.
It controls if the PoolGuard allows access to the underlying connection.
(Default: false)
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setConnectionInitSqls(Collection connectionInitSqls) {
if ((connectionInitSqls != null) && (connectionInitSqls.size() > 0)) {
ArrayList newVal = null;
for (Iterator iterator = connectionInitSqls.iterator();
iterator.hasNext();) {
Object o = iterator.next();
if (o != null) {
String s = o.toString();
if (s.trim().length() > 0) {
if (newVal == null) {
newVal = new ArrayList();
}
newVal.add(s);
}
}
}
this.connectionInitSqls = newVal;
} else {
this.connectionInitSqls = null;
}
this.restartNeeded = true;
}
Sets the list of SQL statements to be executed when a physical
connection is first created.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter. |
public void setConnectionProperties(String connectionProperties) {
if (connectionProperties == null) throw new NullPointerException("connectionProperties is null");
String[] entries = connectionProperties.split(";");
Properties properties = new Properties();
for (int i = 0; i < entries.length; i++) {
String entry = entries[i];
if (entry.length() > 0) {
int index = entry.indexOf('=');
if (index > 0) {
String name = entry.substring(0, index);
String value = entry.substring(index + 1);
properties.setProperty(name, value);
} else {
// no value is empty string which is how java.util.Properties works
properties.setProperty(entry, "");
}
}
}
this.connectionProperties = properties;
this.restartNeeded = true;
}
Sets the connection properties passed to driver.connect(...).
Format of the string must be [propertyName=property;]*
NOTE - The "user" and "password" properties will be added
explicitly, so they do not need to be included here. |
public void setDefaultAutoCommit(boolean defaultAutoCommit) {
this.defaultAutoCommit = defaultAutoCommit;
this.restartNeeded = true;
}
Sets default auto-commit state of connections returned by this
datasource.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setDefaultCatalog(String defaultCatalog) {
if ((defaultCatalog != null) && (defaultCatalog.trim().length() > 0)) {
this.defaultCatalog = defaultCatalog;
}
else {
this.defaultCatalog = null;
}
this.restartNeeded = true;
}
Sets the default catalog.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setDefaultReadOnly(boolean defaultReadOnly) {
this.defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
this.restartNeeded = true;
}
Sets defaultReadonly property.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
this.defaultTransactionIsolation = defaultTransactionIsolation;
this.restartNeeded = true;
}
Sets the default transaction isolation state for returned
connections.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public synchronized void setDriverClassLoader(ClassLoader driverClassLoader) {
this.driverClassLoader = driverClassLoader;
this.restartNeeded = true;
}
Sets the class loader to be used to load the JDBC driver.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public synchronized void setDriverClassName(String driverClassName) {
if ((driverClassName != null) && (driverClassName.trim().length() > 0)) {
this.driverClassName = driverClassName;
}
else {
this.driverClassName = null;
}
this.restartNeeded = true;
}
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public synchronized void setInitialSize(int initialSize) {
this.initialSize = initialSize;
this.restartNeeded = true;
}
Sets the initial size of the connection pool.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setLogAbandoned(boolean logAbandoned) {
if (abandonedConfig == null) {
abandonedConfig = new AbandonedConfig();
}
abandonedConfig.setLogAbandoned(logAbandoned);
this.restartNeeded = true;
}
|
public void setLogWriter(PrintWriter logWriter) throws SQLException {
createDataSource().setLogWriter(logWriter);
this.logWriter = logWriter;
}
Sets the log writer being used by this data source.
Calls #createDataSource() , so has the side effect
of initializing the connection pool.
|
public void setLoginTimeout(int loginTimeout) throws SQLException {
// This method isn't supported by the PoolingDataSource returned by
// the createDataSource
throw new UnsupportedOperationException("Not supported by BasicDataSource");
//createDataSource().setLoginTimeout(loginTimeout);
}
BasicDataSource does NOT support this method.
Set the login timeout (in seconds) for connecting to the
database.
Calls #createDataSource() , so has the side effect
of initializing the connection pool. |
public synchronized void setMaxActive(int maxActive) {
this.maxActive = maxActive;
if (connectionPool != null) {
connectionPool.setMaxActive(maxActive);
}
}
Sets the maximum number of active connections that can be
allocated at the same time. Use a negative value for no limit. |
public synchronized void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
if (connectionPool != null) {
connectionPool.setMaxIdle(maxIdle);
}
}
Sets the maximum number of connections that can remain idle in the
pool. |
public synchronized void setMaxOpenPreparedStatements(int maxOpenStatements) {
this.maxOpenPreparedStatements = maxOpenStatements;
this.restartNeeded = true;
}
Sets the value of the #maxOpenPreparedStatements
property.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public synchronized void setMaxWait(long maxWait) {
this.maxWait = maxWait;
if (connectionPool != null) {
connectionPool.setMaxWait(maxWait);
}
}
Sets the maxWait property.
Use -1 to make the pool wait indefinitely.
|
public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
if (connectionPool != null) {
connectionPool.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
}
|
public synchronized void setMinIdle(int minIdle) {
this.minIdle = minIdle;
if (connectionPool != null) {
connectionPool.setMinIdle(minIdle);
}
}
Sets the minimum number of idle connections in the pool. |
public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
if (connectionPool != null) {
connectionPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
}
}
|
public void setPassword(String password) {
this.password = password;
this.restartNeeded = true;
}
Sets the #password .
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public synchronized void setPoolPreparedStatements(boolean poolingStatements) {
this.poolPreparedStatements = poolingStatements;
this.restartNeeded = true;
}
Sets whether to pool statements or not.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setRemoveAbandoned(boolean removeAbandoned) {
if (abandonedConfig == null) {
abandonedConfig = new AbandonedConfig();
}
abandonedConfig.setRemoveAbandoned(removeAbandoned);
this.restartNeeded = true;
}
|
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
if (abandonedConfig == null) {
abandonedConfig = new AbandonedConfig();
}
abandonedConfig.setRemoveAbandonedTimeout(removeAbandonedTimeout);
this.restartNeeded = true;
}
|
public synchronized void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
if (connectionPool != null) {
connectionPool.setTestOnBorrow(testOnBorrow);
}
}
Sets the #testOnBorrow property. This property determines
whether or not the pool will validate objects before they are borrowed
from the pool. For a true value to have any effect, the
validationQuery property must be set to a non-null string. |
public synchronized void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
if (connectionPool != null) {
connectionPool.setTestOnReturn(testOnReturn);
}
}
Sets the testOnReturn property. This property determines
whether or not the pool will validate objects before they are returned
to the pool. For a true value to have any effect, the
validationQuery property must be set to a non-null string. |
public synchronized void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
if (connectionPool != null) {
connectionPool.setTestWhileIdle(testWhileIdle);
}
}
Sets the testWhileIdle property. This property determines
whether or not the idle object evictor will validate connections. For a
true value to have any effect, the
validationQuery property must be set to a non-null string. |
public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
if (connectionPool != null) {
connectionPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
}
|
public synchronized void setUrl(String url) {
this.url = url;
this.restartNeeded = true;
}
Sets the #url .
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setUsername(String username) {
this.username = username;
this.restartNeeded = true;
}
Sets the #username .
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setValidationQuery(String validationQuery) {
if ((validationQuery != null) && (validationQuery.trim().length() > 0)) {
this.validationQuery = validationQuery;
} else {
this.validationQuery = null;
}
this.restartNeeded = true;
}
Sets the #validationQuery .
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
|
public void setValidationQueryTimeout(int timeout) {
this.validationQueryTimeout = timeout;
restartNeeded = true;
}
Sets the validation query timeout, the amount of time, in seconds, that
connection validation will wait for a response from the database when
executing a validation query. Use a value less than or equal to 0 for
no timeout.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter. |
public T unwrap(Class<T> iface) throws SQLException {
throw new SQLException("BasicDataSource is not a wrapper.");
}
|
protected static void validateConnectionFactory(PoolableConnectionFactory connectionFactory) throws Exception {
Connection conn = null;
try {
conn = (Connection) connectionFactory.makeObject();
connectionFactory.activateObject(conn);
connectionFactory.validateConnection(conn);
connectionFactory.passivateObject(conn);
}
finally {
connectionFactory.destroyObject(conn);
}
}
|