Although normally used within a JNDI environment, the DriverAdapterCPDS
can be instantiated and initialized as any bean and then attached
directly to a pooling DataSource.
Jdbc2PoolDataSource can use the
ConnectionPoolDataSource with or without the use of JNDI.
| Method from org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS Detail: |
public String getDescription() {
return description;
}
Get the value of description. This property is here for use by
the code which will deploy this datasource. It is not used
internally. |
public String getDriver() {
return driver;
}
Get the driver classname. |
public PrintWriter getLogWriter() {
return logWriter;
}
Get the log writer for this data source. NOT USED. |
public int getLoginTimeout() {
return loginTimeout;
}
Gets the maximum time in seconds that this data source can wait
while attempting to connect to a database. NOT USED. |
public int getMaxActive() {
return (this.maxActive);
}
The maximum number of active statements that can be allocated from
this pool at the same time, or non-positive for no limit. |
public int getMaxIdle() {
return (this.maxIdle);
}
The maximum number of statements that can remain idle in the
pool, without extra ones being released, or negative for no limit. |
public int getMaxPreparedStatements() {
return _maxPreparedStatements;
}
Returns the maximun number of prepared statements. |
public int getMinEvictableIdleTimeMillis() {
return _minEvictableIdleTimeMillis;
}
Returns the minimum amount of time a statement may sit idle in the pool
before it is eligible for eviction by the idle object evictor
(if any).
*see #setMinEvictableIdleTimeMillis
*see #setTimeBetweenEvictionRunsMillis |
public int getNumTestsPerEvictionRun() {
return _numTestsPerEvictionRun;
}
Returns the number of statements to examine during each run of the
idle object evictor thread (if any).
*see #setNumTestsPerEvictionRun
*see #setTimeBetweenEvictionRunsMillis |
public Object getObjectInstance(Object refObj,
Name name,
Context context,
Hashtable env) throws Exception {
// The spec says to return null if we can't create an instance
// of the reference
DriverAdapterCPDS cpds = null;
if (refObj instanceof Reference) {
Reference ref = (Reference)refObj;
if (ref.getClassName().equals(getClass().getName())) {
RefAddr ra = ref.get("description");
if (ra != null && ra.getContent() != null) {
setDescription(ra.getContent().toString());
}
ra = ref.get("driver");
if (ra != null && ra.getContent() != null) {
setDriver(ra.getContent().toString());
}
ra = ref.get("url");
if (ra != null && ra.getContent() != null) {
setUrl(ra.getContent().toString());
}
ra = ref.get("user");
if (ra != null && ra.getContent() != null) {
setUser(ra.getContent().toString());
}
ra = ref.get("password");
if (ra != null && ra.getContent() != null) {
setPassword(ra.getContent().toString());
}
ra = ref.get("poolPreparedStatements");
if (ra != null && ra.getContent() != null) {
setPoolPreparedStatements(
Boolean.getBoolean(ra.getContent().toString()));
}
ra = ref.get("maxActive");
if (ra != null && ra.getContent() != null) {
setMaxActive(Integer.parseInt(ra.getContent().toString()));
}
ra = ref.get("maxIdle");
if (ra != null && ra.getContent() != null) {
setMaxIdle(Integer.parseInt(ra.getContent().toString()));
}
ra = ref.get("timeBetweenEvictionRunsMillis");
if (ra != null && ra.getContent() != null) {
setTimeBetweenEvictionRunsMillis(
Integer.parseInt(ra.getContent().toString()));
}
ra = ref.get("numTestsPerEvictionRun");
if (ra != null && ra.getContent() != null) {
setNumTestsPerEvictionRun(
Integer.parseInt(ra.getContent().toString()));
}
ra = ref.get("minEvictableIdleTimeMillis");
if (ra != null && ra.getContent() != null) {
setMinEvictableIdleTimeMillis(
Integer.parseInt(ra.getContent().toString()));
}
ra = ref.get("maxPreparedStatements");
if (ra != null && ra.getContent() != null) {
setMaxPreparedStatements(
Integer.parseInt(ra.getContent().toString()));
}
cpds = this;
}
}
return cpds;
}
implements ObjectFactory to create an instance of this class |
public String getPassword() {
return password;
}
Get the value of password for the default user. |
public PooledConnection getPooledConnection() throws SQLException {
return getPooledConnection(getUser(), getPassword());
}
Attempt to establish a database connection using the default
user and password. |
public PooledConnection getPooledConnection(String username,
String password) throws SQLException {
getConnectionCalled = true;
/*
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive, byte whenExhaustedAction, long maxWait,
int maxIdle, boolean testOnBorrow, boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
boolean testWhileIdle) {
*/
KeyedObjectPool stmtPool = null;
if (isPoolPreparedStatements()) {
if (getMaxPreparedStatements() < = 0)
{
// since there is no limit, create a prepared statement pool with an eviction thread
// evictor settings are the same as the connection pool settings.
stmtPool = new GenericKeyedObjectPool(null,
getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
getMaxIdle(), false, false,
getTimeBetweenEvictionRunsMillis(),getNumTestsPerEvictionRun(),getMinEvictableIdleTimeMillis(),
false);
}
else
{
// since there is limit, create a prepared statement pool without an eviction thread
// pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
// see org.apache.commons.pool.impl.GenericKeyedObjectPool.clearOldest method
stmtPool = new GenericKeyedObjectPool(null,
getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
getMaxIdle(), getMaxPreparedStatements(), false, false,
-1,0,0, // -1 tells the pool that there should be no eviction thread.
false);
}
}
// Workaround for buggy WebLogic 5.1 classloader - ignore the
// exception upon first invocation.
try {
return new PooledConnectionImpl(
DriverManager.getConnection(getUrl(), username, password),
stmtPool );
}
catch (ClassCircularityError e)
{
return new PooledConnectionImpl(
DriverManager.getConnection(getUrl(), username, password),
stmtPool );
}
}
Attempt to establish a database connection. |
public Reference getReference() throws NamingException {
// this class implements its own factory
String factory = getClass().getName();
Reference ref = new Reference(getClass().getName(), factory, null);
ref.add(new StringRefAddr("description", getDescription()));
ref.add(new StringRefAddr("driver", getDriver()));
ref.add(new StringRefAddr("loginTimeout",
String.valueOf(getLoginTimeout())));
ref.add(new StringRefAddr("password", getPassword()));
ref.add(new StringRefAddr("user", getUser()));
ref.add(new StringRefAddr("url", getUrl()));
ref.add(new StringRefAddr("poolPreparedStatements",
String.valueOf(isPoolPreparedStatements())));
ref.add(new StringRefAddr("maxActive",
String.valueOf(getMaxActive())));
ref.add(new StringRefAddr("maxIdle",
String.valueOf(getMaxIdle())));
ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis",
String.valueOf(getTimeBetweenEvictionRunsMillis())));
ref.add(new StringRefAddr("numTestsPerEvictionRun",
String.valueOf(getNumTestsPerEvictionRun())));
ref.add(new StringRefAddr("minEvictableIdleTimeMillis",
String.valueOf(getMinEvictableIdleTimeMillis())));
ref.add(new StringRefAddr("maxPreparedStatements",
String.valueOf(getMaxPreparedStatements())));
return ref;
}
Referenceable implementation.
|
public int getTimeBetweenEvictionRunsMillis() {
return _timeBetweenEvictionRunsMillis;
}
Returns 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.
*see #setTimeBetweenEvictionRunsMillis |
public String getUrl() {
return url;
}
Get the value of url used to locate the database for this datasource. |
public String getUser() {
return user;
}
Get the value of default user (login or username). |
public boolean isPoolPreparedStatements() {
return poolPreparedStatements;
}
Flag to toggle the pooling of PreparedStatements |
public void setDescription(String v) {
this.description = v;
}
Set the value of description. This property is here for use by
the code which will deploy this datasource. It is not used
internally. |
public void setDriver(String v) throws ClassNotFoundException {
assertInitializationAllowed();
this.driver = v;
// make sure driver is registered
Class.forName(v);
}
Set the driver classname. Setting the driver classname cause the
driver to be registered with the DriverManager. |
public void setLogWriter(PrintWriter out) {
logWriter = out;
}
Set the log writer for this data source. NOT USED. |
public void setLoginTimeout(int seconds) {
loginTimeout = seconds;
}
Sets the maximum time in seconds that this data source will wait
while attempting to connect to a database. NOT USED. |
public void setMaxActive(int maxActive) {
assertInitializationAllowed();
this.maxActive = maxActive;
}
The maximum number of active statements that can be allocated from
this pool at the same time, or non-positive for no limit. |
public void setMaxIdle(int maxIdle) {
assertInitializationAllowed();
this.maxIdle = maxIdle;
}
The maximum number of statements that can remain idle in the
pool, without extra ones being released, or negative for no limit. |
public void setMaxPreparedStatements(int maxPreparedStatements) {
_maxPreparedStatements = maxPreparedStatements;
}
Sets the maximum number of prepared statements. |
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
assertInitializationAllowed();
_minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
Sets the minimum amount of time a statement may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any).
When non-positive, no objects will be evicted from the pool
due to idle time alone.
*see #getMinEvictableIdleTimeMillis
*see #setTimeBetweenEvictionRunsMillis |
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
assertInitializationAllowed();
_numTestsPerEvictionRun = numTestsPerEvictionRun;
}
Sets the number of statements to examine during each run of the
idle object evictor thread (if any).
When a negative value is supplied, ceil({*link #numIdle})/abs({*link #getNumTestsPerEvictionRun})
tests will be run. I.e., when the value is -n, roughly one nth of the
idle objects will be tested per run.
*see #getNumTestsPerEvictionRun
*see #setTimeBetweenEvictionRunsMillis |
public void setPassword(String v) {
assertInitializationAllowed();
this.password = v;
}
Set the value of password for the default user. |
public void setPoolPreparedStatements(boolean v) {
assertInitializationAllowed();
this.poolPreparedStatements = v;
}
Flag to toggle the pooling of PreparedStatements |
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
assertInitializationAllowed();
_timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
Sets 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.
*see #getTimeBetweenEvictionRunsMillis |
public void setUrl(String v) {
assertInitializationAllowed();
this.url = v;
}
Set the value of url used to locate the database for this datasource. |
public void setUser(String v) {
assertInitializationAllowed();
this.user = v;
}
Set the value of default user (login or username). |