public class CommonsDatabaseConnectionMonitor extends Object implements DatabaseConnectionMonitor
Constructor and Description |
---|
CommonsDatabaseConnectionMonitor(String name,
org.apache.commons.dbcp.BasicDataSource ds) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionProperty(String name,
String value)
Add a custom connection property to the set that will be passed to our
JDBC driver.
|
boolean |
getDefaultAutoCommit()
Returns the default auto-commit property.
|
String |
getDefaultCatalog()
Returns the default catalog.
|
boolean |
getDefaultReadOnly()
Returns the default readOnly property.
|
int |
getDefaultTransactionIsolation()
Returns the default transaction isolation state of returned connections.
|
String |
getDriverClassName()
Returns the jdbc driver class name.
|
int |
getInitialSize()
Returns the initial size of the connection pool.
|
boolean |
getLogAbandoned()
Flag to log stack traces for application code which abandoned
a Statement or Connection.
|
int |
getLoginTimeout()
BasicDataSource does NOT support this method.
|
int |
getMaxActive()
Returns the maximum number of active connections that can be
allocated at the same time.
|
int |
getMaxIdle()
Returns the maximum number of connections that can remain idle in the
pool.
|
int |
getMaxOpenPreparedStatements()
Gets the value of the
#maxOpenPreparedStatements property. |
long |
getMaxWait()
Returns the maximum number of milliseconds that the pool will wait
for a connection to be returned before throwing an exception.
|
long |
getMinEvictableIdleTimeMillis()
Returns the
#minEvictableIdleTimeMillis property. |
int |
getMinIdle()
Returns the minimum number of idle connections in the pool
|
int |
getNumActive()
[Read Only] The current number of active connections that have been
allocated from this data source.
|
int |
getNumIdle()
[Read Only] The current number of idle connections that are waiting
to be allocated from this data source.
|
int |
getNumTestsPerEvictionRun()
Returns the value of the
#numTestsPerEvictionRun property. |
String |
getPassword() |
boolean |
getRemoveAbandoned()
Flag to remove abandoned connections if they exceed the
removeAbandonedTimout.
|
int |
getRemoveAbandonedTimeout()
Timeout in seconds before an abandoned connection can be removed.
|
boolean |
getTestOnBorrow()
Returns the
#testOnBorrow property. |
boolean |
getTestOnReturn()
Returns the value of the
#testOnReturn property. |
boolean |
getTestWhileIdle()
Returns the value of the
#testWhileIdle property. |
long |
getTimeBetweenEvictionRunsMillis()
Returns the value of the
#timeBetweenEvictionRunsMillis
property. |
String |
getUrl()
Returns the JDBC connection
#url property. |
String |
getUsername()
Returns the JDBC connection
#username property. |
String |
getValidationQuery()
Returns the validation query used to validate connections before
returning them.
|
int |
getValidationQueryTimeout()
Returns the validation query timeout.
|
void |
install() |
boolean |
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.
|
boolean |
isClosed()
If true, this data source is closed and no more connections can be retrieved from this datasource.
|
boolean |
isPoolPreparedStatements()
Returns true if we are pooling statements.
|
void |
removeConnectionProperty(String name)
Remove a custom connection property.
|
void |
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.
|
void |
setConnectionProperties(String connectionProperties)
Sets the connection properties passed to driver.connect(...).
|
void |
setDefaultAutoCommit(boolean defaultAutoCommit)
Sets default auto-commit state of connections returned by this
datasource.
|
void |
setDefaultCatalog(String defaultCatalog)
Sets the default catalog.
|
void |
setDefaultReadOnly(boolean defaultReadOnly)
Sets defaultReadonly property.
|
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation)
Sets the default transaction isolation state for returned
connections.
|
void |
setInitialSize(int initialSize) |
void |
setLogAbandoned(boolean logAbandoned) |
void |
setLoginTimeout(int loginTimeout)
BasicDataSource does NOT support this method.
|
void |
setLogWriter(PrintWriter logWriter) |
void |
setMaxActive(int maxActive)
Sets the maximum number of active connections that can be
allocated at the same time.
|
void |
setMaxIdle(int maxIdle)
Sets the maximum number of connections that can remain idle in the
pool.
|
void |
setMaxOpenPreparedStatements(int maxOpenStatements)
Sets the value of the
#maxOpenPreparedStatements
property. |
void |
setMaxWait(long maxWait)
Sets the maxWait property.
|
void |
setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the
#minEvictableIdleTimeMillis property. |
void |
setMinIdle(int minIdle)
Sets the minimum number of idle connections in the pool.
|
void |
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the value of the
#numTestsPerEvictionRun property. |
void |
setPoolPreparedStatements(boolean poolingStatements)
Sets whether to pool statements or not.
|
void |
setRemoveAbandoned(boolean removeAbandoned) |
void |
setRemoveAbandonedTimeout(int removeAbandonedTimeout) |
void |
setTestOnBorrow(boolean testOnBorrow)
Sets the
#testOnBorrow property. |
void |
setTestOnReturn(boolean testOnReturn)
Sets the
testOnReturn property. |
void |
setTestWhileIdle(boolean testWhileIdle)
Sets the
testWhileIdle property. |
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the
#timeBetweenEvictionRunsMillis property. |
void |
setValidationQuery(String validationQuery)
Sets the
#validationQuery . |
void |
setValidationQueryTimeout(int timeout)
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.
|
void |
uninstall() |
public CommonsDatabaseConnectionMonitor(String name, org.apache.commons.dbcp.BasicDataSource ds)
public boolean getDefaultAutoCommit()
DatabaseConnectionMonitor
getDefaultAutoCommit
in interface DatabaseConnectionMonitor
public void setDefaultAutoCommit(boolean defaultAutoCommit)
DatabaseConnectionMonitor
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.
setDefaultAutoCommit
in interface DatabaseConnectionMonitor
defaultAutoCommit
- default auto-commit valuepublic boolean getDefaultReadOnly()
DatabaseConnectionMonitor
getDefaultReadOnly
in interface DatabaseConnectionMonitor
public void setDefaultReadOnly(boolean defaultReadOnly)
DatabaseConnectionMonitor
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.
setDefaultReadOnly
in interface DatabaseConnectionMonitor
defaultReadOnly
- default read-only valuepublic int getDefaultTransactionIsolation()
DatabaseConnectionMonitor
getDefaultTransactionIsolation
in interface DatabaseConnectionMonitor
Connection.getTransactionIsolation()
public void setDefaultTransactionIsolation(int defaultTransactionIsolation)
DatabaseConnectionMonitor
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.
setDefaultTransactionIsolation
in interface DatabaseConnectionMonitor
defaultTransactionIsolation
- the default transaction isolation
stateConnection.getTransactionIsolation()
public String getDefaultCatalog()
DatabaseConnectionMonitor
getDefaultCatalog
in interface DatabaseConnectionMonitor
public void setDefaultCatalog(String defaultCatalog)
DatabaseConnectionMonitor
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.
setDefaultCatalog
in interface DatabaseConnectionMonitor
defaultCatalog
- the default catalogpublic String getDriverClassName()
DatabaseConnectionMonitor
getDriverClassName
in interface DatabaseConnectionMonitor
public int getMaxActive()
DatabaseConnectionMonitor
Returns the maximum number of active connections that can be allocated at the same time.
A negative number means that there is no limit.
getMaxActive
in interface DatabaseConnectionMonitor
public void setMaxActive(int maxActive)
DatabaseConnectionMonitor
setMaxActive
in interface DatabaseConnectionMonitor
maxActive
- the new value for maxActiveDatabaseConnectionMonitor.getMaxActive()
public int getMaxIdle()
DatabaseConnectionMonitor
Returns the maximum number of connections that can remain idle in the pool.
A negative value indicates that there is no limit
getMaxIdle
in interface DatabaseConnectionMonitor
public void setMaxIdle(int maxIdle)
DatabaseConnectionMonitor
setMaxIdle
in interface DatabaseConnectionMonitor
maxIdle
- the new value for maxIdleDatabaseConnectionMonitor.getMaxIdle()
public int getMinIdle()
DatabaseConnectionMonitor
getMinIdle
in interface DatabaseConnectionMonitor
GenericObjectPool.getMinIdle()
public void setMinIdle(int minIdle)
DatabaseConnectionMonitor
setMinIdle
in interface DatabaseConnectionMonitor
minIdle
- the new value for minIdleGenericObjectPool.setMinIdle(int)
public int getInitialSize()
DatabaseConnectionMonitor
getInitialSize
in interface DatabaseConnectionMonitor
public void setInitialSize(int initialSize)
public long getMaxWait()
DatabaseConnectionMonitor
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.
getMaxWait
in interface DatabaseConnectionMonitor
public void setMaxWait(long maxWait)
DatabaseConnectionMonitor
Sets the maxWait property.
Use -1 to make the pool wait indefinitely.
setMaxWait
in interface DatabaseConnectionMonitor
maxWait
- the new value for maxWaitDatabaseConnectionMonitor.getMaxWait()
public boolean isPoolPreparedStatements()
DatabaseConnectionMonitor
isPoolPreparedStatements
in interface DatabaseConnectionMonitor
public void setPoolPreparedStatements(boolean poolingStatements)
DatabaseConnectionMonitor
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.
setPoolPreparedStatements
in interface DatabaseConnectionMonitor
poolingStatements
- pooling on or offpublic int getMaxOpenPreparedStatements()
DatabaseConnectionMonitor
#maxOpenPreparedStatements
property.getMaxOpenPreparedStatements
in interface DatabaseConnectionMonitor
#maxOpenPreparedStatements
public void setMaxOpenPreparedStatements(int maxOpenStatements)
DatabaseConnectionMonitor
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.
setMaxOpenPreparedStatements
in interface DatabaseConnectionMonitor
maxOpenStatements
- the new maximum number of prepared statements#maxOpenPreparedStatements
public boolean getTestOnBorrow()
DatabaseConnectionMonitor
#testOnBorrow
property.getTestOnBorrow
in interface DatabaseConnectionMonitor
#testOnBorrow
public void setTestOnBorrow(boolean testOnBorrow)
DatabaseConnectionMonitor
#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.setTestOnBorrow
in interface DatabaseConnectionMonitor
testOnBorrow
- new value for testOnBorrow propertypublic boolean getTestOnReturn()
DatabaseConnectionMonitor
#testOnReturn
property.getTestOnReturn
in interface DatabaseConnectionMonitor
#testOnReturn
public void setTestOnReturn(boolean testOnReturn)
DatabaseConnectionMonitor
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.setTestOnReturn
in interface DatabaseConnectionMonitor
testOnReturn
- new value for testOnReturn propertypublic long getTimeBetweenEvictionRunsMillis()
DatabaseConnectionMonitor
#timeBetweenEvictionRunsMillis
property.getTimeBetweenEvictionRunsMillis
in interface DatabaseConnectionMonitor
#timeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
DatabaseConnectionMonitor
#timeBetweenEvictionRunsMillis
property.setTimeBetweenEvictionRunsMillis
in interface DatabaseConnectionMonitor
timeBetweenEvictionRunsMillis
- the new time between evictor runs#timeBetweenEvictionRunsMillis
public int getNumTestsPerEvictionRun()
DatabaseConnectionMonitor
#numTestsPerEvictionRun
property.getNumTestsPerEvictionRun
in interface DatabaseConnectionMonitor
#numTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
DatabaseConnectionMonitor
#numTestsPerEvictionRun
property.setNumTestsPerEvictionRun
in interface DatabaseConnectionMonitor
numTestsPerEvictionRun
- the new #numTestsPerEvictionRun
value#numTestsPerEvictionRun
public long getMinEvictableIdleTimeMillis()
DatabaseConnectionMonitor
#minEvictableIdleTimeMillis
property.getMinEvictableIdleTimeMillis
in interface DatabaseConnectionMonitor
#minEvictableIdleTimeMillis
property#minEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
DatabaseConnectionMonitor
#minEvictableIdleTimeMillis
property.setMinEvictableIdleTimeMillis
in interface DatabaseConnectionMonitor
minEvictableIdleTimeMillis
- the minimum amount of time an object
may sit idle in the pool#minEvictableIdleTimeMillis
public boolean getTestWhileIdle()
DatabaseConnectionMonitor
#testWhileIdle
property.getTestWhileIdle
in interface DatabaseConnectionMonitor
#testWhileIdle
public void setTestWhileIdle(boolean testWhileIdle)
DatabaseConnectionMonitor
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.setTestWhileIdle
in interface DatabaseConnectionMonitor
testWhileIdle
- new value for testWhileIdle propertypublic int getNumActive()
DatabaseConnectionMonitor
getNumActive
in interface DatabaseConnectionMonitor
public int getNumIdle()
DatabaseConnectionMonitor
getNumIdle
in interface DatabaseConnectionMonitor
public String getPassword()
public String getUrl()
DatabaseConnectionMonitor
#url
property.getUrl
in interface DatabaseConnectionMonitor
#url
passed to the JDBC driver to establish
connectionspublic String getUsername()
DatabaseConnectionMonitor
#username
property.getUsername
in interface DatabaseConnectionMonitor
#username
passed to the JDBC driver to establish
connectionspublic String getValidationQuery()
DatabaseConnectionMonitor
getValidationQuery
in interface DatabaseConnectionMonitor
#validationQuery
public void setValidationQuery(String validationQuery)
DatabaseConnectionMonitor
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.
setValidationQuery
in interface DatabaseConnectionMonitor
validationQuery
- the new value for the validation querypublic int getValidationQueryTimeout()
DatabaseConnectionMonitor
getValidationQueryTimeout
in interface DatabaseConnectionMonitor
public void setValidationQueryTimeout(int timeout)
DatabaseConnectionMonitor
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.
setValidationQueryTimeout
in interface DatabaseConnectionMonitor
timeout
- new validation query timeout value in secondspublic boolean isAccessToUnderlyingConnectionAllowed()
DatabaseConnectionMonitor
isAccessToUnderlyingConnectionAllowed
in interface DatabaseConnectionMonitor
public int getLoginTimeout() throws SQLException
DatabaseConnectionMonitor
Returns the login timeout (in seconds) for connecting to the database.
Calls #createDataSource()
, so has the side effect
of initializing the connection pool.
getLoginTimeout
in interface DatabaseConnectionMonitor
SQLException
- if a database access error occurspublic void setLoginTimeout(int loginTimeout) throws SQLException
DatabaseConnectionMonitor
Set the login timeout (in seconds) for connecting to the database.
Calls #createDataSource()
, so has the side effect
of initializing the connection pool.
setLoginTimeout
in interface DatabaseConnectionMonitor
loginTimeout
- The new login timeout, or zero for no timeoutSQLException
- if a database access error occurspublic void setLogWriter(PrintWriter logWriter) throws SQLException
SQLException
public boolean getRemoveAbandoned()
DatabaseConnectionMonitor
Abandonded connections are identified and removed when
#getConnection()
is invoked and the following conditions hold
getRemoveAbandoned
in interface DatabaseConnectionMonitor
public void setRemoveAbandoned(boolean removeAbandoned)
setRemoveAbandoned
in interface DatabaseConnectionMonitor
removeAbandoned
- new removeAbandoned property valueDatabaseConnectionMonitor.getRemoveAbandoned()
public int getRemoveAbandonedTimeout()
DatabaseConnectionMonitor
getRemoveAbandonedTimeout
in interface DatabaseConnectionMonitor
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
setRemoveAbandonedTimeout
in interface DatabaseConnectionMonitor
removeAbandonedTimeout
- new removeAbandonedTimeout valuepublic boolean getLogAbandoned()
DatabaseConnectionMonitor
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.
getLogAbandoned
in interface DatabaseConnectionMonitor
public void setLogAbandoned(boolean logAbandoned)
setLogAbandoned
in interface DatabaseConnectionMonitor
logAbandoned
- new logAbandoned property valuepublic void removeConnectionProperty(String name)
DatabaseConnectionMonitor
removeConnectionProperty
in interface DatabaseConnectionMonitor
name
- Name of the custom connection property to removeDatabaseConnectionMonitor.addConnectionProperty(String, String)
public boolean isClosed()
DatabaseConnectionMonitor
isClosed
in interface DatabaseConnectionMonitor
public void setAccessToUnderlyingConnectionAllowed(boolean allow)
DatabaseConnectionMonitor
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.
setAccessToUnderlyingConnectionAllowed
in interface DatabaseConnectionMonitor
allow
- Access to the underlying connection is granted when true.public void addConnectionProperty(String name, String value)
DatabaseConnectionMonitor
addConnectionProperty
in interface DatabaseConnectionMonitor
name
- Name of the custom connection propertyvalue
- Value of the custom connection propertypublic void setConnectionProperties(String connectionProperties)
DatabaseConnectionMonitor
setConnectionProperties
in interface DatabaseConnectionMonitor
connectionProperties
- the connection properties used to
create new connectionsCopyright © 2013 Nuxeo SA. All Rights Reserved.