org.opensubsystems.core.persist.db.connectionpool
Class PooledDatabaseConnectionFactorySetupReader

java.lang.Object
  extended by org.opensubsystems.core.util.SetupReader
      extended by org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactorySetupReader

public class PooledDatabaseConnectionFactorySetupReader
extends SetupReader

Class that reads setup for database connection pools from properties. Each pool have unique name. For this name class will find all properties for name or wil use default values if property with name is not present. The DBCP configuration is available at http://jakarta.apache.org/commons/dbcp/configuration.html The XAPool configuration is available at file:///e:/Development/OpenSubsystems/external/xapool/jdoc/index.html see classes StandardXADataSource, StandardXAPoolDataSource The C3P0 configuration is available at http://www.mchange.com/projects/c3p0/index.html#appendix_a The Proxool configuraion is available at http://proxool.sourceforge.net/properties.html

Version:
$Id: PooledDatabaseConnectionFactorySetupReader.java,v 1.6 2007/01/07 06:14:58 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.2 2006/04/27 13:31:23 bastafidli

Field Summary
static java.lang.String DATABASE_POOL_BASE_PATH
          base path for all properties
static java.lang.String DBPOOL_CAN_GROW
          Can the connection pool grow above maximal size or should it block.
static boolean DBPOOL_CAN_GROW_DEFAULT
          Can the connection pool grow above maximal size or should it block.
static java.lang.String DBPOOL_CHECK_LEVEL
          How thoroughly to validate the objects in the pool.
static int DBPOOL_CHECK_LEVEL_DEFAULT
          How thoroughly to validate the objects in the pool.
static java.lang.String DBPOOL_IDLE_CHECK_PERIOD
          How often to validate idle connections.
static long DBPOOL_IDLE_CHECK_PERIOD_DEFAULT
          How often to validate idle connections.
static java.lang.String DBPOOL_IDLE_CHECK_SIZE
          How many of the idle connections to test during one test run.
static int DBPOOL_IDLE_CHECK_SIZE_DEFAULT
          How much of the idle connections to test during one test run.
static java.lang.String DBPOOL_IDLE_PERIOD
          How long can connection sit in the pool before it is considered idle.
static long DBPOOL_IDLE_PERIOD_DEFAULT
          How long can connection sit in the pool before it is considered idle.
static java.lang.String DBPOOL_INITIAL_SIZE
          Initial size of the connection pool.
static int DBPOOL_INITIAL_SIZE_DEFAULT
          Initial size of the connection pool.
static java.lang.String DBPOOL_MAX_SIZE
          Maximal size of the connection pool.
static int DBPOOL_MAX_SIZE_DEFAULT
          Maximal size of the connection pool.
static java.lang.String DBPOOL_MIN_SIZE
          Minimal size of the connection pool.
static int DBPOOL_MIN_SIZE_DEFAULT
          Minimal size of the connection pool.
static java.lang.String DBPOOL_PREPSTATEMENT_CACHE_SIZE
          Should the connection pool cache prepared statements and if so how many.
static int DBPOOL_PREPSTATEMENT_CACHE_SIZE_DEFAULT
          Should the connection pool cache prepared statements and if so how many.
static java.lang.String DBPOOL_RETRY_COUNT
          If getting connection from the pool fails (e.g.
static long DBPOOL_RETRY_COUNT_DEFAULT
          If getting connection from the pool fails (e.g.
static java.lang.String DBPOOL_RETRY_PERIOD
          If getting connection from the pool fails (e.g.
static long DBPOOL_RETRY_PERIOD_DEFAULT
          If getting connection from the pool fails (e.g.
static java.lang.String DBPOOL_TRANSACTION_ISOLATION
          Default transaction isolation level.
static java.lang.String DBPOOL_TRANSACTION_ISOLATION_DEFAULT
          Default transaction isolation level.
static java.lang.String DBPOOL_VALIDATE_BORROW
          Should the pool validate connection immmediately before it is borrowed from the pool.
static boolean DBPOOL_VALIDATE_BORROW_DEFAULT
          Should the pool validate connection immmediately before it is borrowed from the pool.
static java.lang.String DBPOOL_VALIDATE_IDLE
          Should the pool validate connection when it is idle.
static boolean DBPOOL_VALIDATE_IDLE_DEFAULT
          Should the pool validate connection when it is idle.
static java.lang.String DBPOOL_VALIDATE_RETURN
          Should the pool validate connection when it is returned to the pool.
static boolean DBPOOL_VALIDATE_RETURN_DEFAULT
          Should the pool validate connection when it is returned to the pool.
static java.lang.String DBPOOL_WAIT_PERIOD
          If the pool should block when it reaches maximal size, how long can wait at most for a connection.
static long DBPOOL_WAIT_PERIOD_DEFAULT
          If the pool should block when it reaches maximal size, how long can wait at most for connection.
protected static java.util.Map s_registeredParametersDefaults
          Map with all registered paremeters names (as key) and default values (as String value) This map is common for all instances of class
protected static java.util.Map s_registeredParametersTypes
          Map with all registered paremeters names (as key) and types (as Integer value) This map is common for all instances of class
 
Fields inherited from class org.opensubsystems.core.util.SetupReader
m_basePath, m_readerName, m_registeredParametersValues, m_settings, PARAMETER_TYPE_BOOLEAN, PARAMETER_TYPE_BOOLEAN_OBJ, PARAMETER_TYPE_DOUBLE, PARAMETER_TYPE_DOUBLE_OBJ, PARAMETER_TYPE_FLOAT, PARAMETER_TYPE_FLOAT_OBJ, PARAMETER_TYPE_INTEGER, PARAMETER_TYPE_INTEGER_OBJ, PARAMETER_TYPE_LONG, PARAMETER_TYPE_LONG_OBJ, PARAMETER_TYPE_PATH, PARAMETER_TYPE_PATH_OBJ, PARAMETER_TYPE_STRING, PARAMETER_TYPE_STRING_OBJ, PARAMETER_TYPE_UNKNOWN, PARAMETER_TYPE_UNKNOWN_OBJ
 
Constructor Summary
PooledDatabaseConnectionFactorySetupReader(java.lang.String readerName)
           
 
Method Summary
static int convertTransactionIsolationToConstant(java.lang.String strTransactionIsolation)
          Translate transaction isolation setting to a Connection.TRANSACTION_XXX constant.
protected  java.util.Map getRegisteredParametersDefaults()
          this function returns Map for parameter defaults.
protected  java.util.Map getRegisteredParameterTypes()
          this function returns Map for parameter types.
protected  void registerParameters()
          Implementation can register all parameters in this function.
 
Methods inherited from class org.opensubsystems.core.util.SetupReader
getBooleanParameterValue, getDoubleParameterValue, getFloatParameterValue, getIntegerParameterValue, getLongParameterValue, getParameterValue, getStringParameterValue, parseValue, registerParameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_POOL_BASE_PATH

public static final java.lang.String DATABASE_POOL_BASE_PATH
base path for all properties

See Also:
Constant Field Values

DBPOOL_INITIAL_SIZE

public static final java.lang.String DBPOOL_INITIAL_SIZE
Initial size of the connection pool. How many connections are created in the pool when the pool is started. Connection pool specific terminology: DBCP: initialSize - if 0 - no initial connections created XAPool: StandardXAPoolDataSource(iInitialPoolSize) C3P0: initialPoolSize Proxool: No support

See Also:
Constant Field Values

DBPOOL_MIN_SIZE

public static final java.lang.String DBPOOL_MIN_SIZE
Minimal size of the connection pool. Number of connections in the pool should not fall under this threshold regardless if they are used or not. This is not the same as the initial/optimal size. Connection pool specific terminology: DBCP: minIdle - if 0 - pool can become empty XAPool: StandardXAPoolDataSource.setMinSize C3P0: minPoolSize Proxool: minimum-connection-count

See Also:
Constant Field Values

DBPOOL_MAX_SIZE

public static final java.lang.String DBPOOL_MAX_SIZE
Maximal size of the connection pool. How many connections can be taken out of the pool or can exist in the pool idle. Connection pool specific terminology: DBCP: maxActive, maxIdle - if 0 - no limit XAPool: StandardXAPoolDataSource.setMaxSize C3P0: maxPoolSize Proxool: maximum-connection-count

See Also:
Constant Field Values

DBPOOL_CAN_GROW

public static final java.lang.String DBPOOL_CAN_GROW
Can the connection pool grow above maximal size or should it block. This can be useful if we want to have soft max limit but still allow to satisfy request when load increases and then maybe in the future readjust the settings. If we do not allow growing, then the caller will be blocked until connection becomes available. Connection pool specific terminology: DBCP: GenericObjectPool(...whenExhaustedAction...) XAPool: No support C3P0: No support Proxool: No support

See Also:
Constant Field Values

DBPOOL_WAIT_PERIOD

public static final java.lang.String DBPOOL_WAIT_PERIOD
If the pool should block when it reaches maximal size, how long can wait at most for a connection. Time is in miliseconds. Connection pool specific terminology: DBCP: maxWait - if -1 - wait indefinitely XAPool: StandardXAPoolDataSource.setDeadLockMaxWait C3P0: checkoutTimeout - if 0 - wait indefinitely Proxool: No support

See Also:
Constant Field Values

DBPOOL_RETRY_PERIOD

public static final java.lang.String DBPOOL_RETRY_PERIOD
If getting connection from the pool fails (e.g. in case of C3P0 even for some other reason than the pool is exhaused, such as temporary database outage) how long to wait until the pool tries to acquire another connection. Time is in miliseconds. Connection pool specific terminology: DBCP: No support XAPool: StandardXAPoolDataSource.setDeadLockRetryWait C3P0: acquireRetryDelay Proxool: No support

See Also:
Constant Field Values

DBPOOL_RETRY_COUNT

public static final java.lang.String DBPOOL_RETRY_COUNT
If getting connection from the pool fails (e.g. in case of C3P0 even for some other reason than the pool is exhaused, such as temporary database outage) how many times to try to acquire another connection. Connection pool specific terminology: DBCP: No support XAPool: No support C3P0: acquireRetryAttempts - if less or equal to 0 - try indefinitely Proxool: No support

See Also:
Constant Field Values

DBPOOL_VALIDATE_BORROW

public static final java.lang.String DBPOOL_VALIDATE_BORROW
Should the pool validate connection immmediately before it is borrowed from the pool. This is quite expensive to do by default and often it is better to let pool check on idle connection if such option is available. Connection pool specific terminology: DBCP: testOnBorrow XAPool: No support C3P0: testConnectionOnCheckout Proxool: test-before-use

See Also:
Constant Field Values

DBPOOL_VALIDATE_RETURN

public static final java.lang.String DBPOOL_VALIDATE_RETURN
Should the pool validate connection when it is returned to the pool. Connection pool specific terminology: DBCP: testOnReturn XAPool: No support C3P0: testConnectionOnCheckin Proxool: test-after-use

See Also:
Constant Field Values

DBPOOL_VALIDATE_IDLE

public static final java.lang.String DBPOOL_VALIDATE_IDLE
Should the pool validate connection when it is idle. This is the most efficient way of conection testing and if you do decide to test connections you may consider doing so while they are idle. Connection pool specific terminology: DBCP: testWhileIdle XAPool: No support C3P0: just set value for idleConnectionTestPeriod Proxool: Just set value for idlecheckperiod

See Also:
Constant Field Values

DBPOOL_CHECK_LEVEL

public static final java.lang.String DBPOOL_CHECK_LEVEL
How thoroughly to validate the objects in the pool. Since this is the only way provided by XAPool to configure connection testing, we provide this attribute, even though it has no meaning for other pools. Connection pool specific terminology: DBCP: No support XAPool: StandardXAPoolDataSource.setCheckLevelObject C3P0: No support Proxool: No support From XAPool JavaDoc: 0 = no special checking 1 = just a check on an object 2 = test the object 3 = just a check on an object (for all the objects) 4 = test the object (for all the objects)

See Also:
Constant Field Values

DBPOOL_IDLE_CHECK_PERIOD

public static final java.lang.String DBPOOL_IDLE_CHECK_PERIOD
How often to validate idle connections. Validating idles connections is the most efficient way of validating connections since it doesn't affect requesting of returning of connections and therefore performance of the application. Time is in miliseconds (even though some pools expect it in seconds, it will be converted from milliseconds as needed). Alternative is to set idlechecksize if the connection pool supports it. Connection pool specific terminology: DBCP: timeBetweenEvictionRunsMillis - if less or equal to 0 - do not check XAPool: No support C3P0: idleConnectionTestPeriod - if less or equal to 0 - do not check Proxool: house-keeping-sleep-time

See Also:
Constant Field Values

DBPOOL_IDLE_CHECK_SIZE

public static final java.lang.String DBPOOL_IDLE_CHECK_SIZE
How many of the idle connections to test during one test run. This is an alternative of idlecheckperiod. Connection pool specific terminology: DBCP: numTestsPerEvictionRun XAPool: No support C3P0: No support Proxool: No support

See Also:
Constant Field Values

DBPOOL_IDLE_PERIOD

public static final java.lang.String DBPOOL_IDLE_PERIOD
How long can connection sit in the pool before it is considered idle. Time is in miliseconds (even though some pools expect it in seconds, it will be converted from milliseconds as needed). Connection pool specific terminology: DBCP: minEvictableIdleTimeMillis XAPool: No support C3P0: maxIdleTime - 0 means connections will never expire Proxool: No support

See Also:
Constant Field Values

DBPOOL_TRANSACTION_ISOLATION

public static final java.lang.String DBPOOL_TRANSACTION_ISOLATION
Default transaction isolation level. Settings are commited, uncommited, repeatable, serializable. Connection pool specific terminology: DBCP: defaultTransactionIsolation XAPool: StandardXADataSource.setTransactionIsolation C3P0: No support Proxool: No support

See Also:
Constant Field Values

DBPOOL_PREPSTATEMENT_CACHE_SIZE

public static final java.lang.String DBPOOL_PREPSTATEMENT_CACHE_SIZE
Should the connection pool cache prepared statements and if so how many. Connection pool specific terminology: DBCP: maxOpenPreparedStatements - if 0 - cache and do not impose any limit - if less than 0 - do no cache XAPool: StandardXADataSource.setPreparedStmtCacheSize - if less or equal to 0 - do not cache C3P0: maxStatements - if less or equal to 0 - do not cache Proxool: No support

See Also:
Constant Field Values

DBPOOL_INITIAL_SIZE_DEFAULT

public static final int DBPOOL_INITIAL_SIZE_DEFAULT
Initial size of the connection pool. Make this 0 since if the database doesn't exist or is not started we do not want to create unnecessary error conditions due to creation of initial connections.

See Also:
Constant Field Values

DBPOOL_MIN_SIZE_DEFAULT

public static final int DBPOOL_MIN_SIZE_DEFAULT
Minimal size of the connection pool. Make this 0 since if the database doesn't exist or is not started we do not want to create unnecessary error conditions due to creation of initial connections.

See Also:
Constant Field Values

DBPOOL_MAX_SIZE_DEFAULT

public static final int DBPOOL_MAX_SIZE_DEFAULT
Maximal size of the connection pool. This is reasonable amount for most not high volume applications.

See Also:
Constant Field Values

DBPOOL_CAN_GROW_DEFAULT

public static final boolean DBPOOL_CAN_GROW_DEFAULT
Can the connection pool grow above maximal size or should it block.

See Also:
Constant Field Values

DBPOOL_WAIT_PERIOD_DEFAULT

public static final long DBPOOL_WAIT_PERIOD_DEFAULT
If the pool should block when it reaches maximal size, how long can wait at most for connection.

See Also:
Constant Field Values

DBPOOL_RETRY_PERIOD_DEFAULT

public static final long DBPOOL_RETRY_PERIOD_DEFAULT
If getting connection from the pool fails (e.g. in case of C3P0 even for some other reason than the pool is exhaused, such as temporary database outage) how long to wait until the pool tries to acquire another connection. Time is in miliseconds.

See Also:
Constant Field Values

DBPOOL_RETRY_COUNT_DEFAULT

public static final long DBPOOL_RETRY_COUNT_DEFAULT
If getting connection from the pool fails (e.g. in case of C3P0 even for some other reason than the pool is exhaused, such as temporary database outage) how many times to try to acquire another connection.

See Also:
Constant Field Values

DBPOOL_VALIDATE_BORROW_DEFAULT

public static final boolean DBPOOL_VALIDATE_BORROW_DEFAULT
Should the pool validate connection immmediately before it is borrowed from the pool. This is quite expensive to do by default and often it is better to let pool check on idle connection if such option is available.

See Also:
Constant Field Values

DBPOOL_VALIDATE_RETURN_DEFAULT

public static final boolean DBPOOL_VALIDATE_RETURN_DEFAULT
Should the pool validate connection when it is returned to the pool.

See Also:
Constant Field Values

DBPOOL_VALIDATE_IDLE_DEFAULT

public static final boolean DBPOOL_VALIDATE_IDLE_DEFAULT
Should the pool validate connection when it is idle. This is the most efficient way of conection testing and if you do decide to test connections you may consider doing so while they are idle.

See Also:
Constant Field Values

DBPOOL_CHECK_LEVEL_DEFAULT

public static final int DBPOOL_CHECK_LEVEL_DEFAULT
How thoroughly to validate the objects in the pool. Since this is the only way provided by XAPool to configure connection testing, we provide this attribute, even though it has no meaning for other pools. From XAPool JavaDoc: 0 = no special checking 1 = just a check on an object 2 = test the object 3 = just a check on an object (for all the objects) 4 = test the object (for all the objects)

See Also:
Constant Field Values

DBPOOL_IDLE_CHECK_PERIOD_DEFAULT

public static final long DBPOOL_IDLE_CHECK_PERIOD_DEFAULT
How often to validate idle connections. Validating idles connections is the most efficient way of validating connections since it doesn't affect requesting of returning of connections and therefore performance of the application. Time is in miliseconds (even though some pools expect it in seconds, it will be converted from milliseconds as needed).

See Also:
Constant Field Values

DBPOOL_IDLE_CHECK_SIZE_DEFAULT

public static final int DBPOOL_IDLE_CHECK_SIZE_DEFAULT
How much of the idle connections to test during one test run.

See Also:
Constant Field Values

DBPOOL_IDLE_PERIOD_DEFAULT

public static final long DBPOOL_IDLE_PERIOD_DEFAULT
How long can connection sit in the pool before it is considered idle. Time is in miliseconds (even though some pools expect it in seconds, it will be converted from milliseconds as needed).

See Also:
Constant Field Values

DBPOOL_TRANSACTION_ISOLATION_DEFAULT

public static final java.lang.String DBPOOL_TRANSACTION_ISOLATION_DEFAULT
Default transaction isolation level. Settings are commited, uncommited, repeatable, serializable.

See Also:
Constant Field Values

DBPOOL_PREPSTATEMENT_CACHE_SIZE_DEFAULT

public static final int DBPOOL_PREPSTATEMENT_CACHE_SIZE_DEFAULT
Should the connection pool cache prepared statements and if so how many. In XAPool 1.4.1 0 triggers NullPointerException in XAPool therefore we have patched StandardConnectionHandle.java:145 in 1.4.1 ourselves. This was fixed in subsequent releases of XAPool.

See Also:
Constant Field Values

s_registeredParametersTypes

protected static java.util.Map s_registeredParametersTypes
Map with all registered paremeters names (as key) and types (as Integer value) This map is common for all instances of class


s_registeredParametersDefaults

protected static java.util.Map s_registeredParametersDefaults
Map with all registered paremeters names (as key) and default values (as String value) This map is common for all instances of class

Constructor Detail

PooledDatabaseConnectionFactorySetupReader

public PooledDatabaseConnectionFactorySetupReader(java.lang.String readerName)
Parameters:
readerName - - name of reader Each property name consist from three parts. base path, reader name and parameter name. Property name looks like .. where xxx is base path (for example myapp.receiver) yyy is receiver name (for example defaultfax) and zzz is parameter name (for example priority). result will be myapp.receiver.defaultfax.priority
Method Detail

registerParameters

protected void registerParameters()
Implementation can register all parameters in this function.

Specified by:
registerParameters in class SetupReader

getRegisteredParameterTypes

protected java.util.Map getRegisteredParameterTypes()
this function returns Map for parameter types. This map have to be static. key in map is parameter name and value is Integer type constant

Specified by:
getRegisteredParameterTypes in class SetupReader
Returns:
Map of parameter types

getRegisteredParametersDefaults

protected java.util.Map getRegisteredParametersDefaults()
this function returns Map for parameter defaults. This map have to be static. key in map is parameter name and value is String default value

Specified by:
getRegisteredParametersDefaults in class SetupReader
Returns:
Map of default values

convertTransactionIsolationToConstant

public static int convertTransactionIsolationToConstant(java.lang.String strTransactionIsolation)
Translate transaction isolation setting to a Connection.TRANSACTION_XXX constant.

Parameters:
strTransactionIsolation - - one of the settings to set transaction isolation
Returns:
int


Copyright © 2003 - 2006 OpenSubsystems s.r.o.