Class BasicDataSource
- All Implemented Interfaces:
AutoCloseable, Wrapper, MBeanRegistration, CommonDataSource, DataSource, BasicDataSourceMXBean
Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is not
the only way to combine the commons-dbcp2 and commons-pool2 packages, but provides a "one stop
shopping" solution for basic requirements.
- Since:
- 2.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AbandonedConfigprivate booleanControls access to the underlying connection.private booleanprivate booleanThe property that controls if the pooled connections cache some state rather than query the database for current state to improve performance.private booleanprivate StringThe fully qualified Java class name of aConnectionFactoryimplementation.These SQL statements run once after a Connection is created.private GenericObjectPool<PoolableConnection> The object pool that internally manages our connections.private PropertiesThe connection properties that will be sent to our JDBC driver when establishing new connections.private DataSourceThe data source we will use to manage connections.private BooleanThe default auto-commit state of connections created by this pool.private StringThe default "catalog" of connections created by this pool.private Integerprivate BooleanThe default read-only state of connections created by this pool.private StringThe default "schema" of connections created by this pool.private intThe default TransactionIsolation state of connections created by this pool.private DriverThe instance of the JDBC Driver to use.private ClassLoaderThe class loader instance to use to load the JDBC driver.private StringThe fully qualified Java class name of the JDBC driver to be used.private Stringprivate booleanprivate intThe initial number of connections that are created when the pool is started.private Stringprivate booleanTrue means that borrowObject returns the most recently used ("last in") connection in the pool (if there are idle connections available).private static final org.datanucleus.util.NucleusLoggerprivate booleanprivate PrintWriterThe PrintWriter to which log messages should be directed.private longprivate intThe maximum number of connections that can remain idle in the pool, without extra ones being destroyed, or negative for no limit.private intThe maximum number of open statements that can be allocated from the statement pool at the same time, or negative for no limit.private intThe maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.private longThe maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or invalid input: '<'= 0 to wait indefinitely.private longThe minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any).private intThe minimum number of active connections that can remain idle in the pool, without extra ones being created when the evictor runs, or 0 to create none.private intThe number of objects to examine during each run of the idle object evictor thread (if any).private StringThe connection password to be passed to our JDBC driver to establish a connection.private booleanPrepared statement pooling for this pool.private ObjectNameWrapperActual name under which this component has been registered.private booleanprivate longThe minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool.private booleanThe indication of whether objects will be validated before being borrowed from the pool.private booleanThe indication of whether objects will be validated as soon as they have been created by the pool.private booleanThe indication of whether objects will be validated before being returned to the pool.private booleanThe indication of whether objects will be validated by the idle object evictor (if any).private longThe number of milliseconds to sleep between runs of the idle object evictor thread.private StringThe connection URL to be passed to our JDBC driver to establish a connection.private StringThe connection user name to be passed to our JDBC driver to establish a connection.private StringThe SQL query that will be used to validate connections from this pool before returning them to the caller.private intTimeout in seconds before connection validation queries fail. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnectionProperty(String name, String value) Adds a custom connection property to the set that will be passed to our JDBC driver.voidclose()Closes and releases all idle connections that are currently stored in the connection pool associated with this data source.private voidCloses the connection pool, silently swallowing any exception that occurs.protected ConnectionFactoryCreates a JDBC connection factory for this data source.protected voidCreates a connection pool for this datasource.protected DataSourceCreates (if necessary) and return the internal data source we are using to manage our connections.protected DataSourceCreates the actual data source instance.protected GenericObjectPool<PoolableConnection> createObjectPool(PoolableConnectionFactory factory, GenericObjectPoolConfig<PoolableConnection> poolConfig, AbandonedConfig abandonedConfig) Creates an object pool used to provide pooling support forJDBC connections.protected PoolableConnectionFactorycreatePoolableConnectionFactory(ConnectionFactory driverConnectionFactory) Creates the PoolableConnectionFactory and attaches it to the connection pool.voidevict()Manually evicts idle connectionsGets the print writer used by this configuration to log information on abandoned objects.booleanIf the connection pool implementsUsageTracking, should the connection pool record a stack trace every time a method is called on a pooled connection and retain the most recent stack trace to aid debugging of abandoned connections?booleanReturns the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned.booleanReturns the state caching flag.Creates (if necessary) and return a connection to the database.getConnection(String user, String pass) BasicDataSource does NOT support this method.Returns the ConnectionFactoryClassName that has been configured for use by this pool.Returns the list of SQL statements executed when a physical connection is first created.String[]Provides the same data asgetConnectionInitSqls()but in an array so it is accessible via JMX.protected GenericObjectPool<PoolableConnection> (package private) PropertiesReturns the default auto-commit property.Returns the default catalog.Gets the default query timeout that will be used forStatements created from this connection.Returns the default readOnly property.Returns the default schema.intReturns the default transaction isolation state of returned connections.Returns the set of SQL_STATE codes considered to signal fatal conditions.String[]Provides the same data asgetDisconnectionSqlCodes()but in an array so it is accessible via JMX.Returns the JDBC Driver that has been configured for use by this pool.Returns the class loader specified for loading the JDBC driver.Returns the JDBC driver class name.booleanDeprecated.Gets the EvictionPolicy implementation in use with this connection pool.booleanTrue means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL_STATE indicating fatal disconnection errors.intReturns the initial size of the connection pool.Returns the JMX name that has been requested for this DataSource.booleangetLifo()Returns the LIFO property.booleanFlag to log stack traces for application code which abandoned a Statement or Connection.booleanWhengetMaxConnLifetimeMillis()is set to limit connection lifetime, this property determines whether or not log messages are generated when the pool closes connections due to maximum lifetime exceeded.intBasicDataSource does NOT support this method.Returns the log writer being used by this data source.longReturns the maximum permitted lifetime of a connection in milliseconds.intReturns the maximum number of connections that can remain idle in the pool.intGets the value of themaxOpenPreparedStatementsproperty.intReturns the maximum number of active connections that can be allocated at the same time.longReturns the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.longReturns theminEvictableIdleTimeMillisproperty.intReturns the minimum number of idle connections in the pool.int[Read Only] The current number of active connections that have been allocated from this data source.int[Read Only] The current number of idle connections that are waiting to be allocated from this data source.intReturns the value of thenumTestsPerEvictionRunproperty.Returns the password passed to the JDBC driver to establish connections.protected ObjectNamebooleanFlag to remove abandoned connections if they exceed the removeAbandonedTimeout when borrowObject is invoked.booleanFlag to remove abandoned connections if they exceed the removeAbandonedTimeout during pool maintenance.intTimeout in seconds before an abandoned connection can be removed.booleanGets the current value of the flag that controls whether a connection will be rolled back when it is returned to the pool if auto commit is not enabled and the connection is not read only.longReturns the minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool.booleanReturns thetestOnBorrowproperty.booleanReturns thetestOnCreateproperty.booleanReturns the value of thetestOnReturnproperty.booleanReturns the value of thetestWhileIdleproperty.longReturns the value of thetimeBetweenEvictionRunsMillisproperty.getUrl()Returns the JDBC connectionurlproperty.Returns the JDBC connectionuserNameproperty.Returns the validation query used to validate connections before returning them.intReturns the validation query timeout.voidinvalidateConnection(Connection connection) Manually invalidates a connection, effectively requesting the pool to try to close it, remove it from the pool and reclaim pool capacity.booleanReturns the value of the accessToUnderlyingConnectionAllowed property.booleanisClosed()If true, this data source is closed and no more connections can be retrieved from this data source.private booleanDelegates in a null-safe manner toString.isEmpty().booleanReturns true if we are pooling statements.booleanisWrapperFor(Class<?> iface) private voidprotected voidprotected voidLogs the given throwable.voidvoidpostRegister(Boolean registrationDone) voidpreRegister(MBeanServer server, ObjectName objectName) voidRemoves a custom connection property.voidsetAbandonedLogWriter(PrintWriter logWriter) Sets the print writer to be used by this configuration to log information on abandoned objects.voidsetAbandonedUsageTracking(boolean usageTracking) If the connection pool implementsUsageTracking, configure whether the connection pool should record a stack trace every time a method is called on a pooled connection and retain the most recent stack trace to aid debugging of abandoned connections.voidsetAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property.voidsetAutoCommitOnReturn(boolean autoCommitOnReturn) Sets the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned.voidsetCacheState(boolean cacheState) Sets the state caching flag.voidsetConnectionFactoryClassName(String connectionFactoryClassName) Sets the ConnectionFactory class name.voidsetConnectionInitSqls(Collection<String> connectionInitSqls) Sets the list of SQL statements to be executed when a physical connection is first created.voidsetConnectionProperties(String connectionProperties) Sets the connection properties passed to driver.connect(...).voidsetDefaultAutoCommit(Boolean defaultAutoCommit) Sets default auto-commit state of connections returned by this datasource.voidsetDefaultCatalog(String defaultCatalog) Sets the default catalog.voidsetDefaultQueryTimeout(Integer defaultQueryTimeoutSeconds) Sets the default query timeout that will be used forStatements created from this connection.voidsetDefaultReadOnly(Boolean defaultReadOnly) Sets defaultReadonly property.voidsetDefaultSchema(String defaultSchema) Sets the default schema.voidsetDefaultTransactionIsolation(int defaultTransactionIsolation) Sets the default transaction isolation state for returned connections.voidsetDisconnectionSqlCodes(Collection<String> disconnectionSqlCodes) Sets the SQL_STATE codes considered to signal fatal conditions.voidSets the JDBC Driver instance to use for this pool.voidsetDriverClassLoader(ClassLoader driverClassLoader) Sets the class loader to be used to load the JDBC driver.voidsetDriverClassName(String driverClassName) Sets the JDBC driver class name.voidsetEnableAutoCommitOnReturn(boolean autoCommitOnReturn) Deprecated.voidsetEvictionPolicyClassName(String evictionPolicyClassName) Sets the EvictionPolicy implementation to use with this connection pool.voidsetFastFailValidation(boolean fastFailValidation) voidsetInitialSize(int initialSize) Sets the initial size of the connection pool.voidsetJmxName(String jmxName) Sets the JMX name that has been requested for this DataSource.voidsetLifo(boolean lifo) Sets the LIFO property.voidsetLogAbandoned(boolean logAbandoned) voidsetLogExpiredConnections(boolean logExpiredConnections) WhengetMaxConnLifetimeMillis()is set to limit connection lifetime, this property determines whether or not log messages are generated when the pool closes connections due to maximum lifetime exceeded.voidsetLoginTimeout(int loginTimeout) BasicDataSource does NOT support this method.voidsetLogWriter(PrintWriter logWriter) Sets the log writer being used by this data source.voidsetMaxConnLifetimeMillis(long maxConnLifetimeMillis) Sets the maximum permitted lifetime of a connection in milliseconds.voidsetMaxIdle(int maxIdle) Sets the maximum number of connections that can remain idle in the pool.voidsetMaxOpenPreparedStatements(int maxOpenStatements) Sets the value of themaxOpenPreparedStatementsproperty.voidsetMaxTotal(int maxTotal) Sets the maximum total number of idle and borrows connections that can be active at the same time.voidsetMaxWaitMillis(long maxWaitMillis) Sets the MaxWaitMillis property.voidsetMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Sets theminEvictableIdleTimeMillisproperty.voidsetMinIdle(int minIdle) Sets the minimum number of idle connections in the pool.voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun) Sets the value of thenumTestsPerEvictionRunproperty.voidsetPassword(String password) Sets thepassword.voidsetPoolPreparedStatements(boolean poolingStatements) Sets whether to pool statements or not.voidsetRemoveAbandonedOnBorrow(boolean removeAbandonedOnBorrow) voidsetRemoveAbandonedOnMaintenance(boolean removeAbandonedOnMaintenance) voidsetRemoveAbandonedTimeout(int removeAbandonedTimeout) Sets the timeout in seconds before an abandoned connection can be removed.voidsetRollbackOnReturn(boolean rollbackOnReturn) Sets the flag that controls if a connection will be rolled back when it is returned to the pool if auto commit is not enabled and the connection is not read only.voidsetSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) Sets the minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool.voidsetTestOnBorrow(boolean testOnBorrow) Sets thetestOnBorrowproperty.voidsetTestOnCreate(boolean testOnCreate) Sets thetestOnCreateproperty.voidsetTestOnReturn(boolean testOnReturn) Sets thetestOnReturnproperty.voidsetTestWhileIdle(boolean testWhileIdle) Sets thetestWhileIdleproperty.voidsetTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Sets thetimeBetweenEvictionRunsMillisproperty.voidSets theurl.voidsetUsername(String userName) Sets theuserName.voidsetValidationQuery(String validationQuery) Sets thevalidationQuery.voidsetValidationQueryTimeout(int validationQueryTimeoutSeconds) 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.protected voidStarts the connection pool maintenance task, if configured.<T> Tprivate voidupdateJmxName(GenericObjectPoolConfig<?> config) protected static voidvalidateConnectionFactory(PoolableConnectionFactory connectionFactory) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilderMethods inherited from interface DataSource
createConnectionBuilder
-
Field Details
-
log
private static final org.datanucleus.util.NucleusLogger log -
defaultAutoCommit
The default auto-commit state of connections created by this pool. -
defaultReadOnly
The default read-only state of connections created by this pool. -
defaultTransactionIsolation
private volatile int defaultTransactionIsolationThe default TransactionIsolation state of connections created by this pool. -
defaultQueryTimeoutSeconds
-
defaultCatalog
The default "catalog" of connections created by this pool. -
defaultSchema
The default "schema" of connections created by this pool. -
cacheState
private boolean cacheStateThe property that controls if the pooled connections cache some state rather than query the database for current state to improve performance. -
driver
The instance of the JDBC Driver to use. -
driverClassName
The fully qualified Java class name of the JDBC driver to be used. -
driverClassLoader
The class loader instance to use to load the JDBC driver. If not specified,Class.forName(String)is used to load the JDBC driver. If specified,Class.forName(String, boolean, ClassLoader)is used. -
lifo
private boolean lifoTrue means that borrowObject returns the most recently used ("last in") connection in the pool (if there are idle connections available). False means that the pool behaves as a FIFO queue - connections are taken from the idle instance pool in the order that they are returned to the pool. -
maxTotal
private int maxTotalThe maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit. -
maxIdle
private int maxIdleThe maximum number of connections that can remain idle in the pool, without extra ones being destroyed, or negative for no limit. If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point. -
minIdle
private int minIdleThe minimum number of active connections that can remain idle in the pool, without extra ones being created when the evictor runs, or 0 to create none. The pool attempts to ensure that minIdle connections are available when the idle object evictor runs. The value of this property has no effect unlesstimeBetweenEvictionRunsMillishas a positive value. -
initialSize
private int initialSizeThe initial number of connections that are created when the pool is started. -
maxWaitMillis
private long maxWaitMillisThe maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or invalid input: '<'= 0 to wait indefinitely. -
poolPreparedStatements
private boolean poolPreparedStatementsPrepared statement pooling for this pool. When this property is set totrueboth PreparedStatements and CallableStatements are pooled. -
maxOpenPreparedStatements
private int maxOpenPreparedStatementsThe maximum number of open statements that can be allocated from the statement pool at the same time, or negative for no limit. Since a connection usually only uses one or two statements at a time, this is mostly used to help detect resource leaks.
Note: As of version 1.3, CallableStatements (those produced by
Connection.prepareCall(String)) are pooled along with PreparedStatements (produced byConnection.prepareStatement(String)) andmaxOpenPreparedStatementslimits the total number of prepared or callable statements that may be in use at a given time. -
testOnCreate
private boolean testOnCreateThe indication of whether objects will be validated as soon as they have been created by the pool. If the object fails to validate, the borrow operation that triggered the creation will fail. -
testOnBorrow
private boolean testOnBorrowThe indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. -
testOnReturn
private boolean testOnReturnThe indication of whether objects will be validated before being returned to the pool. -
timeBetweenEvictionRunsMillis
private long timeBetweenEvictionRunsMillisThe number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run. -
numTestsPerEvictionRun
private int numTestsPerEvictionRunThe number of objects to examine during each run of the idle object evictor thread (if any). -
minEvictableIdleTimeMillis
private long minEvictableIdleTimeMillisThe minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any). -
softMinEvictableIdleTimeMillis
private long softMinEvictableIdleTimeMillisThe minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool. Note thatminEvictableIdleTimeMillistakes precedence over this parameter. SeegetSoftMinEvictableIdleTimeMillis(). -
evictionPolicyClassName
-
testWhileIdle
private boolean testWhileIdleThe indication of whether objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool. -
password
The connection password to be passed to our JDBC driver to establish a connection. -
url
The connection URL to be passed to our JDBC driver to establish a connection. -
userName
The connection user name to be passed to our JDBC driver to establish a connection. -
validationQuery
The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. If not specified,Connection.isValid(int)will be used to validate connections. -
validationQueryTimeoutSeconds
private volatile int validationQueryTimeoutSecondsTimeout in seconds before connection validation queries fail. -
connectionFactoryClassName
The fully qualified Java class name of aConnectionFactoryimplementation. -
connectionInitSqls
-
accessToUnderlyingConnectionAllowed
private boolean accessToUnderlyingConnectionAllowedControls access to the underlying connection. -
maxConnLifetimeMillis
private long maxConnLifetimeMillis -
logExpiredConnections
private boolean logExpiredConnections -
jmxName
-
autoCommitOnReturn
private boolean autoCommitOnReturn -
rollbackOnReturn
private boolean rollbackOnReturn -
disconnectionSqlCodes
-
fastFailValidation
private boolean fastFailValidation -
connectionPool
The object pool that internally manages our connections. -
connectionProperties
The connection properties that will be sent to our JDBC driver when establishing new connections. NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here. -
dataSource
The data source we will use to manage connections. This object should be acquired ONLY by calls to thecreateDataSource()method. -
logWriter
The PrintWriter to which log messages should be directed. -
abandonedConfig
-
closed
private boolean closed -
registeredJmxObjectName
Actual name under which this component has been registered.
-
-
Constructor Details
-
BasicDataSource
public BasicDataSource()
-
-
Method Details
-
validateConnectionFactory
protected static void validateConnectionFactory(PoolableConnectionFactory connectionFactory) throws Exception - Throws:
Exception
-
addConnectionProperty
Adds 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.- Parameters:
name- Name of the custom connection propertyvalue- Value of the custom connection property
-
close
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.
- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException- if an error occurs closing idle connections
-
closeConnectionPool
private void closeConnectionPool()Closes the connection pool, silently swallowing any exception that occurs. -
createConnectionFactory
Creates a JDBC connection factory for this data source. The JDBC driver is loaded using the following algorithm:- If a Driver instance has been specified via
setDriver(Driver)use it - If no Driver instance was specified and
driverClassNameis specified that class is loaded using theClassLoaderof this class or, ifdriverClassLoaderis set,driverClassNameis loaded with the specifiedClassLoader. - If
driverClassNameis specified and the previous attempt fails, the class is loaded using the context class loader of the current thread. - If a driver still isn't loaded one is loaded via the
DriverManagerusing the specifiedurl.
This method exists so subclasses can replace the implementation class.
- Returns:
- A new connection factory.
- Throws:
SQLException- If the connection factort cannot be created
- If a Driver instance has been specified via
-
createConnectionPool
Creates a connection pool for this datasource. This method only exists so subclasses can replace the implementation class.This implementation configures all pool properties other than timeBetweenEvictionRunsMillis. Setting that property is deferred to
startPoolMaintenance(), since setting timeBetweenEvictionRunsMillis to a positive value causesGenericObjectPool's eviction timer to be started.- Parameters:
factory- The factory to use to create new connections for this pool.
-
createDataSource
Creates (if necessary) and return the internal data source we are using to manage our connections.
- Returns:
- The current internal DataSource or a newly created instance if it has not yet been created.
- Throws:
SQLException- if the object pool cannot be created.
-
createDataSourceInstance
Creates the actual data source instance. This method only exists so that subclasses can replace the implementation class.- Returns:
- A new DataSource instance
- Throws:
SQLException- if unable to create a datasource instance
-
createObjectPool
protected GenericObjectPool<PoolableConnection> createObjectPool(PoolableConnectionFactory factory, GenericObjectPoolConfig<PoolableConnection> poolConfig, AbandonedConfig abandonedConfig) Creates an object pool used to provide pooling support forJDBC connections.- Parameters:
factory- the object factorypoolConfig- the object pool configurationabandonedConfig- the abandoned objects configuration- Returns:
- a non-null instance
-
createPoolableConnectionFactory
protected PoolableConnectionFactory createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory) throws SQLException Creates the PoolableConnectionFactory and attaches it to the connection pool. This method only exists so subclasses can replace the default implementation.- Parameters:
driverConnectionFactory- JDBC connection factory- Returns:
- A new PoolableConnectionFactory configured with the current configuration of this BasicDataSource
- Throws:
SQLException- if an error occurs creating the PoolableConnectionFactory
-
evict
-
getAbandonedLogWriter
Gets the print writer used by this configuration to log information on abandoned objects.- Returns:
- The print writer used by this configuration to log information on abandoned objects.
-
getAbandonedUsageTracking
public boolean getAbandonedUsageTracking()If the connection pool implementsUsageTracking, should the connection pool record a stack trace every time a method is called on a pooled connection and retain the most recent stack trace to aid debugging of abandoned connections?- Specified by:
getAbandonedUsageTrackingin interfaceBasicDataSourceMXBean- Returns:
trueif usage tracking is enabled
-
getAutoCommitOnReturn
public boolean getAutoCommitOnReturn()Returns the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned. It istrueby default.- Returns:
- Whether or not connections being returned to the pool will be checked and configured with auto-commit.
-
getCacheState
public boolean getCacheState()Returns the state caching flag.- Specified by:
getCacheStatein interfaceBasicDataSourceMXBean- Returns:
- the state caching flag
-
getConnection
Creates (if necessary) and return a connection to the database.- Specified by:
getConnectionin interfaceDataSource- Returns:
- a database connection
- Throws:
SQLException- if a database access error occurs
-
getConnection
BasicDataSource does NOT support this method.- Specified by:
getConnectionin interfaceDataSource- Parameters:
user- Database user on whose behalf the Connection is being madepass- The database user's password- Returns:
- nothing - always throws UnsupportedOperationException
- Throws:
UnsupportedOperationException- always thrown.SQLException- if a database access error occurs
-
getConnectionFactoryClassName
Returns the ConnectionFactoryClassName that has been configured for use by this pool.Note: This getter only returns the last value set by a call to
setConnectionFactoryClassName(String).- Returns:
- the ConnectionFactoryClassName that has been configured for use by this pool.
- Since:
- 2.7.0
-
getConnectionInitSqls
-
getConnectionInitSqlsAsArray
Provides the same data asgetConnectionInitSqls()but in an array so it is accessible via JMX.- Specified by:
getConnectionInitSqlsAsArrayin interfaceBasicDataSourceMXBean- Returns:
getConnectionInitSqlsAsArray()
-
getConnectionPool
-
getConnectionProperties
Properties getConnectionProperties() -
getDefaultAutoCommit
Returns the default auto-commit property.- Specified by:
getDefaultAutoCommitin interfaceBasicDataSourceMXBean- Returns:
- true if default auto-commit is enabled
-
getDefaultCatalog
Returns the default catalog.- Specified by:
getDefaultCatalogin interfaceBasicDataSourceMXBean- Returns:
- the default catalog
-
getDefaultQueryTimeout
-
getDefaultReadOnly
Returns the default readOnly property.- Specified by:
getDefaultReadOnlyin interfaceBasicDataSourceMXBean- Returns:
- true if connections are readOnly by default
-
getDefaultSchema
Returns the default schema.- Specified by:
getDefaultSchemain interfaceBasicDataSourceMXBean- Returns:
- the default schema.
- Since:
- 2.5.0
-
getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()Returns the default transaction isolation state of returned connections.- Specified by:
getDefaultTransactionIsolationin interfaceBasicDataSourceMXBean- Returns:
- the default value for transaction isolation state
- See Also:
-
getDisconnectionSqlCodes
-
getDisconnectionSqlCodesAsArray
Provides the same data asgetDisconnectionSqlCodes()but in an array so it is accessible via JMX.- Specified by:
getDisconnectionSqlCodesAsArrayin interfaceBasicDataSourceMXBean- Returns:
getDisconnectionSqlCodesAsArray()- Since:
- 2.1
-
getDriver
Returns the JDBC Driver that has been configured for use by this pool.Note: This getter only returns the last value set by a call to
setDriver(Driver). It does not return any driver instance that may have been created from the value set viasetDriverClassName(String).- Returns:
- the JDBC Driver that has been configured for use by this pool
-
getDriverClassLoader
Returns the class loader specified for loading the JDBC driver. Returnsnullif no class loader has been explicitly specified.Note: This getter only returns the last value set by a call to
setDriverClassLoader(ClassLoader). It does not return the class loader of any driver that may have been set viasetDriver(Driver).- Returns:
- The class loader specified for loading the JDBC driver.
-
getDriverClassName
Returns the JDBC driver class name.Note: This getter only returns the last value set by a call to
setDriverClassName(String). It does not return the class name of any driver that may have been set viasetDriver(Driver).- Specified by:
getDriverClassNamein interfaceBasicDataSourceMXBean- Returns:
- the JDBC driver class name
-
getEnableAutoCommitOnReturn
Deprecated.Returns the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned. It istrueby default.- Returns:
- Whether or not connections being returned to the pool will be checked and configured with auto-commit.
-
getEvictionPolicyClassName
Gets the EvictionPolicy implementation in use with this connection pool.- Returns:
- The EvictionPolicy implementation in use with this connection pool.
-
getFastFailValidation
public boolean getFastFailValidation()True means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL_STATE indicating fatal disconnection errors.- Specified by:
getFastFailValidationin interfaceBasicDataSourceMXBean- Returns:
- true if connections created by this datasource will fast fail validation.
- Since:
- 2.1
- See Also:
-
getInitialSize
public int getInitialSize()Returns the initial size of the connection pool.- Specified by:
getInitialSizein interfaceBasicDataSourceMXBean- Returns:
- the number of connections created when the pool is initialized
-
getJmxName
Returns the JMX name that has been requested for this DataSource. If the requested name is not valid, an alternative may be chosen.- Returns:
- The JMX name that has been requested for this DataSource.
-
getLifo
public boolean getLifo()Returns the LIFO property.- Specified by:
getLifoin interfaceBasicDataSourceMXBean- Returns:
- true if connection pool behaves as a LIFO queue.
-
getLogAbandoned
public boolean getLogAbandoned()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.
- Specified by:
getLogAbandonedin interfaceBasicDataSourceMXBean- Returns:
getLogAbandoned()
-
getLogExpiredConnections
public boolean getLogExpiredConnections()WhengetMaxConnLifetimeMillis()is set to limit connection lifetime, this property determines whether or not log messages are generated when the pool closes connections due to maximum lifetime exceeded.- Specified by:
getLogExpiredConnectionsin interfaceBasicDataSourceMXBean- Returns:
getLogExpiredConnections()- Since:
- 2.1
-
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.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Returns:
- login timeout in seconds
- Throws:
SQLException- if a database access error occursUnsupportedOperationException- If the DataSource implementation does not support the login timeout feature.
-
getLogWriter
Returns the log writer being used by this data source.
Calls
createDataSource(), so has the side effect of initializing the connection pool.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Returns:
- log writer in use
- Throws:
SQLException- if a database access error occurs
-
getMaxConnLifetimeMillis
public long getMaxConnLifetimeMillis()Returns the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.- Specified by:
getMaxConnLifetimeMillisin interfaceBasicDataSourceMXBean- Returns:
getMaxConnLifetimeMillis()
-
getMaxIdle
public int getMaxIdle()Returns the maximum number of connections that can remain idle in the pool. Excess idle connections are destroyed on return to the pool.
A negative value indicates that there is no limit
- Specified by:
getMaxIdlein interfaceBasicDataSourceMXBean- Returns:
- the maximum number of idle connections
-
getMaxOpenPreparedStatements
public int getMaxOpenPreparedStatements()Gets the value of themaxOpenPreparedStatementsproperty.- Specified by:
getMaxOpenPreparedStatementsin interfaceBasicDataSourceMXBean- Returns:
- the maximum number of open statements
-
getMaxTotal
public int getMaxTotal()Returns the maximum number of active connections that can be allocated at the same time.
A negative number means that there is no limit.
- Specified by:
getMaxTotalin interfaceBasicDataSourceMXBean- Returns:
- the maximum number of active connections
-
getMaxWaitMillis
public long getMaxWaitMillis()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.- Specified by:
getMaxWaitMillisin interfaceBasicDataSourceMXBean- Returns:
- the maxWaitMillis property value
-
getMinEvictableIdleTimeMillis
public long getMinEvictableIdleTimeMillis()Returns theminEvictableIdleTimeMillisproperty.- Specified by:
getMinEvictableIdleTimeMillisin interfaceBasicDataSourceMXBean- Returns:
- the value of the
minEvictableIdleTimeMillisproperty - See Also:
-
getMinIdle
public int getMinIdle()Returns the minimum number of idle connections in the pool. The pool attempts to ensure that minIdle connections are available when the idle object evictor runs. The value of this property has no effect unlesstimeBetweenEvictionRunsMillishas a positive value.- Specified by:
getMinIdlein interfaceBasicDataSourceMXBean- Returns:
- the minimum number of idle connections
- See Also:
-
getNumActive
public int getNumActive()[Read Only] The current number of active connections that have been allocated from this data source.- Specified by:
getNumActivein interfaceBasicDataSourceMXBean- Returns:
- the current number of active connections
-
getNumIdle
public int getNumIdle()[Read Only] The current number of idle connections that are waiting to be allocated from this data source.- Specified by:
getNumIdlein interfaceBasicDataSourceMXBean- Returns:
- the current number of idle connections
-
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()Returns the value of thenumTestsPerEvictionRunproperty.- Specified by:
getNumTestsPerEvictionRunin interfaceBasicDataSourceMXBean- Returns:
- the number of objects to examine during idle object evictor runs
- See Also:
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
getPassword
Returns the password passed to the JDBC driver to establish connections.- Specified by:
getPasswordin interfaceBasicDataSourceMXBean- Returns:
- the connection password
-
getRegisteredJmxName
-
getRemoveAbandonedOnBorrow
public boolean getRemoveAbandonedOnBorrow()Flag to remove abandoned connections if they exceed the removeAbandonedTimeout when borrowObject is invoked.
The default value is false.
If set to true a connection is considered abandoned and eligible for removal if it has not been used for more than
removeAbandonedTimeoutseconds.Abandoned connections are identified and removed when
getConnection()is invoked and all of the following conditions hold:- Specified by:
getRemoveAbandonedOnBorrowin interfaceBasicDataSourceMXBean- Returns:
getRemoveAbandonedOnBorrow()- See Also:
-
getRemoveAbandonedOnMaintenance
public boolean getRemoveAbandonedOnMaintenance()Flag to remove abandoned connections if they exceed the removeAbandonedTimeout during pool maintenance.
The default value is false.
If set to true a connection is considered abandoned and eligible for removal if it has not been used for more than
removeAbandonedTimeoutseconds.- Specified by:
getRemoveAbandonedOnMaintenancein interfaceBasicDataSourceMXBean- Returns:
getRemoveAbandonedOnMaintenance()- See Also:
-
getRemoveAbandonedTimeout
public int getRemoveAbandonedTimeout()Timeout in seconds before an abandoned connection can be removed.
Creating a Statement, PreparedStatement or CallableStatement or using one of these to execute a query (using one of the execute methods) resets the lastUsed property of the parent connection.
Abandoned connection cleanup happens when:
getRemoveAbandonedOnBorrow()orgetRemoveAbandonedOnMaintenance()= truenumIdle< 2numActive>maxTotal- 3
The default value is 300 seconds.
- Specified by:
getRemoveAbandonedTimeoutin interfaceBasicDataSourceMXBean- Returns:
getRemoveAbandonedTimeout()
-
getRollbackOnReturn
public boolean getRollbackOnReturn()Gets the current value of the flag that controls whether a connection will be rolled back when it is returned to the pool if auto commit is not enabled and the connection is not read only.- Returns:
- whether a connection will be rolled back when it is returned to the pool.
-
getSoftMinEvictableIdleTimeMillis
public long getSoftMinEvictableIdleTimeMillis()Returns the minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool.
When
minEvictableIdleTimeMillisis set to a positive value, minEvictableIdleTimeMillis is examined first by the idle connection evictor - i.e. when idle connections are visited by the evictor, idle time is first compared againstminEvictableIdleTimeMillis(without considering the number of idle connections in the pool) and then againstsoftMinEvictableIdleTimeMillis, including theminIdle, constraint.- Specified by:
getSoftMinEvictableIdleTimeMillisin interfaceBasicDataSourceMXBean- Returns:
- minimum amount of time a connection may sit idle in the pool before it is eligible for eviction, assuming there are minIdle idle connections in the pool
-
getTestOnBorrow
public boolean getTestOnBorrow()Returns thetestOnBorrowproperty.- Specified by:
getTestOnBorrowin interfaceBasicDataSourceMXBean- Returns:
- true if objects are validated before being borrowed from the pool
- See Also:
-
getTestOnCreate
public boolean getTestOnCreate()Returns thetestOnCreateproperty.- Specified by:
getTestOnCreatein interfaceBasicDataSourceMXBean- Returns:
- true if objects are validated immediately after they are created by the pool
- See Also:
-
getTestOnReturn
public boolean getTestOnReturn()Returns the value of thetestOnReturnproperty.- Returns:
- true if objects are validated before being returned to the pool
- See Also:
-
getTestWhileIdle
public boolean getTestWhileIdle()Returns the value of thetestWhileIdleproperty.- Specified by:
getTestWhileIdlein interfaceBasicDataSourceMXBean- Returns:
- true if objects examined by the idle object evictor are validated
- See Also:
-
getTimeBetweenEvictionRunsMillis
public long getTimeBetweenEvictionRunsMillis()Returns the value of thetimeBetweenEvictionRunsMillisproperty.- Specified by:
getTimeBetweenEvictionRunsMillisin interfaceBasicDataSourceMXBean- Returns:
- the time (in milliseconds) between evictor runs
- See Also:
-
getUrl
Returns the JDBC connectionurlproperty.- Specified by:
getUrlin interfaceBasicDataSourceMXBean- Returns:
- the
urlpassed to the JDBC driver to establish connections
-
getUsername
Returns the JDBC connectionuserNameproperty.- Specified by:
getUsernamein interfaceBasicDataSourceMXBean- Returns:
- the
userNamepassed to the JDBC driver to establish connections
-
getValidationQuery
Returns the validation query used to validate connections before returning them.- Specified by:
getValidationQueryin interfaceBasicDataSourceMXBean- Returns:
- the SQL validation query
- See Also:
-
getValidationQueryTimeout
public int getValidationQueryTimeout()Returns the validation query timeout.- Specified by:
getValidationQueryTimeoutin interfaceBasicDataSourceMXBean- Returns:
- the timeout in seconds before connection validation queries fail.
-
invalidateConnection
Manually invalidates a connection, effectively requesting the pool to try to close it, remove it from the pool and reclaim pool capacity.- Parameters:
connection- The Connection to invalidate.- Throws:
IllegalStateException- if invalidating the connection failed.- Since:
- 2.1
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()Returns the value of the accessToUnderlyingConnectionAllowed property.- Specified by:
isAccessToUnderlyingConnectionAllowedin interfaceBasicDataSourceMXBean- Returns:
- true if access to the underlying connection is allowed, false otherwise.
-
isClosed
public boolean isClosed()If true, this data source is closed and no more connections can be retrieved from this data source.- Specified by:
isClosedin interfaceBasicDataSourceMXBean- Returns:
- true, if the data source is closed; false otherwise
-
isEmpty
Delegates in a null-safe manner toString.isEmpty().- Parameters:
value- the string to test, may be null.- Returns:
- boolean false if value is null, otherwise
String.isEmpty().
-
isPoolPreparedStatements
public boolean isPoolPreparedStatements()Returns true if we are pooling statements.- Specified by:
isPoolPreparedStatementsin interfaceBasicDataSourceMXBean- Returns:
- true if prepared and callable statements are pooled
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
jmxRegister
private void jmxRegister() -
log
-
log
-
postDeregister
public void postDeregister()- Specified by:
postDeregisterin interfaceMBeanRegistration
-
postRegister
- Specified by:
postRegisterin interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception
-
preRegister
- Specified by:
preRegisterin interfaceMBeanRegistration
-
removeConnectionProperty
Removes a custom connection property.- Parameters:
name- Name of the custom connection property to remove- See Also:
-
setAbandonedLogWriter
Sets the print writer to be used by this configuration to log information on abandoned objects.- Parameters:
logWriter- The new log writer
-
setAbandonedUsageTracking
public void setAbandonedUsageTracking(boolean usageTracking) If the connection pool implementsUsageTracking, configure whether the connection pool should record a stack trace every time a method is called on a pooled connection and retain the most recent stack trace to aid debugging of abandoned connections.- Parameters:
usageTracking- A value oftruewill enable the recording of a stack trace on every use of a pooled connection
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean allow) 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.- Parameters:
allow- Access to the underlying connection is granted when true.
-
setAutoCommitOnReturn
public void setAutoCommitOnReturn(boolean autoCommitOnReturn) Sets the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned. It istrueby default.- Parameters:
autoCommitOnReturn- Whether or not connections being returned to the pool will be checked and configured with auto-commit.- Since:
- 2.6.0
-
setCacheState
public void setCacheState(boolean cacheState) Sets the state caching flag.- Parameters:
cacheState- The new value for the state caching flag
-
setConnectionFactoryClassName
Sets the ConnectionFactory class name.- Parameters:
connectionFactoryClassName- A class name.- Since:
- 2.7.0
-
setConnectionInitSqls
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.- Parameters:
connectionInitSqls- Collection of SQL statements to execute on connection creation
-
setConnectionProperties
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.
- Parameters:
connectionProperties- the connection properties used to create new connections
-
setDefaultAutoCommit
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.- Parameters:
defaultAutoCommit- default auto-commit value
-
setDefaultCatalog
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.- Parameters:
defaultCatalog- the default catalog
-
setDefaultQueryTimeout
-
setDefaultReadOnly
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.- Parameters:
defaultReadOnly- default read-only value
-
setDefaultSchema
Sets the default schema.
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.- Parameters:
defaultSchema- the default catalog- Since:
- 2.5.0
-
setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) 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.- Parameters:
defaultTransactionIsolation- the default transaction isolation state- See Also:
-
setDisconnectionSqlCodes
Sets the SQL_STATE codes considered to signal fatal conditions.Overrides the defaults in
Utils.DISCONNECTION_SQL_CODES(plus anything starting withUtils.DISCONNECTION_SQL_CODE_PREFIX). If this property is non-null andgetFastFailValidation()istrue, whenever connections created by this datasource generate exceptions with SQL_STATE codes in this list, they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at isValid or validation query).If
getFastFailValidation()isfalsesetting this property has no effect.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.- Parameters:
disconnectionSqlCodes- SQL_STATE codes considered to signal fatal conditions- Since:
- 2.1
-
setDriver
Sets the JDBC Driver instance to use for this 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.- Parameters:
driver- The JDBC Driver instance to use for this pool.
-
setDriverClassLoader
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.- Parameters:
driverClassLoader- the class loader with which to load the JDBC driver
-
setDriverClassName
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.- Parameters:
driverClassName- the class name of the JDBC driver
-
setEnableAutoCommitOnReturn
Deprecated.Sets the value of the flag that controls whether or not connections being returned to the pool will be checked and configured withConnection.setAutoCommit(true)if the auto commit setting isfalsewhen the connection is returned. It istrueby default.- Parameters:
autoCommitOnReturn- Whether or not connections being returned to the pool will be checked and configured with auto-commit.
-
setEvictionPolicyClassName
Sets the EvictionPolicy implementation to use with this connection pool.- Parameters:
evictionPolicyClassName- The fully qualified class name of the EvictionPolicy implementation
-
setFastFailValidation
public void setFastFailValidation(boolean fastFailValidation) - Parameters:
fastFailValidation- true means connections created by this factory will fast fail validation- Since:
- 2.1
- See Also:
-
setInitialSize
public void setInitialSize(int initialSize) 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.- Parameters:
initialSize- the number of connections created when the pool is initialized
-
setJmxName
Sets the JMX name that has been requested for this DataSource. If the requested name is not valid, an alternative may be chosen. This DataSource will attempt to register itself using this name. If another component registers this DataSource with JMX and this name is valid this name will be used in preference to any specified by the other component.- Parameters:
jmxName- The JMX name that has been requested for this DataSource
-
setLifo
public void setLifo(boolean lifo) Sets the LIFO property. True means the pool behaves as a LIFO queue; false means FIFO.- Parameters:
lifo- the new value for the LIFO property
-
setLogAbandoned
public void setLogAbandoned(boolean logAbandoned) - Parameters:
logAbandoned- new logAbandoned property value
-
setLogExpiredConnections
public void setLogExpiredConnections(boolean logExpiredConnections) WhengetMaxConnLifetimeMillis()is set to limit connection lifetime, this property determines whether or not log messages are generated when the pool closes connections due to maximum lifetime exceeded. Set this property to false to suppress log messages when connections expire.- Parameters:
logExpiredConnections- Whether or not log messages are generated when the pool closes connections due to maximum lifetime exceeded.
-
setLoginTimeout
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.- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Parameters:
loginTimeout- The new login timeout, or zero for no timeout- Throws:
UnsupportedOperationException- If the DataSource implementation does not support the login timeout feature.SQLException- if a database access error occurs
-
setLogWriter
Sets the log writer being used by this data source.
Calls
createDataSource(), so has the side effect of initializing the connection pool.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Parameters:
logWriter- The new log writer- Throws:
SQLException- if a database access error occurs
-
setMaxConnLifetimeMillis
public void setMaxConnLifetimeMillis(long maxConnLifetimeMillis) Sets the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.
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.- Parameters:
maxConnLifetimeMillis- The maximum permitted lifetime of a connection in milliseconds.
-
setMaxIdle
public void setMaxIdle(int maxIdle) Sets the maximum number of connections that can remain idle in the pool. Excess idle connections are destroyed on return to the pool.- Parameters:
maxIdle- the new value for maxIdle- See Also:
-
setMaxOpenPreparedStatements
public void setMaxOpenPreparedStatements(int maxOpenStatements) Sets the value of the
maxOpenPreparedStatementsproperty.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.- Parameters:
maxOpenStatements- the new maximum number of prepared statements
-
setMaxTotal
public void setMaxTotal(int maxTotal) Sets the maximum total number of idle and borrows connections that can be active at the same time. Use a negative value for no limit.- Parameters:
maxTotal- the new value for maxTotal- See Also:
-
setMaxWaitMillis
public void setMaxWaitMillis(long maxWaitMillis) Sets the MaxWaitMillis property. Use -1 to make the pool wait indefinitely.- Parameters:
maxWaitMillis- the new value for MaxWaitMillis- See Also:
-
setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Sets theminEvictableIdleTimeMillisproperty.- Parameters:
minEvictableIdleTimeMillis- the minimum amount of time an object may sit idle in the pool- See Also:
-
setMinIdle
public void setMinIdle(int minIdle) Sets the minimum number of idle connections in the pool. The pool attempts to ensure that minIdle connections are available when the idle object evictor runs. The value of this property has no effect unlesstimeBetweenEvictionRunsMillishas a positive value.- Parameters:
minIdle- the new value for minIdle- See Also:
-
setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) Sets the value of thenumTestsPerEvictionRunproperty.- Parameters:
numTestsPerEvictionRun- the newnumTestsPerEvictionRunvalue- See Also:
-
setPassword
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.- Parameters:
password- new value for the password
-
setPoolPreparedStatements
public void setPoolPreparedStatements(boolean poolingStatements) 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.- Parameters:
poolingStatements- pooling on or off
-
setRemoveAbandonedOnBorrow
public void setRemoveAbandonedOnBorrow(boolean removeAbandonedOnBorrow) - Parameters:
removeAbandonedOnBorrow- true means abandoned connections may be removed when connections are borrowed from the pool.- See Also:
-
setRemoveAbandonedOnMaintenance
public void setRemoveAbandonedOnMaintenance(boolean removeAbandonedOnMaintenance) - Parameters:
removeAbandonedOnMaintenance- true means abandoned connections may be removed on pool maintenance.- See Also:
-
setRemoveAbandonedTimeout
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) Sets the timeout in seconds before an abandoned connection can be removed.
Setting this property has no effect if
getRemoveAbandonedOnBorrow()andgetRemoveAbandonedOnMaintenance()are false.- Parameters:
removeAbandonedTimeout- new abandoned timeout in seconds- See Also:
-
setRollbackOnReturn
public void setRollbackOnReturn(boolean rollbackOnReturn) Sets the flag that controls if a connection will be rolled back when it is returned to the pool if auto commit is not enabled and the connection is not read only.- Parameters:
rollbackOnReturn- whether a connection will be rolled back when it is returned to the pool.
-
setSoftMinEvictableIdleTimeMillis
public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) Sets the minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool.- Parameters:
softMinEvictableIdleTimeMillis- minimum amount of time a connection may sit idle in the pool before it is eligible for eviction, assuming there are minIdle idle connections in the pool.- See Also:
-
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow) Sets thetestOnBorrowproperty. This property determines whether or not the pool will validate objects before they are borrowed from the pool.- Parameters:
testOnBorrow- new value for testOnBorrow property
-
setTestOnCreate
public void setTestOnCreate(boolean testOnCreate) Sets thetestOnCreateproperty. This property determines whether or not the pool will validate objects immediately after they are created by the pool- Parameters:
testOnCreate- new value for testOnCreate property
-
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn) Sets thetestOnReturnproperty. This property determines whether or not the pool will validate objects before they are returned to the pool.- Parameters:
testOnReturn- new value for testOnReturn property
-
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle) Sets thetestWhileIdleproperty. This property determines whether or not the idle object evictor will validate connections.- Parameters:
testWhileIdle- new value for testWhileIdle property
-
setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Sets thetimeBetweenEvictionRunsMillisproperty.- Parameters:
timeBetweenEvictionRunsMillis- the new time between evictor runs- See Also:
-
setUrl
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.- Parameters:
url- the new value for the JDBC connection url
-
setUsername
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.- Parameters:
userName- the new value for the JDBC connection user name
-
setValidationQuery
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.- Parameters:
validationQuery- the new value for the validation query
-
setValidationQueryTimeout
public void setValidationQueryTimeout(int validationQueryTimeoutSeconds) 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.- Parameters:
validationQueryTimeoutSeconds- new validation query timeout value in seconds
-
startPoolMaintenance
protected void startPoolMaintenance()Starts the connection pool maintenance task, if configured. -
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
updateJmxName
-
getAutoCommitOnReturn().