Package org.apache.tomcat.jdbc.pool
Class DataSourceFactory
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.DataSourceFactory
-
- All Implemented Interfaces:
javax.naming.spi.ObjectFactory
public class DataSourceFactory extends java.lang.Object implements javax.naming.spi.ObjectFactory
JNDI object factory that creates an instance of
BasicDataSource
that has been configured based on theRefAddr
values of the specifiedReference
, which must match the names and data types of theBasicDataSource
bean properties.
Properties available for configuration:
Commons DBCP properties
- initSQL - A query that gets executed once, right after the connection is established.
- testOnConnect - run validationQuery after connection has been established.
- validationInterval - avoid excess validation, only run validation at most at this frequency - time in milliseconds.
- jdbcInterceptors - a semicolon separated list of classnames extending
JdbcInterceptor
class. - jmxEnabled - true of false, whether to register the pool with JMX.
- fairQueue - true of false, whether the pool should sacrifice a little bit of performance for true fairness.
- Author:
- Craig R. McClanahan, Dirk Verbeeck
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String[]
ALL_PROPERTIES
static java.lang.String
OBJECT_NAME
protected static java.lang.String
PROP_ABANDONWHENPERCENTAGEFULL
protected static java.lang.String
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
protected static java.lang.String
PROP_ALTERNATE_USERNAME_ALLOWED
protected static java.lang.String
PROP_COMMITONRETURN
protected static java.lang.String
PROP_CONNECTIONPROPERTIES
protected static java.lang.String
PROP_DATASOURCE
protected static java.lang.String
PROP_DATASOURCE_JNDI
protected static java.lang.String
PROP_DEFAULTAUTOCOMMIT
protected static java.lang.String
PROP_DEFAULTCATALOG
protected static java.lang.String
PROP_DEFAULTREADONLY
protected static java.lang.String
PROP_DEFAULTTRANSACTIONISOLATION
protected static java.lang.String
PROP_DRIVERCLASSNAME
protected static java.lang.String
PROP_FAIR_QUEUE
protected static java.lang.String
PROP_IGNOREEXCEPTIONONPRELOAD
protected static java.lang.String
PROP_INITIALSIZE
protected static java.lang.String
PROP_INITSQL
protected static java.lang.String
PROP_INTERCEPTORS
protected static java.lang.String
PROP_JMX_ENABLED
protected static java.lang.String
PROP_LOGABANDONED
protected static java.lang.String
PROP_LOGVALIDATIONERRORS
protected static java.lang.String
PROP_MAXACTIVE
protected static java.lang.String
PROP_MAXAGE
protected static java.lang.String
PROP_MAXIDLE
protected static java.lang.String
PROP_MAXOPENPREPAREDSTATEMENTS
protected static java.lang.String
PROP_MAXWAIT
protected static java.lang.String
PROP_MINEVICTABLEIDLETIMEMILLIS
protected static java.lang.String
PROP_MINIDLE
protected static java.lang.String
PROP_NUMTESTSPEREVICTIONRUN
protected static java.lang.String
PROP_PASSWORD
protected static java.lang.String
PROP_POOLPREPAREDSTATEMENTS
protected static java.lang.String
PROP_PROPAGATEINTERRUPTSTATE
protected static java.lang.String
PROP_REMOVEABANDONED
protected static java.lang.String
PROP_REMOVEABANDONEDTIMEOUT
protected static java.lang.String
PROP_ROLLBACKONRETURN
protected static java.lang.String
PROP_SUSPECT_TIMEOUT
protected static java.lang.String
PROP_TESTONBORROW
protected static java.lang.String
PROP_TESTONCONNECT
protected static java.lang.String
PROP_TESTONRETURN
protected static java.lang.String
PROP_TESTWHILEIDLE
protected static java.lang.String
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
protected static java.lang.String
PROP_URL
protected static java.lang.String
PROP_USE_CON_LOCK
protected static java.lang.String
PROP_USE_EQUALS
protected static java.lang.String
PROP_USEDISPOSABLECONNECTIONFACADE
protected static java.lang.String
PROP_USERNAME
protected static java.lang.String
PROP_USESTATEMENTFACADE
protected static java.lang.String
PROP_VALIDATIONINTERVAL
protected static java.lang.String
PROP_VALIDATIONQUERY
protected static java.lang.String
PROP_VALIDATIONQUERY_TIMEOUT
protected static java.lang.String
PROP_VALIDATOR_CLASS_NAME
static int
UNKNOWN_TRANSACTIONISOLATION
-
Constructor Summary
Constructors Constructor Description DataSourceFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.sql.DataSource
createDataSource(java.util.Properties properties)
Creates and configures aDataSource
instance based on the given properties.javax.sql.DataSource
createDataSource(java.util.Properties properties, javax.naming.Context context, boolean XA)
java.lang.Object
getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment)
Create and return a newBasicDataSource
instance.protected static java.util.Properties
getProperties(java.lang.String propText)
Parse properties from the string.static PoolConfiguration
parsePoolProperties(java.util.Properties properties)
void
performJNDILookup(javax.naming.Context context, PoolConfiguration poolProperties)
-
-
-
Field Detail
-
PROP_DEFAULTAUTOCOMMIT
protected static final java.lang.String PROP_DEFAULTAUTOCOMMIT
- See Also:
- Constant Field Values
-
PROP_DEFAULTREADONLY
protected static final java.lang.String PROP_DEFAULTREADONLY
- See Also:
- Constant Field Values
-
PROP_DEFAULTTRANSACTIONISOLATION
protected static final java.lang.String PROP_DEFAULTTRANSACTIONISOLATION
- See Also:
- Constant Field Values
-
PROP_DEFAULTCATALOG
protected static final java.lang.String PROP_DEFAULTCATALOG
- See Also:
- Constant Field Values
-
PROP_DRIVERCLASSNAME
protected static final java.lang.String PROP_DRIVERCLASSNAME
- See Also:
- Constant Field Values
-
PROP_PASSWORD
protected static final java.lang.String PROP_PASSWORD
- See Also:
- Constant Field Values
-
PROP_URL
protected static final java.lang.String PROP_URL
- See Also:
- Constant Field Values
-
PROP_USERNAME
protected static final java.lang.String PROP_USERNAME
- See Also:
- Constant Field Values
-
PROP_MAXACTIVE
protected static final java.lang.String PROP_MAXACTIVE
- See Also:
- Constant Field Values
-
PROP_MAXIDLE
protected static final java.lang.String PROP_MAXIDLE
- See Also:
- Constant Field Values
-
PROP_MINIDLE
protected static final java.lang.String PROP_MINIDLE
- See Also:
- Constant Field Values
-
PROP_INITIALSIZE
protected static final java.lang.String PROP_INITIALSIZE
- See Also:
- Constant Field Values
-
PROP_MAXWAIT
protected static final java.lang.String PROP_MAXWAIT
- See Also:
- Constant Field Values
-
PROP_MAXAGE
protected static final java.lang.String PROP_MAXAGE
- See Also:
- Constant Field Values
-
PROP_TESTONBORROW
protected static final java.lang.String PROP_TESTONBORROW
- See Also:
- Constant Field Values
-
PROP_TESTONRETURN
protected static final java.lang.String PROP_TESTONRETURN
- See Also:
- Constant Field Values
-
PROP_TESTWHILEIDLE
protected static final java.lang.String PROP_TESTWHILEIDLE
- See Also:
- Constant Field Values
-
PROP_TESTONCONNECT
protected static final java.lang.String PROP_TESTONCONNECT
- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY
protected static final java.lang.String PROP_VALIDATIONQUERY
- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY_TIMEOUT
protected static final java.lang.String PROP_VALIDATIONQUERY_TIMEOUT
- See Also:
- Constant Field Values
-
PROP_VALIDATOR_CLASS_NAME
protected static final java.lang.String PROP_VALIDATOR_CLASS_NAME
- See Also:
- Constant Field Values
-
PROP_NUMTESTSPEREVICTIONRUN
protected static final java.lang.String PROP_NUMTESTSPEREVICTIONRUN
- See Also:
- Constant Field Values
-
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
protected static final java.lang.String PROP_TIMEBETWEENEVICTIONRUNSMILLIS
- See Also:
- Constant Field Values
-
PROP_MINEVICTABLEIDLETIMEMILLIS
protected static final java.lang.String PROP_MINEVICTABLEIDLETIMEMILLIS
- See Also:
- Constant Field Values
-
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
protected static final java.lang.String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONED
protected static final java.lang.String PROP_REMOVEABANDONED
- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONEDTIMEOUT
protected static final java.lang.String PROP_REMOVEABANDONEDTIMEOUT
- See Also:
- Constant Field Values
-
PROP_LOGABANDONED
protected static final java.lang.String PROP_LOGABANDONED
- See Also:
- Constant Field Values
-
PROP_ABANDONWHENPERCENTAGEFULL
protected static final java.lang.String PROP_ABANDONWHENPERCENTAGEFULL
- See Also:
- Constant Field Values
-
PROP_POOLPREPAREDSTATEMENTS
protected static final java.lang.String PROP_POOLPREPAREDSTATEMENTS
- See Also:
- Constant Field Values
-
PROP_MAXOPENPREPAREDSTATEMENTS
protected static final java.lang.String PROP_MAXOPENPREPAREDSTATEMENTS
- See Also:
- Constant Field Values
-
PROP_CONNECTIONPROPERTIES
protected static final java.lang.String PROP_CONNECTIONPROPERTIES
- See Also:
- Constant Field Values
-
PROP_INITSQL
protected static final java.lang.String PROP_INITSQL
- See Also:
- Constant Field Values
-
PROP_INTERCEPTORS
protected static final java.lang.String PROP_INTERCEPTORS
- See Also:
- Constant Field Values
-
PROP_VALIDATIONINTERVAL
protected static final java.lang.String PROP_VALIDATIONINTERVAL
- See Also:
- Constant Field Values
-
PROP_JMX_ENABLED
protected static final java.lang.String PROP_JMX_ENABLED
- See Also:
- Constant Field Values
-
PROP_FAIR_QUEUE
protected static final java.lang.String PROP_FAIR_QUEUE
- See Also:
- Constant Field Values
-
PROP_USE_EQUALS
protected static final java.lang.String PROP_USE_EQUALS
- See Also:
- Constant Field Values
-
PROP_USE_CON_LOCK
protected static final java.lang.String PROP_USE_CON_LOCK
- See Also:
- Constant Field Values
-
PROP_DATASOURCE
protected static final java.lang.String PROP_DATASOURCE
- See Also:
- Constant Field Values
-
PROP_DATASOURCE_JNDI
protected static final java.lang.String PROP_DATASOURCE_JNDI
- See Also:
- Constant Field Values
-
PROP_SUSPECT_TIMEOUT
protected static final java.lang.String PROP_SUSPECT_TIMEOUT
- See Also:
- Constant Field Values
-
PROP_ALTERNATE_USERNAME_ALLOWED
protected static final java.lang.String PROP_ALTERNATE_USERNAME_ALLOWED
- See Also:
- Constant Field Values
-
PROP_COMMITONRETURN
protected static final java.lang.String PROP_COMMITONRETURN
- See Also:
- Constant Field Values
-
PROP_ROLLBACKONRETURN
protected static final java.lang.String PROP_ROLLBACKONRETURN
- See Also:
- Constant Field Values
-
PROP_USEDISPOSABLECONNECTIONFACADE
protected static final java.lang.String PROP_USEDISPOSABLECONNECTIONFACADE
- See Also:
- Constant Field Values
-
PROP_LOGVALIDATIONERRORS
protected static final java.lang.String PROP_LOGVALIDATIONERRORS
- See Also:
- Constant Field Values
-
PROP_PROPAGATEINTERRUPTSTATE
protected static final java.lang.String PROP_PROPAGATEINTERRUPTSTATE
- See Also:
- Constant Field Values
-
PROP_IGNOREEXCEPTIONONPRELOAD
protected static final java.lang.String PROP_IGNOREEXCEPTIONONPRELOAD
- See Also:
- Constant Field Values
-
PROP_USESTATEMENTFACADE
protected static final java.lang.String PROP_USESTATEMENTFACADE
- See Also:
- Constant Field Values
-
UNKNOWN_TRANSACTIONISOLATION
public static final int UNKNOWN_TRANSACTIONISOLATION
- See Also:
- Constant Field Values
-
OBJECT_NAME
public static final java.lang.String OBJECT_NAME
- See Also:
- Constant Field Values
-
ALL_PROPERTIES
protected static final java.lang.String[] ALL_PROPERTIES
-
-
Method Detail
-
getObjectInstance
public java.lang.Object getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment) throws java.lang.Exception
Create and return a new
BasicDataSource
instance. If no instance can be created, returnnull
instead.- Specified by:
getObjectInstance
in interfacejavax.naming.spi.ObjectFactory
- Parameters:
obj
- The possibly null object containing location or reference information that can be used in creating an objectname
- The name of this object relative tonameCtx
nameCtx
- The context relative to which thename
parameter is specified, ornull
ifname
is relative to the default initial contextenvironment
- The possibly null environment that is used in creating this object- Throws:
java.lang.Exception
- if an exception occurs creating the instance
-
parsePoolProperties
public static PoolConfiguration parsePoolProperties(java.util.Properties properties)
-
createDataSource
public javax.sql.DataSource createDataSource(java.util.Properties properties) throws java.lang.Exception
Creates and configures aDataSource
instance based on the given properties.- Parameters:
properties
- the datasource configuration properties- Returns:
- the datasource
- Throws:
java.lang.Exception
- if an error occurs creating the data source
-
createDataSource
public javax.sql.DataSource createDataSource(java.util.Properties properties, javax.naming.Context context, boolean XA) throws java.lang.Exception
- Throws:
java.lang.Exception
-
performJNDILookup
public void performJNDILookup(javax.naming.Context context, PoolConfiguration poolProperties)
-
getProperties
protected static java.util.Properties getProperties(java.lang.String propText)
Parse properties from the string. Format of the string must be [propertyName=property;]*.- Parameters:
propText
- The properties string- Returns:
- the properties
-
-