org.apache.commons.dbcp
public class BasicDataSource extends java.lang.Object implements javax.sql.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.
Constructor and Description |
---|
BasicDataSource() |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionProperty(java.lang.String name,
java.lang.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.
|
java.sql.Connection |
getConnection()
Create (if necessary) and return a connection to the database.
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
Create (if necessary) and return a connection to the database.
|
boolean |
getDefaultAutoCommit() |
java.lang.String |
getDefaultCatalog() |
boolean |
getDefaultReadOnly() |
int |
getDefaultTransactionIsolation() |
java.lang.String |
getDriverClassName() |
int |
getInitialSize() |
int |
getLoginTimeout()
Return the login timeout (in seconds) for connecting to the database.
|
java.io.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() |
java.util.logging.Logger |
getParentLogger() |
java.lang.String |
getPassword() |
boolean |
getTestOnBorrow() |
boolean |
getTestOnReturn() |
boolean |
getTestWhileIdle() |
long |
getTimeBetweenEvictionRunsMillis() |
java.lang.String |
getUrl() |
java.lang.String |
getUsername() |
java.lang.String |
getValidationQuery() |
boolean |
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.
|
boolean |
isPoolPreparedStatements()
Returns true if we are pooling statements.
|
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
removeConnectionProperty(java.lang.String name) |
void |
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.
|
void |
setDefaultAutoCommit(boolean defaultAutoCommit) |
void |
setDefaultCatalog(java.lang.String defaultCatalog) |
void |
setDefaultReadOnly(boolean defaultReadOnly) |
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation) |
void |
setDriverClassName(java.lang.String driverClassName) |
void |
setInitialSize(int initialSize) |
void |
setLoginTimeout(int loginTimeout)
Set the login timeout (in seconds) for connecting to the database.
|
void |
setLogWriter(java.io.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(java.lang.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(java.lang.String url) |
void |
setUsername(java.lang.String username) |
void |
setValidationQuery(java.lang.String validationQuery) |
<T> T |
unwrap(java.lang.Class<T> iface) |
public void addConnectionProperty(java.lang.String name, java.lang.String value)
name
- Name of the custom connection propertyvalue
- Value of the custom connection propertypublic void close() throws java.sql.SQLException
java.sql.SQLException
- if a database error occurspublic java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
username
- Database user on whose behalf the Connection
is being madepassword
- The database user's passwordjava.sql.SQLException
- if a database access error occurspublic boolean getDefaultAutoCommit()
public java.lang.String getDefaultCatalog()
public boolean getDefaultReadOnly()
public int getDefaultTransactionIsolation()
public java.lang.String getDriverClassName()
public int getInitialSize()
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
- if a database access error occurspublic java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
- if a database access error occurspublic int getMaxActive()
public int getMaxIdle()
public int getMaxOpenPreparedStatements()
public long getMaxWait()
public long getMinEvictableIdleTimeMillis()
public int getMinIdle()
public int getNumActive()
public int getNumIdle()
public int getNumTestsPerEvictionRun()
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
java.sql.SQLFeatureNotSupportedException
public java.lang.String getPassword()
public boolean getTestOnBorrow()
public boolean getTestOnReturn()
public boolean getTestWhileIdle()
public long getTimeBetweenEvictionRunsMillis()
public java.lang.String getUrl()
public java.lang.String getUsername()
public java.lang.String getValidationQuery()
public boolean isAccessToUnderlyingConnectionAllowed()
public boolean isPoolPreparedStatements()
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
java.sql.SQLException
public void removeConnectionProperty(java.lang.String name)
public void setAccessToUnderlyingConnectionAllowed(boolean allow)
allow
- Access to the underlying connection is granted when true.public void setDefaultAutoCommit(boolean defaultAutoCommit)
public void setDefaultCatalog(java.lang.String defaultCatalog)
public void setDefaultReadOnly(boolean defaultReadOnly)
public void setDefaultTransactionIsolation(int defaultTransactionIsolation)
public void setDriverClassName(java.lang.String driverClassName)
public void setInitialSize(int initialSize)
public void setLoginTimeout(int loginTimeout) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
loginTimeout
- The new login timeout, or zero for no timeoutjava.sql.SQLException
- if a database access error occurspublic void setLogWriter(java.io.PrintWriter logWriter) throws java.sql.SQLException
setLogWriter
in interface javax.sql.CommonDataSource
logWriter
- The new log writerjava.sql.SQLException
- if a database access error occurspublic void setMaxActive(int maxActive)
public void setMaxIdle(int maxIdle)
public void setMaxOpenPreparedStatements(int maxOpenStatements)
public void setMaxWait(long maxWait)
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
public void setMinIdle(int minIdle)
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
public void setPassword(java.lang.String password)
public void setPoolPreparedStatements(boolean poolingStatements)
poolPreparedStatements
- pooling on or offpublic void setTestOnBorrow(boolean testOnBorrow)
public void setTestOnReturn(boolean testOnReturn)
public void setTestWhileIdle(boolean testWhileIdle)
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
public void setUrl(java.lang.String url)
public void setUsername(java.lang.String username)
public void setValidationQuery(java.lang.String validationQuery)
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
java.sql.SQLException
Copyright © 2001-2003 Apache Software Foundation. Documenation generated May 10 2016.