You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2002/11/28 22:22:13 UTC
cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling PoolConfiguration.java ByPassConnection.java
arminw 2002/11/28 13:22:13
Modified: src/java/org/apache/ojb/broker/util/configuration/impl
OjbConfiguration.java
src/java/org/apache/ojb/broker/util/factory
ConfigurableFactory.java
src/java/org/apache/ojb/broker/util/sequence
SequenceGenerator.java
src/java/org/apache/ojb/broker/util/pooling
ByPassConnection.java
Added: src/java/org/apache/ojb/broker/util/pooling
PoolConfiguration.java
Log:
fix sequence generator, add class PoolConfiguration,
change logging
Revision Changes Path
1.14 +38 -26 jakarta-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java
Index: OjbConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- OjbConfiguration.java 20 Oct 2002 15:50:57 -0000 1.13
+++ OjbConfiguration.java 28 Nov 2002 21:22:13 -0000 1.14
@@ -55,11 +55,11 @@
*/
import org.apache.ojb.broker.ManageableCollection;
-import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PBKey;
+import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.accesslayer.ConnectionFactory;
import org.apache.ojb.broker.accesslayer.ConnectionFactoryConfiguration;
-import org.apache.ojb.broker.accesslayer.ConnectionFactoryDefaultImpl;
+import org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl;
import org.apache.ojb.broker.cache.ObjectCache;
import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
@@ -73,13 +73,18 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggingConfiguration;
import org.apache.ojb.broker.util.logging.PoorMansLoggerImpl;
-import org.apache.ojb.broker.util.pooling.PoolInfo;
+import org.apache.ojb.broker.util.pooling.PoolConfiguration;
import org.apache.ojb.broker.util.sequence.SequenceConfiguration;
import org.apache.ojb.broker.util.sequence.SequenceManager;
import org.apache.ojb.broker.util.sequence.SequenceManagerHiLoImpl;
import org.apache.ojb.odmg.OdmgConfiguration;
import org.apache.ojb.odmg.collections.DListImpl;
-import org.apache.ojb.odmg.locking.*;
+import org.apache.ojb.odmg.locking.AbstractLockStrategy;
+import org.apache.ojb.odmg.locking.LockManager;
+import org.apache.ojb.odmg.locking.LockManagerDefaultImpl;
+import org.apache.ojb.odmg.locking.LockMap;
+import org.apache.ojb.odmg.locking.LockingConfiguration;
+import org.apache.ojb.odmg.locking.PersistentLockMapImpl;
/**
* This class contains the runtime configuration of the OJB
@@ -108,8 +113,8 @@
private String loggerConfigFile;
private Class persistenceBrokerClass;
// limit for number of values in SQL IN Statement
- private int sqlInLimit;
-
+ private int sqlInLimit;
+
// sequence manager
private int sequenceManagerGrabSize;
private Class sequenceManagerClass;
@@ -165,10 +170,9 @@
}
public String getLogLevel(String loggerName)
- {
- return this.getString(loggerName + ".LogLevel", "INFO");
- }
-
+ {
+ return this.getString(loggerName + ".LogLevel", "INFO");
+ }
//*************************************************************
@@ -237,6 +241,7 @@
{
return sequenceManagerRepository.equalsIgnoreCase(NULL) ? null : new PBKey(sequenceManagerRepository);
}
+
private static final String NULL = "null";
public boolean getSequenceManagerGlobalId()
@@ -248,6 +253,7 @@
{
return sequenceManagerGrabSize;
}
+
//*************************************************************
public Class getObjectCacheClass()
@@ -315,14 +321,14 @@
sequenceManagerGlobalId = getBoolean("SequenceManagerGlobalIDs", false);
- sequenceManagerRepository= getString("SequenceManagerRepository", NULL);
+ sequenceManagerRepository = getString("SequenceManagerRepository", NULL);
// load ObjectCache Class
objectCacheClass = getClass("ObjectCacheClass", ObjectCacheDefaultImpl.class, ObjectCache.class);
// load ConnectionFactory Class
connectionFactoryClass =
- getClass("ConnectionFactoryClass", ConnectionFactoryDefaultImpl.class, ConnectionFactory.class);
+ getClass("ConnectionFactoryClass", ConnectionFactoryPooledImpl.class, ConnectionFactory.class);
// load LockManager Class
lockManagerClass = getClass("LockManagerClass", LockManagerDefaultImpl.class, LockManager.class);
@@ -370,12 +376,18 @@
sqlInLimit = getInteger("SqlInLimit", -1);
//load configuration for PB pool
- maxActive = getInteger("maxActive", PoolInfo.DEFAULT_MAX_ACTIVE);
- maxIdle = getInteger("maxIdle", PoolInfo.DEFAULT_MAX_IDLE);
- maxWait = getLong("maxWait", PoolInfo.DEFAULT_MAX_WAIT);
- timeBetweenEvictionRunsMillis = getLong("timeBetweenEvictionRunsMillis", PoolInfo.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
- minEvictableIdleTimeMillis = getLong("minEvictableIdleTimeMillis", PoolInfo.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
- whenExhaustedAction = getByte("whenExhaustedAction", PoolInfo.DEFAULT_WHEN_EXHAUSTED_ACTION);
+ maxActive = getInteger(PoolConfiguration.MAX_ACTIVE,
+ PoolConfiguration.DEFAULT_MAX_ACTIVE);
+ maxIdle = getInteger(PoolConfiguration.MAX_IDLE,
+ PoolConfiguration.DEFAULT_MAX_IDLE);
+ maxWait = getLong(PoolConfiguration.MAX_WAIT,
+ PoolConfiguration.DEFAULT_MAX_WAIT);
+ timeBetweenEvictionRunsMillis = getLong(PoolConfiguration.TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ PoolConfiguration.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
+ minEvictableIdleTimeMillis = getLong(PoolConfiguration.MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ PoolConfiguration.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+ whenExhaustedAction = getByte(PoolConfiguration.WHEN_EXHAUSTED_ACTION,
+ PoolConfiguration.DEFAULT_WHEN_EXHAUSTED_ACTION);
//load configuration for connection pools
con_maxActive = getInteger("maxConnectionsInPool", 10);
@@ -399,12 +411,12 @@
this.persistentFieldClass = persistentFieldClass;
}
- /**
- * @see org.apache.ojb.odmg.OdmgConfiguration#useImplicitLocking()
- */
- public boolean useImplicitLocking()
- {
- return useImplicitLocking;
- }
+ /**
+ * @see org.apache.ojb.odmg.OdmgConfiguration#useImplicitLocking()
+ */
+ public boolean useImplicitLocking()
+ {
+ return useImplicitLocking;
+ }
}
1.4 +94 -92 jakarta-ojb/src/java/org/apache/ojb/broker/util/factory/ConfigurableFactory.java
Index: ConfigurableFactory.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/factory/ConfigurableFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurableFactory.java 8 Nov 2002 16:11:19 -0000 1.3
+++ ConfigurableFactory.java 28 Nov 2002 21:22:13 -0000 1.4
@@ -53,6 +53,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
+
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.PersistenceBrokerFactory;
import org.apache.ojb.broker.util.configuration.Configurable;
@@ -70,100 +71,101 @@
* by the derived factory.
* The lookup is performed in the configure() method and uses the OJB.properties
* information.
- *
+ *
* @author Thomas Mahler
*/
public abstract class ConfigurableFactory implements Configurable
-{
- /**
- * the class to be served
- */
- private Class classToServe = null;
-
- /**
- * the public constructor calls configure() to perform configuration
- * of the factory instance.
- */
- public ConfigurableFactory()
- {
- PersistenceBrokerFactory.getConfigurator().configure(this);
- }
-
- /**
- * the factory method for creating new instances
- * the Class to be instantiated is defined by getClassToServe().
- * @return Object the created instance
- */
- public Object createNewInstance()
- {
- Logger logger = getLogger();
- // class to serve is set in configure()!
- Class clazz = getClassToServe();
- logger.info("ConfigurableFactory called to serve a " + clazz + " instance");
- try
- {
- // create an instance of the target class
- Object result = clazz.newInstance();
-
- // if defined in OJB.properties all instances are wrapped by an interceptor
- result = InterceptorFactory.getInstance().createInterceptorFor(result);
- return result;
- }
- catch (InstantiationException e)
- {
- logger.error("ConfigurableFactory can't instantiate " + clazz, e);
- throw new PersistenceBrokerException(e);
- }
- catch (IllegalAccessException e)
- {
- logger.error("ConfigurableFactory can't access default constructor for " + clazz, e);
- throw new PersistenceBrokerException(e);
- }
- }
-
- /**
- * Returns the classToServe.
- * @return Class
- */
- protected Class getClassToServe()
- {
- return classToServe;
- }
-
- /**
- * Sets the classToServe.
- * @param classToServe The classToServe to set
- */
- protected void setClassToServe(Class classToServe)
- {
- this.classToServe = classToServe;
- }
-
- /**
- * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
- * looks up the the key getConfigurationKey() in the OjbConfiguration
- * to determine the Class to be served.
- */
- public void configure(Configuration pConfig) throws ConfigurationException
- {
- Class clazz = pConfig.getClass(getConfigurationKey(), null);
- this.setClassToServe(clazz);
- }
-
-
- /**
- * must be implemented in the concrete factory classes.
- * the configuration key is used to lookup the Class to serve
- * from the OjbConfiguration in configure().
- */
- protected abstract String getConfigurationKey();
-
- /**
- * the logger for the ConfigurableFactory
- */
- protected Logger getLogger()
- {
- return LoggerFactory.getLogger(this.getClass().getName());
- }
+{
+ /**
+ * the class to be served
+ */
+ private Class classToServe = null;
+
+ /**
+ * the public constructor calls configure() to perform configuration
+ * of the factory instance.
+ */
+ public ConfigurableFactory()
+ {
+ PersistenceBrokerFactory.getConfigurator().configure(this);
+ }
+
+ /**
+ * the factory method for creating new instances
+ * the Class to be instantiated is defined by getClassToServe().
+ * @return Object the created instance
+ */
+ public Object createNewInstance()
+ {
+ Logger logger = getLogger();
+ // class to serve is set in configure()!
+ Class clazz = getClassToServe();
+ // only debug, to reduce logging statements
+ if (logger.isDebugEnabled()) logger.debug("ConfigurableFactory called to serve a " + clazz + " instance");
+ try
+ {
+ // create an instance of the target class
+ Object result = clazz.newInstance();
+
+ // if defined in OJB.properties all instances are wrapped by an interceptor
+ result = InterceptorFactory.getInstance().createInterceptorFor(result);
+ return result;
+ }
+ catch (InstantiationException e)
+ {
+ logger.error("ConfigurableFactory can't instantiate " + clazz, e);
+ throw new PersistenceBrokerException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ logger.error("ConfigurableFactory can't access default constructor for " + clazz, e);
+ throw new PersistenceBrokerException(e);
+ }
+ }
+
+ /**
+ * Returns the classToServe.
+ * @return Class
+ */
+ protected Class getClassToServe()
+ {
+ return classToServe;
+ }
+
+ /**
+ * Sets the classToServe.
+ * @param classToServe The classToServe to set
+ */
+ protected void setClassToServe(Class classToServe)
+ {
+ this.classToServe = classToServe;
+ }
+
+ /**
+ * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
+ * looks up the the key getConfigurationKey() in the OjbConfiguration
+ * to determine the Class to be served.
+ */
+ public void configure(Configuration pConfig) throws ConfigurationException
+ {
+ Class clazz = pConfig.getClass(getConfigurationKey(), null);
+ this.setClassToServe(clazz);
+ }
+
+
+ /**
+ * must be implemented in the concrete factory classes.
+ * the configuration key is used to lookup the Class to serve
+ * from the OjbConfiguration in configure().
+ */
+ protected abstract String getConfigurationKey();
+
+ /**
+ * the logger for the ConfigurableFactory
+ */
+ protected Logger getLogger()
+ {
+ return LoggerFactory.getLogger(this.getClass().getName());
+ }
}
1.12 +16 -6 jakarta-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceGenerator.java
Index: SequenceGenerator.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceGenerator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SequenceGenerator.java 22 Nov 2002 00:13:59 -0000 1.11
+++ SequenceGenerator.java 28 Nov 2002 21:22:13 -0000 1.12
@@ -1,11 +1,13 @@
package org.apache.ojb.broker.util.sequence;
-import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PBFactoryException;
import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -47,9 +49,12 @@
// sequence table
broker_seq = getBrokerForSequenceOperations(keyToSeparateSeqTable);
+ Criteria c = new Criteria();
+ c.addLike("tableName", targetSequence.getTableName());
+ c.addLike("fieldName", targetSequence.getFieldName());
+ Query q = new QueryByCriteria(targetSequence.getClass(), c);
broker_seq.beginTransaction();
- Identity targetSequenceOid = new Identity(targetSequence, broker_seq);
- newSequence = (HighLowSequence) broker_seq.getObjectByIdentity(targetSequenceOid);
+ newSequence = (HighLowSequence) broker_seq.getObjectByQuery(q);
broker_seq.commitTransaction();
@@ -62,7 +67,12 @@
}
newSequence = targetSequence;
}
-
+ // if given maxKey greater that the stored in DB
+ // we use the greater one
+ if (targetSequence.getMaxKey() > newSequence.getMaxKey())
+ {
+ newSequence.setMaxKey(targetSequence.getMaxKey());
+ }
//set current grab size
newSequence.setGrabSize(targetSequence.getGrabSize());
//use copy to avoid sync problems!!
@@ -95,7 +105,7 @@
* @see #getNextSequence(PersistenceBroker brokerForClass,Class clazz, HighLowSequence targetSequence,PBKey keyForSequenceOperations)
*/
public synchronized static HighLowSequence getNextSequence(PersistenceBroker brokerForClass,
- HighLowSequence targetSequence)
+ HighLowSequence targetSequence)
{
return getNextSequence(brokerForClass, targetSequence, null);
}
1.4 +20 -5 jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling/ByPassConnection.java
Index: ByPassConnection.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling/ByPassConnection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ByPassConnection.java 30 Sep 2002 16:55:37 -0000 1.3
+++ ByPassConnection.java 28 Nov 2002 21:22:13 -0000 1.4
@@ -2,7 +2,6 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.broker.accesslayer.ConnectionManager;
import java.sql.Connection;
import java.sql.SQLException;
@@ -23,7 +22,19 @@
}
/**
- * this was a no-op
+ * a no-op
+ */
+ public void setAutoCommit(boolean autoCommit) throws SQLException
+ {
+ /*
+ we ignore this. in managed environments it is not
+ allowed to change autoCommit state
+ */
+ if (log.isDebugEnabled()) log.debug("** we ignore setAutoCommit");
+ }
+
+ /**
+ * a no-op
*/
public void commit() throws SQLException
{
@@ -32,18 +43,22 @@
e.g. the J2EE environment for us, when using
declarative or programmatic transaction in a j2ee container
*/
- if(log.isDebugEnabled()) log.debug("** we ignore commit");
+ if (log.isDebugEnabled()) log.debug("** we ignore commit");
}
+ /**
+ * close the wrapped connection
+ */
public void close() throws SQLException
{
- ConnectionManager.CONN_COUNT--;
super.close();
}
+ /**
+ * rollback the wrapped connection
+ */
public void rollback() throws SQLException
{
- if(log.isDebugEnabled()) log.debug("** rollback was called");
super.rollback();
}
}
1.1 jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java
Index: PoolConfiguration.java
===================================================================
package org.apache.ojb.broker.util.pooling;
/*
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import java.io.Serializable;
import java.util.Properties;
/**
* Encapsulates configuration properties for
* implementations using {@link org.apache.commons.pool.ObjectPool}.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id: PoolConfiguration.java,v 1.1 2002/11/28 21:22:13 arminw Exp $
*/
public class PoolConfiguration extends Properties implements Serializable //, Configurable
{
public static final String EMPTY = "";
public static final String MAX_ACTIVE = "maxActive";
public static final String MAX_IDLE = "maxIdle";
public static final String MAX_WAIT = "maxWait";
public static final String WHEN_EXHAUSTED_ACTION = "whenExhaustedAction";
public static final String TEST_ON_BORROW = "testOnBorrow";
public static final String TEST_ON_RETURN = "testOnReturn";
public static final String TEST_WHILE_IDLE = "testWhileIdle";
public static final String TIME_BETWEEN_EVICTION_RUNS_MILLIS = "timeBetweenEvictionRunsMillis";
public static final String NUM_TESTS_PER_EVICTION_RUN = "numTestsPerEvictionRun";
public static final String MIN_EVICTABLE_IDLE_TIME_MILLIS = "minEvictableIdleIimeMillis";
public static int DEFAULT_MAX_ACTIVE = 15;
public static int DEFAULT_MAX_IDLE = -1;
public static long DEFAULT_MAX_WAIT = 5000;
public static byte DEFAULT_WHEN_EXHAUSTED_ACTION = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
public static boolean DEFAULT_TEST_ON_BORROW = true;
public static boolean DEFAULT_TEST_ON_RETURN = true;
public static boolean DEFAULT_TEST_WHILE_IDLE = true;
public static long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
public static int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 10;
public static long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000 * 60 * 10;
public PoolConfiguration()
{
this.setMaxActive(DEFAULT_MAX_ACTIVE);
this.setMaxIdle(DEFAULT_MAX_IDLE);
this.setMaxWait(DEFAULT_MAX_WAIT);
this.setWhenExhaustedAction(DEFAULT_WHEN_EXHAUSTED_ACTION);
this.setTestOnBorrow(DEFAULT_TEST_ON_BORROW);
this.setTestOnReturn(DEFAULT_TEST_ON_RETURN);
this.setTestWhileIdle(DEFAULT_TEST_WHILE_IDLE);
this.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
this.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
this.setNumTestsPerEvictionRun(DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
}
public PoolConfiguration(Properties properties)
{
this();
this.putAll(properties);
}
/**
* Returns an {@link org.apache.commons.pool.impl.GenericObjectPool.Config} object
* configurated with the properties extracted from the this instance.
* Use this to configurate a pool implementation using
* {@link org.apache.commons.pool.impl.GenericObjectPool}.
*/
public GenericObjectPool.Config getObjectPoolConfig()
{
GenericObjectPool.Config conf = new GenericObjectPool.Config();
conf.maxActive = getMaxActive();
conf.maxIdle = getMaxIdle();
conf.maxWait = getMaxWait();
conf.minEvictableIdleTimeMillis = getMinEvictableIdleTimeMillis();
conf.numTestsPerEvictionRun = getNumTestsPerEvictionRun();
conf.testOnBorrow = isTestOnBorrow();
conf.testOnReturn = isTestOnReturn();
conf.testWhileIdle = isTestWhileIdle();
conf.timeBetweenEvictionRunsMillis = getTimeBetweenEvictionRunsMillis();
conf.whenExhaustedAction = getWhenExhaustedAction();
return conf;
}
/**
* Returns an {@link org.apache.commons.pool.impl.GenericKeyedObjectPool.Config} object
* configurated with the properties extracted from the this instance.
* Use this to configurate a pool implementation using
* {@link org.apache.commons.pool.impl.GenericKeyedObjectPool}.
*/
public GenericKeyedObjectPool.Config getKeyedObjectPoolConfig()
{
GenericKeyedObjectPool.Config conf = new GenericKeyedObjectPool.Config();
conf.maxActive = getMaxActive();
conf.maxIdle = getMaxIdle();
conf.maxWait = getMaxWait();
conf.minEvictableIdleTimeMillis = getMinEvictableIdleTimeMillis();
conf.numTestsPerEvictionRun = getNumTestsPerEvictionRun();
conf.testOnBorrow = isTestOnBorrow();
conf.testOnReturn = isTestOnReturn();
conf.testWhileIdle = isTestWhileIdle();
conf.timeBetweenEvictionRunsMillis = getTimeBetweenEvictionRunsMillis();
conf.whenExhaustedAction = getWhenExhaustedAction();
return conf;
}
public int getMaxActive()
{
return new Integer(getProperty(MAX_ACTIVE)).intValue();
}
public void setMaxActive(int maxActive)
{
if (maxActive > 0)
{
this.setProperty(MAX_ACTIVE, EMPTY + maxActive);
}
else
{
LoggerFactory.getDefaultLogger().error("Size for connection pool must > 0. Value was " + maxActive);
}
}
public int getMaxIdle()
{
return new Integer(getProperty(MAX_IDLE)).intValue();
}
public void setMaxIdle(int maxIdle)
{
this.setProperty(MAX_IDLE, EMPTY + maxIdle);
}
public long getMaxWait()
{
return new Long(getProperty(MAX_WAIT)).longValue();
}
public void setMaxWait(long maxWait)
{
this.setProperty(MAX_WAIT, EMPTY + maxWait);
}
public byte getWhenExhaustedAction()
{
return new Byte(getProperty(WHEN_EXHAUSTED_ACTION)).byteValue();
}
public void setWhenExhaustedAction(byte whenExhaustedAction)
{
this.setProperty(WHEN_EXHAUSTED_ACTION, EMPTY + whenExhaustedAction);
}
public boolean isTestOnBorrow()
{
return new Boolean(getProperty(TEST_ON_BORROW)).booleanValue();
}
public void setTestOnBorrow(boolean testOnBorrow)
{
this.setProperty(TEST_ON_BORROW, EMPTY + testOnBorrow);
}
public boolean isTestOnReturn()
{
return new Boolean(getProperty(TEST_ON_RETURN)).booleanValue();
}
public void setTestOnReturn(boolean testOnReturn)
{
this.setProperty(TEST_ON_RETURN, EMPTY + testOnReturn);
}
public boolean isTestWhileIdle()
{
return new Boolean(getProperty(TEST_WHILE_IDLE)).booleanValue();
}
public void setTestWhileIdle(boolean testWhileIdle)
{
this.setProperty(TEST_WHILE_IDLE, EMPTY + testWhileIdle);
}
public long getMinEvictableIdleTimeMillis()
{
return new Long(getProperty(MIN_EVICTABLE_IDLE_TIME_MILLIS)).longValue();
}
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
{
this.setProperty(MIN_EVICTABLE_IDLE_TIME_MILLIS, EMPTY + minEvictableIdleTimeMillis);
}
public long getTimeBetweenEvictionRunsMillis()
{
return new Long(getProperty(TIME_BETWEEN_EVICTION_RUNS_MILLIS)).longValue();
}
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
{
this.setProperty(TIME_BETWEEN_EVICTION_RUNS_MILLIS, EMPTY + timeBetweenEvictionRunsMillis);
}
public int getNumTestsPerEvictionRun()
{
return new Integer(getProperty(NUM_TESTS_PER_EVICTION_RUN)).intValue();
}
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
{
this.setProperty(NUM_TESTS_PER_EVICTION_RUN, EMPTY + numTestsPerEvictionRun);
}
}