org.apache.commons.dbcp
Class BasicDataSource

java.lang.Object
  extended byorg.apache.commons.dbcp.BasicDataSource
All Implemented Interfaces:
DataSource

public class BasicDataSource
extends Object
implements DataSource

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.

Version:
$Revision: 892307 $ $Date: 2013-12-31 23:27:28 +0000 (Tue, 31 Dec 2013) $
Author:
Glenn L. Nielsen, Craig R. McClanahan, Dirk Verbeeck

Field Summary
protected  GenericObjectPool connectionPool
          The object pool that internally manages our connections.
protected  Properties connectionProperties
          The connection properties that will be sent to our JDBC driver when establishing new connections.
protected  DataSource dataSource
          The data source we will use to manage connections.
protected  boolean defaultAutoCommit
          The default auto-commit state of connections created by this pool.
protected  String defaultCatalog
          The default "catalog" of connections created by this pool.
protected  Boolean defaultReadOnly
          The default read-only state of connections created by this pool.
protected  int defaultTransactionIsolation
          The default TransactionIsolation state of connections created by this pool.
protected  String driverClassName
          The fully qualified Java class name of the JDBC driver to be used.
protected  int initialSize
          The initial number of connections that are created when the pool is started.
protected  PrintWriter logWriter
          The PrintWriter to which log messages should be directed.
protected  int maxActive
          The maximum number of active connections that can be allocated from this pool at the same time, or non-positive for no limit.
protected  int maxIdle
          The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
protected  int maxOpenPreparedStatements
          The maximum number of open statements that can be allocated from the statement pool at the same time, or non-positive for no limit.
protected  long maxWait
          The 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 -1 to wait indefinitely.
protected  long minEvictableIdleTimeMillis
          The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
protected  int minIdle
          The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.
protected  int numTestsPerEvictionRun
          The number of objects to examine during each run of the idle object evictor thread (if any).
protected  String password
          The connection password to be passed to our JDBC driver to establish a connection.
protected  boolean poolPreparedStatements
          Prepared statement pooling for this pool.
protected  boolean testOnBorrow
          The indication of whether objects will be validated before being borrowed from the pool.
protected  boolean testOnReturn
          The indication of whether objects will be validated before being returned to the pool.
protected  boolean testWhileIdle
          The indication of whether objects will be validated by the idle object evictor (if any).
protected  long timeBetweenEvictionRunsMillis
          The number of milliseconds to sleep between runs of the idle object evictor thread.
protected  String url
          The connection URL to be passed to our JDBC driver to establish a connection.
protected  String username
          The connection username to be passed to our JDBC driver to establish a connection.
protected  String validationQuery
          The SQL query that will be used to validate connections from this pool before returning them to the caller.
 
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.
protected  DataSource createDataSource()
          Create (if necessary) and return the internal data source we are using to manage our connections.
 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.
 boolean getLogAbandoned()
          Deprecated.  
 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 getRemoveAbandoned()
          Deprecated.  
 int getRemoveAbandonedTimeout()
          Deprecated.  
 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.
 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 setLogAbandoned(boolean logAbandoned)
          Deprecated.  
 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 setRemoveAbandoned(boolean removeAbandoned)
          Deprecated.  
 void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
          Deprecated.  
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultAutoCommit

protected boolean defaultAutoCommit
The default auto-commit state of connections created by this pool.


defaultReadOnly

protected Boolean defaultReadOnly
The default read-only state of connections created by this pool.


defaultTransactionIsolation

protected int defaultTransactionIsolation
The default TransactionIsolation state of connections created by this pool.


defaultCatalog

protected String defaultCatalog
The default "catalog" of connections created by this pool.


driverClassName

protected String driverClassName
The fully qualified Java class name of the JDBC driver to be used.


maxActive

protected int maxActive
The maximum number of active connections that can be allocated from this pool at the same time, or non-positive for no limit.


maxIdle

protected int maxIdle
The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.


minIdle

protected int minIdle
The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.


initialSize

protected int initialSize
The initial number of connections that are created when the pool is started.

Since:
1.2

maxWait

protected long maxWait
The 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 -1 to wait indefinitely.


poolPreparedStatements

protected boolean poolPreparedStatements
Prepared statement pooling for this pool.


maxOpenPreparedStatements

protected int maxOpenPreparedStatements
The maximum number of open statements that can be allocated from the statement pool at the same time, or non-positive 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.


testOnBorrow

protected boolean testOnBorrow
The 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

protected boolean testOnReturn
The indication of whether objects will be validated before being returned to the pool.


timeBetweenEvictionRunsMillis

protected long timeBetweenEvictionRunsMillis
The 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

protected int numTestsPerEvictionRun
The number of objects to examine during each run of the idle object evictor thread (if any).


minEvictableIdleTimeMillis

protected long minEvictableIdleTimeMillis
The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).


testWhileIdle

protected boolean testWhileIdle
The 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

protected String password
The connection password to be passed to our JDBC driver to establish a connection.


url

protected String url
The connection URL to be passed to our JDBC driver to establish a connection.


username

protected String username
The connection username to be passed to our JDBC driver to establish a connection.


validationQuery

protected String 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.


connectionPool

protected GenericObjectPool connectionPool
The object pool that internally manages our connections.


connectionProperties

protected Properties 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

protected DataSource dataSource
The data source we will use to manage connections. This object should be acquired ONLY by calls to the createDataSource() method.


logWriter

protected PrintWriter logWriter
The PrintWriter to which log messages should be directed.

Constructor Detail

BasicDataSource

public BasicDataSource()
Method Detail

getDefaultAutoCommit

public boolean getDefaultAutoCommit()
Returns the default auto-commit property.

Returns:
true if default auto-commit is enabled

setDefaultAutoCommit

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.

Parameters:
defaultAutoCommit - default auto-commit value

getDefaultReadOnly

public boolean getDefaultReadOnly()
Returns the default readOnly property.

Returns:
true if connections are readOnly by default

setDefaultReadOnly

public 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.

Parameters:
defaultReadOnly - default read-only value

getDefaultTransactionIsolation

public int getDefaultTransactionIsolation()
Returns the default transaction isolation state of returned connections.

Returns:
the default value for transaction isolation state
See Also:
Connection.getTransactionIsolation()

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:
Connection.getTransactionIsolation()

getDefaultCatalog

public String getDefaultCatalog()
Returns the default catalog.

Returns:
the default catalog

setDefaultCatalog

public 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.

Parameters:
defaultCatalog - the default catalog

getDriverClassName

public String getDriverClassName()
Returns the jdbc driver class name.

Returns:
the jdbc driver class name

setDriverClassName

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.

Parameters:
driverClassName - the class name of the jdbc driver

getMaxActive

public 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.

Returns:
the maximum number of active connections

setMaxActive

public void setMaxActive(int maxActive)
Sets the maximum number of active connections that can be allocated at the same time.

Parameters:
maxActive - the new value for maxActive
See Also:
getMaxActive()

getMaxIdle

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

Returns:
the maximum number of idle connections

setMaxIdle

public void setMaxIdle(int maxIdle)
Sets the maximum number of connections that can remail idle in the pool.

Parameters:
maxIdle - the new value for maxIdle
See Also:
getMaxIdle()

getMinIdle

public int getMinIdle()
Returns the minimum number of idle connections in the pool

Returns:
the minimum number of idle connections
See Also:
GenericObjectPool.getMinIdle()

setMinIdle

public void setMinIdle(int minIdle)
Sets the minimum number of idle connections in the pool.

Parameters:
minIdle - the new value for minIdle
See Also:
GenericObjectPool.setMinIdle(int)

getInitialSize

public int getInitialSize()
Returns the initial size of the connection pool.

Returns:
the number of connections created when the pool is initialized

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

getMaxWait

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.

Returns:
the maxWait property value

setMaxWait

public void setMaxWait(long maxWait)
Sets the maxWait property.

Parameters:
maxWait - the new value for maxWait
See Also:
getMaxWait()

isPoolPreparedStatements

public boolean isPoolPreparedStatements()
Returns true if we are pooling statements.

Returns:
true if prepared statements are pooled

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

getMaxOpenPreparedStatements

public int getMaxOpenPreparedStatements()
Gets the value of the maxOpenPreparedStatements property.

Returns:
the maximum number of open statements
See Also:
maxOpenPreparedStatements

setMaxOpenPreparedStatements

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.

Parameters:
maxOpenStatements - the new maximum number of prepared statements
See Also:
maxOpenPreparedStatements

getTestOnBorrow

public boolean getTestOnBorrow()
Returns the testOnBorrow property.

Returns:
true if objects are validated before being borrowed from the pool
See Also:
testOnBorrow

setTestOnBorrow

public void setTestOnBorrow(boolean testOnBorrow)
Sets the testOnBorrow property. This property determines whether or not the pool will validate objects before they are borrowed from the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testOnBorrow - new value for testOnBorrow property

getTestOnReturn

public boolean getTestOnReturn()
Returns the value of the testOnReturn property.

Returns:
true if objects are validated before being returned to the pool
See Also:
testOnReturn

setTestOnReturn

public void setTestOnReturn(boolean testOnReturn)
Sets the testOnReturn property. This property determines whether or not the pool will validate objects before they are returned to the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testOnReturn - new value for testOnReturn property

getTimeBetweenEvictionRunsMillis

public long getTimeBetweenEvictionRunsMillis()
Returns the value of the timeBetweenEvictionRunsMillis property.

Returns:
the time (in miliseconds) between evictor runs
See Also:
timeBetweenEvictionRunsMillis

setTimeBetweenEvictionRunsMillis

public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the timeBetweenEvictionRunsMillis property.

Parameters:
timeBetweenEvictionRunsMillis - the new time between evictor runs
See Also:
timeBetweenEvictionRunsMillis

getNumTestsPerEvictionRun

public int getNumTestsPerEvictionRun()
Returns the value of the numTestsPerEvictionRun property.

Returns:
the number of objects to examine during idle object evictor runs
See Also:
numTestsPerEvictionRun

setNumTestsPerEvictionRun

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the value of the numTestsPerEvictionRun property.

Parameters:
numTestsPerEvictionRun - the new numTestsPerEvictionRun value
See Also:
numTestsPerEvictionRun

getMinEvictableIdleTimeMillis

public long getMinEvictableIdleTimeMillis()
Returns the minEvictableIdleTimeMillis property.

Returns:
the value of the minEvictableIdleTimeMillis property
See Also:
minEvictableIdleTimeMillis

setMinEvictableIdleTimeMillis

public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the minEvictableIdleTimeMillis property.

Parameters:
minEvictableIdleTimeMillis - the minimum amount of time an object may sit idle in the pool
See Also:
minEvictableIdleTimeMillis

getTestWhileIdle

public boolean getTestWhileIdle()
Returns the value of the testWhileIdle property.

Returns:
true if objects examined by the idle object evictor are validated
See Also:
testWhileIdle

setTestWhileIdle

public void setTestWhileIdle(boolean testWhileIdle)
Sets the testWhileIdle property. This property determines whether or not the idle object evictor will validate connections. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testWhileIdle - new value for testWhileIdle property

getNumActive

public int getNumActive()
[Read Only] The current number of active connections that have been allocated from this data source.

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.

Returns:
the current number of idle connections

getPassword

public String getPassword()
Returns the password passed to the JDBC driver to establish connections.

Returns:
the connection password

setPassword

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.

Parameters:
password - new value for the password

getUrl

public String getUrl()
Returns the JDBC connection url property.

Returns:
the url passed to the JDBC driver to establish connections

setUrl

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.

Parameters:
url - the new value for the JDBC connection url

getUsername

public String getUsername()
Returns the JDBC connection username property.

Returns:
the username passed to the JDBC driver to establish connections

setUsername

public 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.

Parameters:
username - the new value for the JDBC connection username

getValidationQuery

public String getValidationQuery()
Returns the validation query used to validate connections before returning them.

Returns:
the SQL validation query
See Also:
validationQuery

setValidationQuery

public 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.

Parameters:
validationQuery - the new value for the validation query

isAccessToUnderlyingConnectionAllowed

public boolean isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.

Returns:
true if access to the underlying connection is allowed, false otherwise.

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.

getConnection

public Connection getConnection()
                         throws SQLException
Create (if necessary) and return a connection to the database.

Specified by:
getConnection in interface DataSource
Returns:
a database connection
Throws:
SQLException - if a database access error occurs

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
BasicDataSource does NOT support this method.

Specified by:
getConnection in interface DataSource
Parameters:
username - Database user on whose behalf the Connection is being made
password - The database user's password
Returns:
nothing - always throws UnsupportedOperationException
Throws:
UnsupportedOperationException
SQLException - if a database access error occurs

getLoginTimeout

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.

Specified by:
getLoginTimeout in interface DataSource
Returns:
login timeout in seconds
Throws:
SQLException - if a database access error occurs
UnsupportedOperationException - If the DataSource implementation does not support the login timeout feature.

getLogWriter

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.

Specified by:
getLogWriter in interface DataSource
Returns:
log writer in use
Throws:
SQLException - if a database access error occurs

setLoginTimeout

public 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.

Specified by:
setLoginTimeout in interface DataSource
Parameters:
loginTimeout - The new login timeout, or zero for no timeout
Throws:
SQLException - if a database access error occurs

setLogWriter

public 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.

Specified by:
setLogWriter in interface DataSource
Parameters:
logWriter - The new log writer
Throws:
SQLException - if a database access error occurs

getRemoveAbandoned

public boolean getRemoveAbandoned()
Deprecated.  

Flag to remove abandoned connections if they exceed the removeAbandonedTimout. Set to true or false, default false. If set to true a connection is considered abandoned and eligible for removal if it has been idle longer than the removeAbandonedTimeout. Setting this to true can recover db connections from poorly written applications which fail to close a connection.


setRemoveAbandoned

public void setRemoveAbandoned(boolean removeAbandoned)
Deprecated.  

Parameters:
removeAbandoned - new removeAbandoned property value

getRemoveAbandonedTimeout

public int getRemoveAbandonedTimeout()
Deprecated.  

Timeout in seconds before an abandoned connection can be removed. Defaults to 300 seconds.

Returns:
abandoned connection timeout

setRemoveAbandonedTimeout

public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
Deprecated.  

Parameters:
removeAbandonedTimeout - new removeAbandonedTimeout value

getLogAbandoned

public boolean getLogAbandoned()
Deprecated.  

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.


setLogAbandoned

public void setLogAbandoned(boolean logAbandoned)
Deprecated.  

Parameters:
logAbandoned - new logAbandoned property value

addConnectionProperty

public void addConnectionProperty(String name,
                                  String value)
Add a custom connection property to the set that will be passed to our JDBC driver. This MUST be called before the first connection is retrieved (along with all the other configuration property setters). Calls to this method after the connection pool has been initialized have no effect.

Parameters:
name - Name of the custom connection property
value - Value of the custom connection property

removeConnectionProperty

public void removeConnectionProperty(String name)
Remove a custom connection property.

Parameters:
name - Name of the custom connection property to remove
See Also:
addConnectionProperty(String, String)

close

public void close()
           throws SQLException
Close and release all connections that are currently stored in the connection pool associated with our data source.

Throws:
SQLException - if a database error occurs

createDataSource

protected DataSource createDataSource()
                               throws SQLException

Create (if necessary) and return the internal data source we are using to manage our connections.

IMPLEMENTATION NOTE - It is tempting to use the "double checked locking" idiom in an attempt to avoid synchronizing on every single call to this method. However, this idiom fails to work correctly in the face of some optimizations that are legal for a JVM to perform.

Throws:
SQLException - if the object pool cannot be created.


Copyright © The Apache Software Foundation. All Rights Reserved.