jmcnally 02/01/13 17:04:43
Modified: proposals/jdbc2pool/org/apache/torque/jdbc2pool Tag:
JDBC2POOL_BRANCH TorqueDataSource.java
Log:
added getters/setters for pooling properties
Revision Changes Path
No revision
No revision
1.1.2.3 +208 -21
jakarta-turbine-torque/proposals/jdbc2pool/org/apache/torque/jdbc2pool/TorqueDataSource.java
Index: TorqueDataSource.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/proposals/jdbc2pool/org/apache/torque/jdbc2pool/TorqueDataSource.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- TorqueDataSource.java 9 Jan 2002 08:03:31 -0000 1.1.2.2
+++ TorqueDataSource.java 14 Jan 2002 01:04:43 -0000 1.1.2.3
@@ -86,11 +86,14 @@
* Torque's default connection pool DataSource
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
- * @version $Id: TorqueDataSource.java,v 1.1.2.2 2002/01/09 08:03:31 jmcnally Exp $
+ * @version $Id: TorqueDataSource.java,v 1.1.2.3 2002/01/14 01:04:43 jmcnally Exp $
*/
public class TorqueDataSource
implements DataSource, Referenceable, Serializable, ObjectFactory
{
+ /** Pools keyed by username. */
+ private static Map pools = new HashMap();
+
/** DataSource Name used to find the ConnectionPoolDataSource */
private String dataSourceName;
/** Description */
@@ -99,18 +102,19 @@
/** Login TimeOut in seconds */
private int loginTimeout;
- ConnectionPoolDataSource cpds;
+ private ConnectionPoolDataSource cpds;
/** Log stream */
private PrintWriter logWriter;
/** Environment that may be used to set up a jndi initial context. */
- Properties jndiEnvironment;
+ private Properties jndiEnvironment;
- /**
- * Pools keyed by username.
- */
- private static Map pools = new HashMap();
+ private int defaultMaxConnections;
+ private Properties perUserMaxConnections;
+ private int maxExpiryTime;
+ private int connectionWaitTimeout;
+ private int logInterval;
/**
* Default no-arg constructor for Serialization
@@ -120,8 +124,129 @@
}
// Properties
+
+ /**
+ * Get the number of database connections to cache per user.
+ * This value is used for any username which is not specified
+ * in perUserMaxConnections. The default is 1.
+ *
+ * @return value of maxConnections.
+ */
+ public int getDefaultMaxConnections()
+ {
+ return defaultMaxConnections;
+ }
+
+ /**
+ * Set the number of database connections to cache per user.
+ * This value is used for any username which is not specified
+ * in perUserMaxConnections. The default is 1.
+ *
+ * @param v Value to assign to maxConnections.
+ */
+ public void setDefaultMaxConnections(int v)
+ {
+ this.defaultMaxConnections = v;
+ }
+
+
+ /**
+ * Get the number of database connections to cache per user. The keys
+ * are usernames and the value is the maximum connections. Any username
+ * specified here will override the value of defaultMaxConnections.
+ *
+ * @return value of perUserMaxConnections.
+ */
+ public Properties getPerUserMaxConnections()
+ {
+ return perUserMaxConnections;
+ }
/**
+ * Set the number of database connections to cache per user. The keys
+ * are usernames and the value is the maximum connections. Any username
+ * specified here will override the value of defaultMaxConnections.
+ *
+ * @param v Value to assign to perUserMaxConnections.
+ */
+ public void setPerUserMaxConnections(Properties v)
+ {
+ this.perUserMaxConnections = v;
+ }
+
+
+ /**
+ * Get the amount of time (in seconds) that database connections
+ * will be cached. The default is 3600 (1 hour).
+ *
+ * @return value of expiryTime.
+ */
+ public int getMaxExpiryTime()
+ {
+ return maxExpiryTime;
+ }
+
+ /**
+ * Set the amount of time (in seconds) that database connections
+ * will be cached. The default is 3600 (1 hour).
+ *
+ * @param v Value to assign to expiryTime.
+ */
+ public void setMaxExpiryTime(int v)
+ {
+ this.maxExpiryTime = v;
+ }
+
+
+ /**
+ * Get the amount of time (in seconds) a connection request will
+ * have to wait before a time out occurs and an error is thrown.
+ *
+ * @return value of connectionWaitTimeout.
+ */
+ public int getConnectionWaitTimeout()
+ {
+ return connectionWaitTimeout;
+ }
+
+ /**
+ * Eet the amount of time (in seconds) a connection request will
+ * have to wait before a time out occurs and an error is thrown.
+ *
+ * @param v Value to assign to connectionWaitTimeout.
+ */
+ public void setConnectionWaitTimeout(int v)
+ {
+ this.connectionWaitTimeout = v;
+ }
+
+
+ /**
+ * Get the interval (in seconds) between which the ConnectionPool logs
+ * the status of it's Connections. Default is 0 which indicates no
+ * logging.
+ *
+ * @return value of logInterval.
+ */
+ public int getLogInterval()
+ {
+ return logInterval;
+ }
+
+ /**
+ * Set the interval (in seconds) between which the ConnectionPool logs
+ * the status of it's Connections. Default is 0 which indicates no
+ * logging.
+ *
+ * @param v Value to assign to logInterval.
+ */
+ public void setLogInterval(int v)
+ {
+ this.logInterval = v;
+ }
+
+
+ /**
* Get the name of the ConnectionPoolDataSource which backs this pool.
* This name is used to look up the datasource from a jndi service
* provider.
@@ -134,7 +259,7 @@
}
/**
- * Get the name of the ConnectionPoolDataSource which backs this pool.
+ * Set the name of the ConnectionPoolDataSource which backs this pool.
* This name is used to look up the datasource from a jndi service
* provider.
*
@@ -147,7 +272,10 @@
/**
- * Get the value of description.
+ * Get the description. This property is defined by jdbc as for use with
+ * GUI (or other) tools that might deploy the datasource. It serves no
+ * internal purpose.
+ *
* @return value of description.
*/
public String getDescription()
@@ -156,7 +284,10 @@
}
/**
- * Set the value of description.
+ * Set the description. This property is defined by jdbc as for use with
+ * GUI (or other) tools that might deploy the datasource. It serves no
+ * internal purpose.
+ *
* @param v Value to assign to description.
*/
public void setDescription(String v)
@@ -166,7 +297,8 @@
/**
* Get the value of jndiEnvironment which is used when instantiating
- * a jndi InitialContext.
+ * a jndi InitialContext. This InitialContext is used to locate the
+ * backend ConnectionPoolDataSource.
*
* @return value of jndiEnvironment.
*/
@@ -177,7 +309,8 @@
/**
* Set the value of jndiEnvironment which is used when instantiating
- * a jndi InitialContext.
+ * a jndi InitialContext. This InitialContext is used to locate the
+ * backend ConnectionPoolDataSource.
*
* @param v Value to assign to jndiEnvironment.
*/
@@ -185,7 +318,6 @@
{
this.jndiEnvironment = v;
}
-
/**
* Get the value of connectionPoolDataSource. This method will return
@@ -193,7 +325,7 @@
*
* @return value of connectionPoolDataSource.
*/
- ConnectionPoolDataSource getConnectionPoolDataSource()
+ public ConnectionPoolDataSource getConnectionPoolDataSource()
{
return cpds;
}
@@ -204,7 +336,7 @@
*
* @param v Value to assign to connectionPoolDataSource.
*/
- void setConnectionPoolDataSource(ConnectionPoolDataSource v)
+ public void setConnectionPoolDataSource(ConnectionPoolDataSource v)
{
this.cpds = v;
}
@@ -275,7 +407,21 @@
cpds = (ConnectionPoolDataSource)ctx.lookup(dataSourceName);
}
- ConnectionPool pool = new ConnectionPool(cpds, username, password);
+ int maxConnections = getDefaultMaxConnections();
+ if ( username != null )
+ {
+ String userMaxCon =
+ (String)getPerUserMaxConnections().get(username);
+ if ( userMaxCon != null )
+ {
+ maxConnections = Integer.parseInt(userMaxCon);
+ }
+ }
+
+ ConnectionPool pool = new ConnectionPool(cpds, username, password,
+ maxConnections, maxExpiryTime, connectionWaitTimeout,
+ logInterval, logWriter);
+
// avoid ConcurrentModificationException
Map newPools = new HashMap(pools);
newPools.put(key, pool);
@@ -285,7 +431,7 @@
/**
* Gets the maximum time in seconds that this data source can wait
- * while attempting to connect to a database..
+ * while attempting to connect to a database.
*/
public int getLoginTimeout()
{
@@ -302,7 +448,7 @@
/**
* Sets the maximum time in seconds that this data source will wait
- * while attempting to connect to a database.
+ * while attempting to connect to a database. NOT USED.
*/
public void setLoginTimeout(int seconds)
{
@@ -310,7 +456,7 @@
}
/**
- * Set the log writer for this data source.
+ * Set the log writer for this data source. NOT USED.
*/
public void setLogWriter(java.io.PrintWriter out)
{
@@ -327,6 +473,14 @@
Reference ref = new Reference(getClass().getName(), factory, null);
+ ref.add(new StringRefAddr("defaultMaxConnections",
+ String.valueOf(getDefaultMaxConnections())));
+ ref.add(new StringRefAddr("maxExpiryTime",
+ String.valueOf(getMaxExpiryTime())));
+ ref.add(new StringRefAddr("connectionWaitTimeout",
+ String.valueOf(getConnectionWaitTimeout())));
+ ref.add(new StringRefAddr("logInterval",
+ String.valueOf(getLogInterval())));
ref.add(new StringRefAddr("dataSourceName", getDataSourceName()));
ref.add(new StringRefAddr("description", getDescription()));
@@ -345,6 +499,22 @@
"serializing the jndiEnvironment properties.");
}
}
+
+ byte[] serPUMC = null;
+ // BinaryRefAddr does not allow null byte[].
+ if ( getPerUserMaxConnections() != null )
+ {
+ try
+ {
+ serPUMC = serialize(getPerUserMaxConnections());
+ ref.add(new BinaryRefAddr("perUserMaxConnections", serPUMC));
+ }
+ catch (IOException ioe)
+ {
+ throw new NamingException("An IOException prevented " +
+ "serializing the perUserMaxConnections properties.");
+ }
+ }
return ref;
}
@@ -361,15 +531,31 @@
if (ref.getClassName().equals(getClass().getName()))
{
+ setDefaultMaxConnections(Integer.parseInt(
+ (String)ref.get("defaultMaxConnections").getContent()));
+ setMaxExpiryTime(Integer.parseInt(
+ (String)ref.get("maxExpiryTime").getContent()));
+ setConnectionWaitTimeout(Integer.parseInt(
+ (String)ref.get("connectionWaitTimeout").getContent()));
+ setLogInterval(Integer.parseInt(
+ (String)ref.get("logInterval").getContent()));
setDataSourceName((String)ref.get("dataSourceName").getContent());
setDescription((String)ref.get("description").getContent());
RefAddr refAddr = ref.get("jndiEnvironment");
if ( refAddr != null )
{
- byte[] serJndiEnv = (byte[])refAddr.getContent();
+ byte[] serialized = (byte[])refAddr.getContent();
setJndiEnvironment(
- (Properties)ObjectUtils.deserialize(serJndiEnv) );
+ (Properties)ObjectUtils.deserialize(serialized) );
+ }
+
+ refAddr = ref.get("perUserMaxConnections");
+ if ( refAddr != null )
+ {
+ byte[] serialized = (byte[])refAddr.getContent();
+ setPerUserMaxConnections(
+ (Properties)ObjectUtils.deserialize(serialized) );
}
return this;
@@ -383,6 +569,7 @@
/**
* Converts a object to a byte array for storage/serialization.
+ * FIXME! this method should be moved to commons.util.ObjectUtils
*
* @param hash The Hashtable to convert.
* @return A byte[] with the converted Hashtable.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>