|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.dbcp.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.
Field Summary | |
protected org.apache.commons.pool.impl.GenericObjectPool |
connectionPool
The object pool that internally manages our connections. |
protected java.util.Properties |
connectionProperties
The connection properties that will be sent to our JDBC driver when establishing new connections. |
protected javax.sql.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 boolean |
defaultReadOnly
The default read-only state of connections created by this pool. |
protected java.lang.String |
driverClassName
The fully qualified Java class name of the JDBC driver to be used. |
protected java.io.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 zero for no limit. |
protected int |
maxIdle
The maximum number of active connections that can remain idle in the pool, without extra ones being released, or zero 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 java.lang.String |
password
The connection password to be passed to our JDBC driver to establish a connection. |
protected java.lang.String |
url
The connection URL to be passed to our JDBC driver to establish a connection. |
protected java.lang.String |
username
The connection username to be passed to our JDBC driver to establish a connection. |
protected java.lang.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(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. |
protected javax.sql.DataSource |
createDataSource()
Create (if necessary) and return the internal data source we are using to manage our connections. |
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()
|
boolean |
getDefaultReadOnly()
|
java.lang.String |
getDriverClassName()
|
boolean |
getLogAbandoned()
Flag to log stack traces for application code which abandoned a Statement or Connection. |
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()
|
long |
getMaxWait()
|
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. |
java.lang.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. |
java.lang.String |
getUrl()
|
java.lang.String |
getUsername()
|
java.lang.String |
getValidationQuery()
|
void |
setDefaultAutoCommit(boolean defaultAutoCommit)
|
void |
setDefaultReadOnly(boolean defaultReadOnly)
|
void |
setDriverClassName(java.lang.String driverClassName)
|
void |
setLogAbandoned(boolean logAbandoned)
|
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 |
setMaxWait(long maxWait)
|
void |
setPassword(java.lang.String password)
|
void |
setRemoveAbandoned(boolean removeAbandoned)
|
void |
setRemoveAbandonedTimeout(int removeAbandonedTimeout)
|
void |
setUrl(java.lang.String url)
|
void |
setUsername(java.lang.String username)
|
void |
setValidationQuery(java.lang.String validationQuery)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected org.apache.commons.pool.impl.GenericObjectPool connectionPool
protected java.util.Properties connectionProperties
protected javax.sql.DataSource dataSource
createDataSource()
method.
protected boolean defaultAutoCommit
protected boolean defaultReadOnly
protected java.lang.String driverClassName
protected java.io.PrintWriter logWriter
protected int maxActive
protected int maxIdle
protected long maxWait
protected java.lang.String password
protected java.lang.String url
protected java.lang.String username
protected java.lang.String validationQuery
Constructor Detail |
public BasicDataSource()
Method Detail |
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 occursprotected javax.sql.DataSource createDataSource() throws java.sql.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.
java.sql.SQLException
- if the object pool cannot be created.public 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 password
java.sql.SQLException
- if a database access error occurspublic boolean getDefaultAutoCommit()
public boolean getDefaultReadOnly()
public java.lang.String getDriverClassName()
public boolean getLogAbandoned()
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic int getMaxActive()
public int getMaxIdle()
public long getMaxWait()
public int getNumActive()
public int getNumIdle()
public java.lang.String getPassword()
public boolean getRemoveAbandoned()
public int getRemoveAbandonedTimeout()
public java.lang.String getUrl()
public java.lang.String getUsername()
public java.lang.String getValidationQuery()
public void setDefaultAutoCommit(boolean defaultAutoCommit)
public void setDefaultReadOnly(boolean defaultReadOnly)
public void setDriverClassName(java.lang.String driverClassName)
public void setLogAbandoned(boolean logAbandoned)
public void setLoginTimeout(int loginTimeout) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.DataSource
loginTimeout
- The new login timeout, or zero for no timeout
java.sql.SQLException
- if a database access error occurspublic void setLogWriter(java.io.PrintWriter logWriter) throws java.sql.SQLException
setLogWriter
in interface javax.sql.DataSource
logWriter
- The new log writer
java.sql.SQLException
- if a database access error occurspublic void setMaxActive(int maxActive)
public void setMaxIdle(int maxIdle)
public void setMaxWait(long maxWait)
public void setPassword(java.lang.String password)
public void setRemoveAbandoned(boolean removeAbandoned)
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
public void setUrl(java.lang.String url)
public void setUsername(java.lang.String username)
public void setValidationQuery(java.lang.String validationQuery)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |