org.apache.commons.dbcp
Class BasicDataSource

java.lang.Object
  extended by org.apache.commons.dbcp.BasicDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, 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: 1.37 $ $Date: 2004/06/09 18:21:23 $
Author:
Glenn L. Nielsen, Craig R. McClanahan, Dirk Verbeeck

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)
          Create (if necessary) and return a connection to the database.
 boolean getDefaultAutoCommit()
           
 String getDefaultCatalog()
           
 boolean getDefaultReadOnly()
           
 int getDefaultTransactionIsolation()
           
 String getDriverClassName()
           
 int getInitialSize()
           
 int getLoginTimeout()
          Return the login timeout (in seconds) for connecting to the database.
 PrintWriter getLogWriter()
          Return the log writer being used by this data source.
 int getMaxActive()
           
 int getMaxIdle()
           
 int getMaxOpenPreparedStatements()
           
 long getMaxWait()
           
 long getMinEvictableIdleTimeMillis()
           
 int getMinIdle()
           
 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()
           
 String getPassword()
           
 boolean getTestOnBorrow()
           
 boolean getTestOnReturn()
           
 boolean getTestWhileIdle()
           
 long getTimeBetweenEvictionRunsMillis()
           
 String getUrl()
           
 String getUsername()
           
 String getValidationQuery()
           
 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)
           
 void setAccessToUnderlyingConnectionAllowed(boolean allow)
          Sets the value of the accessToUnderlyingConnectionAllowed property.
 void setDefaultAutoCommit(boolean defaultAutoCommit)
           
 void setDefaultCatalog(String defaultCatalog)
           
 void setDefaultReadOnly(boolean defaultReadOnly)
           
 void setDefaultTransactionIsolation(int defaultTransactionIsolation)
           
 void setDriverClassName(String driverClassName)
           
 void setInitialSize(int initialSize)
           
 void setLoginTimeout(int loginTimeout)
          Set the login timeout (in seconds) for connecting to the database.
 void setLogWriter(PrintWriter logWriter)
          Set the log writer being used by this data source.
 void setMaxActive(int maxActive)
           
 void setMaxIdle(int maxIdle)
           
 void setMaxOpenPreparedStatements(int maxOpenStatements)
           
 void setMaxWait(long maxWait)
           
 void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
           
 void setMinIdle(int minIdle)
           
 void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
           
 void setPassword(String password)
           
 void setPoolPreparedStatements(boolean poolingStatements)
          Sets whether to pool statements or not.
 void setTestOnBorrow(boolean testOnBorrow)
           
 void setTestOnReturn(boolean testOnReturn)
           
 void setTestWhileIdle(boolean testWhileIdle)
           
 void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
 void setValidationQuery(String validationQuery)
           
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicDataSource

public BasicDataSource()
Method Detail

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

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

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

getConnection

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

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

getConnection

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

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

getDefaultAutoCommit

public boolean getDefaultAutoCommit()

getDefaultCatalog

public String getDefaultCatalog()

getDefaultReadOnly

public boolean getDefaultReadOnly()

getDefaultTransactionIsolation

public int getDefaultTransactionIsolation()

getDriverClassName

public String getDriverClassName()

getInitialSize

public int getInitialSize()

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Return the login timeout (in seconds) for connecting to the database.

Specified by:
getLoginTimeout in interface CommonDataSource
Throws:
SQLException - if a database access error occurs

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Return the log writer being used by this data source.

Specified by:
getLogWriter in interface CommonDataSource
Throws:
SQLException - if a database access error occurs

getMaxActive

public int getMaxActive()

getMaxIdle

public int getMaxIdle()

getMaxOpenPreparedStatements

public int getMaxOpenPreparedStatements()

getMaxWait

public long getMaxWait()

getMinEvictableIdleTimeMillis

public long getMinEvictableIdleTimeMillis()

getMinIdle

public int getMinIdle()

getNumActive

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


getNumIdle

public int getNumIdle()
[Read Only] The current number of idle connections that are waiting to be allocated from this data source.


getNumTestsPerEvictionRun

public int getNumTestsPerEvictionRun()

getPassword

public String getPassword()

getTestOnBorrow

public boolean getTestOnBorrow()

getTestOnReturn

public boolean getTestOnReturn()

getTestWhileIdle

public boolean getTestWhileIdle()

getTimeBetweenEvictionRunsMillis

public long getTimeBetweenEvictionRunsMillis()

getUrl

public String getUrl()

getUsername

public String getUsername()

getValidationQuery

public String getValidationQuery()

isAccessToUnderlyingConnectionAllowed

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

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

isPoolPreparedStatements

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

Returns:
boolean

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
Specified by:
isWrapperFor in interface Wrapper
Throws:
SQLException

removeConnectionProperty

public void removeConnectionProperty(String name)

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)

Parameters:
allow - Access to the underlying connection is granted when true.

setDefaultAutoCommit

public void setDefaultAutoCommit(boolean defaultAutoCommit)

setDefaultCatalog

public void setDefaultCatalog(String defaultCatalog)

setDefaultReadOnly

public void setDefaultReadOnly(boolean defaultReadOnly)

setDefaultTransactionIsolation

public void setDefaultTransactionIsolation(int defaultTransactionIsolation)

setDriverClassName

public void setDriverClassName(String driverClassName)

setInitialSize

public void setInitialSize(int initialSize)

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
                     throws SQLException
Set the login timeout (in seconds) for connecting to the database.

Specified by:
setLoginTimeout in interface CommonDataSource
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
Set the log writer being used by this data source.

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

setMaxActive

public void setMaxActive(int maxActive)

setMaxIdle

public void setMaxIdle(int maxIdle)

setMaxOpenPreparedStatements

public void setMaxOpenPreparedStatements(int maxOpenStatements)

setMaxWait

public void setMaxWait(long maxWait)

setMinEvictableIdleTimeMillis

public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)

setMinIdle

public void setMinIdle(int minIdle)

setNumTestsPerEvictionRun

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)

setPassword

public void setPassword(String password)

setPoolPreparedStatements

public void setPoolPreparedStatements(boolean poolingStatements)
Sets whether to pool statements or not.

Parameters:
poolPreparedStatements - pooling on or off

setTestOnBorrow

public void setTestOnBorrow(boolean testOnBorrow)

setTestOnReturn

public void setTestOnReturn(boolean testOnReturn)

setTestWhileIdle

public void setTestWhileIdle(boolean testWhileIdle)

setTimeBetweenEvictionRunsMillis

public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)

setUrl

public void setUrl(String url)

setUsername

public void setUsername(String username)

setValidationQuery

public void setValidationQuery(String validationQuery)

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException
Specified by:
unwrap in interface Wrapper
Throws:
SQLException


Copyright © 2001-2003 Apache Software Foundation. Documenation generated December 20 2010.