Package org.quartz.utils
Class C3p0PoolingConnectionProvider
- java.lang.Object
-
- org.quartz.utils.C3p0PoolingConnectionProvider
-
- All Implemented Interfaces:
ConnectionProvider,PoolingConnectionProvider
public class C3p0PoolingConnectionProvider extends java.lang.Object implements PoolingConnectionProvider
A
ConnectionProviderimplementation that creates its own pool of connections.This class uses C3PO (http://www.mchange.com/projects/c3p0/index.html) as the underlying pool implementation.
- Author:
- Sharada Jambula, James House, Mohammad Rezaei
- See Also:
DBConnectionManager,ConnectionProvider
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDB_DISCARD_IDLE_CONNECTIONS_SECONDSDiscard connections after they have been idle this many seconds.static java.lang.StringDB_IDLE_VALIDATION_SECONDSThe number of seconds between tests of idle connections - only enabled if the validation query property is set.static java.lang.StringDB_MAX_CACHED_STATEMENTS_PER_CONNECTIONThe maximum number of prepared statements that will be cached per connection in the pool.static java.lang.StringDB_VALIDATE_ON_CHECKOUTWhether the database sql query to validate connections should be executed every time a connection is retrieved from the pool to ensure that it is still valid.static intDEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTIONDefault maximum number of database connections in the pool.-
Fields inherited from interface org.quartz.utils.PoolingConnectionProvider
DB_DRIVER, DB_MAX_CONNECTIONS, DB_PASSWORD, DB_URL, DB_USER, DB_VALIDATION_QUERY, DEFAULT_DB_MAX_CONNECTIONS, POOLING_PROVIDER, POOLING_PROVIDER_C3P0, POOLING_PROVIDER_HIKARICP
-
-
Constructor Summary
Constructors Constructor Description C3p0PoolingConnectionProvider(java.lang.String dbDriver, java.lang.String dbURL, java.lang.String dbUser, java.lang.String dbPassword, int maxConnections, java.lang.String dbValidationQuery)C3p0PoolingConnectionProvider(java.util.Properties config)Create a connection pool using the given properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.sql.ConnectiongetConnection()com.mchange.v2.c3p0.ComboPooledDataSourcegetDataSource()Get the C3PO ComboPooledDataSource created during initialization.voidinitialize()voidshutdown()
-
-
-
Field Detail
-
DB_MAX_CACHED_STATEMENTS_PER_CONNECTION
public static final java.lang.String DB_MAX_CACHED_STATEMENTS_PER_CONNECTION
The maximum number of prepared statements that will be cached per connection in the pool. Depending upon your JDBC Driver this may significantly help performance, or may slightly hinder performance. Default is 120, as Quartz uses over 100 unique statements. 0 disables the feature.- See Also:
- Constant Field Values
-
DB_IDLE_VALIDATION_SECONDS
public static final java.lang.String DB_IDLE_VALIDATION_SECONDS
The number of seconds between tests of idle connections - only enabled if the validation query property is set. Default is 50 seconds.- See Also:
- Constant Field Values
-
DB_VALIDATE_ON_CHECKOUT
public static final java.lang.String DB_VALIDATE_ON_CHECKOUT
Whether the database sql query to validate connections should be executed every time a connection is retrieved from the pool to ensure that it is still valid. If false, then validation will occur on check-in. Default is false.- See Also:
- Constant Field Values
-
DB_DISCARD_IDLE_CONNECTIONS_SECONDS
public static final java.lang.String DB_DISCARD_IDLE_CONNECTIONS_SECONDS
Discard connections after they have been idle this many seconds. 0 disables the feature. Default is 0.- See Also:
- Constant Field Values
-
DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION
public static final int DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION
Default maximum number of database connections in the pool.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
C3p0PoolingConnectionProvider
public C3p0PoolingConnectionProvider(java.lang.String dbDriver, java.lang.String dbURL, java.lang.String dbUser, java.lang.String dbPassword, int maxConnections, java.lang.String dbValidationQuery) throws java.sql.SQLException, SchedulerException- Throws:
java.sql.SQLExceptionSchedulerException
-
C3p0PoolingConnectionProvider
public C3p0PoolingConnectionProvider(java.util.Properties config) throws SchedulerException, java.sql.SQLExceptionCreate a connection pool using the given properties.The properties passed should contain:
PoolingConnectionProvider.DB_DRIVER- The database driver class namePoolingConnectionProvider.DB_URL- The database URLPoolingConnectionProvider.DB_USER- The database userPoolingConnectionProvider.DB_PASSWORD- The database passwordPoolingConnectionProvider.DB_MAX_CONNECTIONS- The maximum # connections in the pool, optionalPoolingConnectionProvider.DB_VALIDATION_QUERY- The sql validation query, optional
- Parameters:
config- configuration properties- Throws:
SchedulerExceptionjava.sql.SQLException
-
-
Method Detail
-
getDataSource
public com.mchange.v2.c3p0.ComboPooledDataSource getDataSource()
Get the C3PO ComboPooledDataSource created during initialization.This can be used to set additional data source properties in a subclass's constructor.
- Specified by:
getDataSourcein interfacePoolingConnectionProvider
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnectionin interfaceConnectionProvider- Returns:
- connection managed by this provider
- Throws:
java.sql.SQLException
-
shutdown
public void shutdown() throws java.sql.SQLException- Specified by:
shutdownin interfaceConnectionProvider- Throws:
java.sql.SQLException
-
initialize
public void initialize() throws java.sql.SQLException- Specified by:
initializein interfaceConnectionProvider- Throws:
java.sql.SQLException
-
-