|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.dbcp.BasicDataSource
public class BasicDataSource
Basic implementation of javax.sql.DataSource
that is
configured via JavaBeans properties. This is not the only way to
combine the commons-dbcp and commons-pool packages,
but provides a "one stop shopping" solution for basic requirements.
Constructor Summary | |
---|---|
BasicDataSource()
|
Method Summary | |
---|---|
void |
addConnectionProperty(String name,
String value)
Add a custom connection property to the set that will be passed to our JDBC driver. |
void |
close()
Close and release all connections that are currently stored in the connection pool associated with our data source. |
Connection |
getConnection()
Create (if necessary) and return a connection to the database. |
Connection |
getConnection(String username,
String password)
BasicDataSource does NOT support this method. |
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. |
int |
getLoginTimeout()
Returns the login timeout (in seconds) for connecting to the database. |
PrintWriter |
getLogWriter()
Returns the log writer being used by this data source. |
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()
Returns the password passed to the JDBC driver to establish connections. |
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. |
boolean |
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property. |
boolean |
isPoolPreparedStatements()
Returns true if we are pooling statements. |
boolean |
isWrapperFor(Class iface)
|
void |
removeConnectionProperty(String name)
Remove a custom connection property. |
void |
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property. |
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 |
setDriverClassName(String driverClassName)
Sets the jdbc driver class name. |
void |
setInitialSize(int initialSize)
Sets the initial size of the connection pool. |
void |
setLoginTimeout(int loginTimeout)
Set the login timeout (in seconds) for connecting to the database. |
void |
setLogWriter(PrintWriter logWriter)
Sets the log writer being used by this data source. |
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 remail 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 |
setPassword(String password)
Sets the password . |
void |
setPoolPreparedStatements(boolean poolingStatements)
Sets whether to pool statements or not. |
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 |
setUrl(String url)
Sets the url . |
void |
setUsername(String username)
Sets the username . |
void |
setValidationQuery(String validationQuery)
Sets the validationQuery . |
Object |
unwrap(Class iface)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BasicDataSource()
Method Detail |
---|
public void addConnectionProperty(String name, String value)
name
- Name of the custom connection propertyvalue
- Value of the custom connection propertypublic void close() throws SQLException
SQLException
- if a database error occurspublic Connection getConnection() throws SQLException
getConnection
in interface DataSource
SQLException
- if a database access error occurspublic Connection getConnection(String username, String password) throws SQLException
getConnection
in interface DataSource
username
- Database user on whose behalf the Connection
is being madepassword
- The database user's password
UnsupportedOperationException
SQLException
- if a database access error occurspublic boolean getDefaultAutoCommit()
public String getDefaultCatalog()
public boolean getDefaultReadOnly()
public int getDefaultTransactionIsolation()
Connection.getTransactionIsolation()
public String getDriverClassName()
public int getInitialSize()
public int getLoginTimeout() throws SQLException
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 CommonDataSource
SQLException
- if a database access error occurs
UnsupportedOperationException
- If the DataSource implementation
does not support the login timeout feature.public PrintWriter getLogWriter() throws SQLException
Returns the log writer being used by this data source.
Calls createDataSource()
, so has the side effect
of initializing the connection pool.
getLogWriter
in interface CommonDataSource
SQLException
- if a database access error occurspublic int getMaxActive()
Returns the maximum number of active connections that can be allocated at the same time.
A non-positive number means that there is no limit.
public int getMaxIdle()
Returns the maximum number of connections that can remain idle in the pool.
A negative value indicates that there is no limit
public int getMaxOpenPreparedStatements()
maxOpenPreparedStatements
property.
maxOpenPreparedStatements
public long getMaxWait()
Returns the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.
Returns -1 if the pool is set to wait indefinitely.
public long getMinEvictableIdleTimeMillis()
minEvictableIdleTimeMillis
property.
minEvictableIdleTimeMillis
propertyminEvictableIdleTimeMillis
public int getMinIdle()
GenericObjectPool.getMinIdle()
public int getNumActive()
public int getNumIdle()
public int getNumTestsPerEvictionRun()
numTestsPerEvictionRun
property.
numTestsPerEvictionRun
public String getPassword()
public boolean getTestOnBorrow()
testOnBorrow
property.
testOnBorrow
public boolean getTestOnReturn()
testOnReturn
property.
testOnReturn
public boolean getTestWhileIdle()
testWhileIdle
property.
testWhileIdle
public long getTimeBetweenEvictionRunsMillis()
timeBetweenEvictionRunsMillis
property.
timeBetweenEvictionRunsMillis
public String getUrl()
url
property.
url
passed to the JDBC driver to establish
connectionspublic String getUsername()
username
property.
username
passed to the JDBC driver to establish
connectionspublic String getValidationQuery()
validationQuery
public boolean isAccessToUnderlyingConnectionAllowed()
public boolean isPoolPreparedStatements()
public boolean isWrapperFor(Class iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
public void removeConnectionProperty(String name)
name
- Name of the custom connection property to removeaddConnectionProperty(String, String)
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.
allow
- Access to the underlying connection is granted when true.public void setDefaultAutoCommit(boolean defaultAutoCommit)
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.
defaultAutoCommit
- default auto-commit valuepublic void setDefaultCatalog(String defaultCatalog)
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.
defaultCatalog
- the default catalogpublic void setDefaultReadOnly(boolean defaultReadOnly)
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.
defaultReadOnly
- default read-only valuepublic 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.
defaultTransactionIsolation
- the default transaction isolation
stateConnection.getTransactionIsolation()
public void setDriverClassName(String driverClassName)
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.
driverClassName
- the class name of the jdbc driverpublic 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.
initialSize
- the number of connections created when the pool
is initializedpublic void setLoginTimeout(int loginTimeout) throws SQLException
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 CommonDataSource
loginTimeout
- The new login timeout, or zero for no timeout
SQLException
- if a database access error occurspublic void setLogWriter(PrintWriter logWriter) throws SQLException
Sets the log writer being used by this data source.
Calls createDataSource()
, so has the side effect
of initializing the connection pool.
setLogWriter
in interface CommonDataSource
logWriter
- The new log writer
SQLException
- if a database access error occurspublic void setMaxActive(int maxActive)
maxActive
- the new value for maxActivegetMaxActive()
public void setMaxIdle(int maxIdle)
maxIdle
- the new value for maxIdlegetMaxIdle()
public void setMaxOpenPreparedStatements(int maxOpenStatements)
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.
maxOpenStatements
- the new maximum number of prepared statementsmaxOpenPreparedStatements
public void setMaxWait(long maxWait)
maxWait
- the new value for maxWaitgetMaxWait()
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
minEvictableIdleTimeMillis
property.
minEvictableIdleTimeMillis
- the minimum amount of time an object
may sit idle in the poolminEvictableIdleTimeMillis
public void setMinIdle(int minIdle)
minIdle
- the new value for minIdleGenericObjectPool.setMinIdle(int)
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
numTestsPerEvictionRun
property.
numTestsPerEvictionRun
- the new numTestsPerEvictionRun
valuenumTestsPerEvictionRun
public void setPassword(String password)
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.
password
- new value for the passwordpublic 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.
poolingStatements
- pooling on or offpublic void setTestOnBorrow(boolean testOnBorrow)
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.
testOnBorrow
- new value for testOnBorrow propertypublic void setTestOnReturn(boolean testOnReturn)
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.
testOnReturn
- new value for testOnReturn propertypublic void setTestWhileIdle(boolean testWhileIdle)
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.
testWhileIdle
- new value for testWhileIdle propertypublic void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
timeBetweenEvictionRunsMillis
property.
timeBetweenEvictionRunsMillis
- the new time between evictor runstimeBetweenEvictionRunsMillis
public void setUrl(String url)
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.
url
- the new value for the JDBC connection urlpublic void setUsername(String username)
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.
username
- the new value for the JDBC connection usernamepublic void setValidationQuery(String validationQuery)
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.
validationQuery
- the new value for the validation querypublic Object unwrap(Class iface) throws SQLException
unwrap
in interface Wrapper
SQLException
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |