jmcnally 02/03/17 22:33:01
Modified: jdbc2pool/src/java/org/apache/commons/jdbc2pool/adapter
DriverAdapterCPDS.java
Log:
added the properties related to the PreparedStatement pool to the Referenceable
and ObjectFactory implementations.
unsynchronized some setters. These setters are meant to be called by a
single thread, but even if they are not, synchronization is not necessary.
Revision Changes Path
1.4 +102 -21
jakarta-commons-sandbox/jdbc2pool/src/java/org/apache/commons/jdbc2pool/adapter/DriverAdapterCPDS.java
Index: DriverAdapterCPDS.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jdbc2pool/src/java/org/apache/commons/jdbc2pool/adapter/DriverAdapterCPDS.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DriverAdapterCPDS.java 4 Mar 2002 07:50:15 -0000 1.3
+++ DriverAdapterCPDS.java 18 Mar 2002 06:33:01 -0000 1.4
@@ -70,6 +70,7 @@
import javax.naming.Referenceable;
import javax.naming.spi.ObjectFactory;
import javax.naming.Reference;
+import javax.naming.RefAddr;
import javax.naming.StringRefAddr;
import javax.naming.NamingException;
@@ -82,7 +83,7 @@
* DriverManager implementation
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
- * @version $Id: DriverAdapterCPDS.java,v 1.3 2002/03/04 07:50:15 jmcnally Exp $
+ * @version $Id: DriverAdapterCPDS.java,v 1.4 2002/03/18 06:33:01 jmcnally Exp $
*/
public class DriverAdapterCPDS
implements ConnectionPoolDataSource, Referenceable, Serializable,
@@ -149,6 +150,8 @@
}
}
+ // ----------------------------------------------------------------------
+ // Referenceable implementation
/**
* <CODE>Referenceable</CODE> implementation.
@@ -156,19 +159,37 @@
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("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())));
+
return ref;
}
+ // ----------------------------------------------------------------------
+ // ObjectFactory implementation
+
/**
* implements ObjectFactory to create an instance of this class
*/
@@ -176,21 +197,80 @@
Context context, Hashtable env)
throws Exception
{
- Reference ref = (Reference)refObj;
-
- if (ref.getClassName().equals(getClass().getName()))
- {
- setDescription((String)ref.get("description").getContent());
- setUrl((String)ref.get("url").getContent());
- setUser((String)ref.get("user").getContent());
- setPassword((String)ref.get("password").getContent());
- return this;
- }
- else
- {
- // We can't create an instance of the reference
- return null;
+ // 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("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()));
+ }
+
+ cpds = this;
+ }
}
+ return cpds;
}
/**
@@ -206,6 +286,7 @@
}
}
+ // ----------------------------------------------------------------------
// Properties
/**
@@ -392,7 +473,7 @@
*
* *see #setTimeBetweenEvictionRunsMillis
*/
- public synchronized long getTimeBetweenEvictionRunsMillis() {
+ public int getTimeBetweenEvictionRunsMillis() {
return _timeBetweenEvictionRunsMillis;
}
@@ -404,8 +485,8 @@
*
* *see #getTimeBetweenEvictionRunsMillis
*/
- public synchronized void
- setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
+ public void
+ setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
assertInitializationAllowed();
_timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
@@ -445,7 +526,7 @@
* *see #setMinEvictableIdleTimeMillis
* *see #setTimeBetweenEvictionRunsMillis
*/
- public synchronized int getMinEvictableIdleTimeMillis() {
+ public int getMinEvictableIdleTimeMillis() {
return _minEvictableIdleTimeMillis;
}
@@ -459,7 +540,7 @@
* *see #getMinEvictableIdleTimeMillis
* *see #setTimeBetweenEvictionRunsMillis
*/
- public synchronized void
+ public void
setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
assertInitializationAllowed();
_minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
@@ -484,7 +565,7 @@
// PreparedStatement pool properties
private int maxActive = 10;
private int maxIdle = 10;
- private long _timeBetweenEvictionRunsMillis = -1L;
+ private int _timeBetweenEvictionRunsMillis = -1;
private int _numTestsPerEvictionRun = -1;
private int _minEvictableIdleTimeMillis = -1;
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>