Is there a reason why the ResourceLimitingJdbcDatasource doesn't allow
maxStrict parameter to the ResourceLimitingPool to be configured?
Without it, the only difference between the
ResourceLimitingJdbcDataSource and the JdbcDataSource is that the former
will allow you to block if max connections has been met.
I've attached a patch that allows maxStrict to be customized. I've also
added a bit of documentation on the auto-commit option.
-Mark
Index:
src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java
===================================================================
RCS file:
/home/cvspublic/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java,v
retrieving revision 1.5
diff -u -r1.5 ResourceLimitingJdbcDataSource.java
---
src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java
8 Feb 2002 12:03:52 -0000 1.5
+++
+src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java
+ 22 Feb 2002 07:43:33 -0000
@@ -19,15 +19,16 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
- * The ResourceLimiting implementation for DataSources in Avalon. This uses the
- * normal <code>java.sql.Connection</code> object and
+ * The ResourceLimiting implementation for DataSources in Avalon.
+ * This uses the normal <code>java.sql.Connection</code> object and
* <code>java.sql.DriverManager</code>.
* <p>
* Configuration Example:
* <pre>
* <jdbc>
- * <pool-controller max="<i>10</i>" blocking="<i>true</i>"
- * timeout="<i>-1</i>" trim-interval="<i>60000</i>"
+ * <pool-controller max="<i>10</i>" maxStrict="<i>true</i>"
+ * blocking="<i>true</i>" timeout="<i>-1</i>"
+ * trim-interval="<i>60000</i>" auto-commit="true"
* connection-class="<i>my.overrided.ConnectionClass</i>">
* <keep-alive disable="false">select 1</keep-alive>
* </pool-controller>
@@ -50,44 +51,65 @@
* <p>
* Configuration Attributes:
* <ul>
- * <li>The <code>max</code> attribute is used to set the maximum number of
connections which
- * will be opened. See the <code>blocking</code> attribute. (Defaults to "3")</li>
+ * <li>The <code>max</code> attribute is used to set the maximum
+ * number of connections which will be opened. See the
+ * <code>blocking</code> attribute. (Defaults to "3")</li>
*
- * <li>The <code>blocking</code> attributes is used to specify the behavior of the
DataSource
- * pool when an attempt is made to allocate more than <code>max</code> concurrent
connections.
- * If true, the request will block until a connection is released, otherwise, a
- * NoAvailableConnectionException will be thrown. (Defaults to "true")</li>
- *
- * <li>The <code>timeout</code> attribute is used to specify the maximum amount of
time in
- * milliseconds that a request for a connection will be allowed to block before a
- * NoAvailableConnectionException is thrown. A value of "0" specifies that the
block will never
- * timeout. (Defaults to "0")</li>
- *
- * <li>The <code>trim-interval</code> attribute is used to specify how long idle
connections will
- * be maintained in the pool before being closed. For a complete explanation on how
this works,
- * see {@link org.apache.avalon.excalibur.pool.ResourceLimitingPool#trim()}
- * (Defaults to "60000", 1 minute)</li>
- *
- * <li>The <code>connection-class</code> attribute is used to override the Connection
class returned
- * by the DataSource from calls to getConnection(). Set this to
- * "org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain access to JDBC3
features.
- * Jdbc3Connection does not exist if your JVM does not support JDBC3.
- * (Defaults to "org.apache.avalon.excalibur.datasource.JdbcConnection")</li>
- *
- * <li>The <code>keep-alive</code> element is used to override the query used to
monitor the health
- * of connections. If a connection has not been used for 5 seconds then before
returning the
- * connection from a call to getConnection(), the connection is first used to ping
the database
- * to make sure that it is still alive. Setting the <code>disable</code> attribute
to true will
- * disable this feature. (Defaults to a query of "SELECT 1" and being enabled)</li>
+ * <li>The <code>maxStrict</code> attribute is determines if the
+ * maximum number of connections will ever be exceeded. An exception
+ * will be thrown if more than max connections are requested and
+ * blocking is false. (Defaults to "true")</li>
*
- * <li>The <code>driver</code> element is used to specify the driver to use when
connecting to the
- * database. The specified class must be in the classpath. (Required)</li>
+ * <li>The <code>blocking</code> attributes is used to specify the
+ * behavior of the DataSource pool when an attempt is made to allocate
+ * more than <code>max</code> concurrent connections. If true, the
+ * request will block until a connection is released, otherwise, a
+ * NoAvailableConnectionException will be thrown. (Defaults to
+ * "true")</li>
*
- * <li>The <code>dburl</code> element is the JDBC connection string which will be
used to connect to
- * the database. (Required)</li>
+ * <li>The <code>timeout</code> attribute is used to specify the
+ * maximum amount of time in milliseconds that a request for a
+ * connection will be allowed to block before a
+ * NoAvailableConnectionException is thrown. A value of "0" specifies
+ * that the block will never timeout. (Defaults to "0")</li>
*
- * <li>The <code>user</code> and <code>password</code> attributes are used to specify
the user and
- * password for connections to the database. (Required)</li>
+ * <li>The <code>trim-interval</code> attribute is used to specify how
+ * long idle connections will be maintained in the pool before being
+ * closed. For a complete explanation on how this works, see {@link
+ * org.apache.avalon.excalibur.pool.ResourceLimitingPool#trim()}
+ * (Defaults to "60000", 1 minute)</li>
+ *
+ * <li>The <code>auto-commit</code> attribute is used to determine the
+ * default auto-commit mode for the <code>Connection</code>s returned
+ * by this <code>DataSource</code>.
+ *
+ * <li>The <code>connection-class</code> attribute is used to override
+ * the Connection class returned by the DataSource from calls to
+ * getConnection(). Set this to
+ * "org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain
+ * access to JDBC3 features. Jdbc3Connection does not exist if your
+ * JVM does not support JDBC3. (Defaults to
+ * "org.apache.avalon.excalibur.datasource.JdbcConnection")</li>
+ *
+ * <li>The <code>keep-alive</code> element is used to override the
+ * query used to monitor the health of connections. If a connection
+ * has not been used for 5 seconds then before returning the
+ * connection from a call to getConnection(), the connection is first
+ * used to ping the database to make sure that it is still alive.
+ * Setting the <code>disable</code> attribute to true will disable
+ * this feature. (Defaults to a query of "SELECT 1" and being
+ * enabled)</li>
+ *
+ * <li>The <code>driver</code> element is used to specify the driver
+ * to use when connecting to the database. The specified class must
+ * be in the classpath. (Required)</li>
+ *
+ * <li>The <code>dburl</code> element is the JDBC connection string
+ * which will be used to connect to the database. (Required)</li>
+ *
+ * <li>The <code>user</code> and <code>password</code> attributes are
+ * used to specify the user and password for connections to the
+ * database. (Required)</li>
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
@@ -175,6 +197,7 @@
final boolean disableKeepAlive = controller.getChild( "keep-alive"
).getAttributeAsBoolean( "disable", false );
final int max = controller.getAttributeAsInteger( "max", 3 );
+ final boolean maxStrict = controller.getAttributeAsBoolean( "maxStrict",
+true );
final boolean blocking = controller.getAttributeAsBoolean( "blocking",
true );
final long timeout = controller.getAttributeAsLong ( "timeout", 0 );
final long trimInterval = controller.getAttributeAsLong (
"trim-interval", 60000 );
@@ -251,7 +274,7 @@
try
{
m_pool = new ResourceLimitingJdbcConnectionPool
- (factory, l_max, true, blocking, timeout, trimInterval, autoCommit );
+ (factory, l_max, maxStrict, blocking, timeout, trimInterval,
+autoCommit );
m_pool.enableLogging( getLogger() );
}
catch (Exception e)
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>