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.ObjectFactoryJNDI object factory that creates an instance of
BasicDataSourcethat has been configured based on theRefAddrvalues of the specifiedReference, which must match the names and data types of theBasicDataSourcebean 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
JdbcInterceptorclass. - 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String[]ALL_PROPERTIESArray of all supported property names.static java.lang.StringOBJECT_NAMEProperty name for the JMX object name.protected static java.lang.StringPROP_ABANDONWHENPERCENTAGEFULLProperty name for abandonWhenPercentageFull.protected static java.lang.StringPROP_ACCESSTOUNDERLYINGCONNECTIONALLOWEDProperty name for accessToUnderlyingConnectionAllowed.protected static java.lang.StringPROP_ALTERNATE_USERNAME_ALLOWEDProperty name for alternateUsernameAllowed.protected static java.lang.StringPROP_COMMITONRETURNProperty name for commitOnReturn.protected static java.lang.StringPROP_CONNECTIONPROPERTIESProperty name for connectionProperties.protected static java.lang.StringPROP_DATASOURCEProperty name for dataSource.protected static java.lang.StringPROP_DATASOURCE_JNDIProperty name for dataSourceJNDI.protected static java.lang.StringPROP_DEFAULTAUTOCOMMITProperty name for defaultAutoCommit.protected static java.lang.StringPROP_DEFAULTCATALOGProperty name for defaultCatalog.protected static java.lang.StringPROP_DEFAULTREADONLYProperty name for defaultReadOnly.protected static java.lang.StringPROP_DEFAULTTRANSACTIONISOLATIONProperty name for defaultTransactionIsolation.protected static java.lang.StringPROP_DRIVERCLASSNAMEProperty name for driverClassName.protected static java.lang.StringPROP_FAIR_QUEUEProperty name for fairQueue.protected static java.lang.StringPROP_IGNOREEXCEPTIONONPRELOADProperty name for ignoreExceptionOnPreLoad.protected static java.lang.StringPROP_INITIALSIZEProperty name for initialSize.protected static java.lang.StringPROP_INITSQLProperty name for initSQL.protected static java.lang.StringPROP_INTERCEPTORSProperty name for jdbcInterceptors.protected static java.lang.StringPROP_JMX_ENABLEDProperty name for jmxEnabled.protected static java.lang.StringPROP_LOGABANDONEDProperty name for logAbandoned.protected static java.lang.StringPROP_LOGVALIDATIONERRORSProperty name for logValidationErrors.protected static java.lang.StringPROP_MAXACTIVEProperty name for maxActive.protected static java.lang.StringPROP_MAXAGEProperty name for maxAge.protected static java.lang.StringPROP_MAXIDLEProperty name for maxIdle.protected static java.lang.StringPROP_MAXOPENPREPAREDSTATEMENTSProperty name for maxOpenPreparedStatements.protected static java.lang.StringPROP_MAXWAITProperty name for maxWait.protected static java.lang.StringPROP_MINEVICTABLEIDLETIMEMILLISProperty name for minEvictableIdleTimeMillis.protected static java.lang.StringPROP_MINIDLEProperty name for minIdle.protected static java.lang.StringPROP_NUMTESTSPEREVICTIONRUNProperty name for numTestsPerEvictionRun.protected static java.lang.StringPROP_PASSWORDProperty name for password.protected static java.lang.StringPROP_POOLPREPAREDSTATEMENTSProperty name for poolPreparedStatements.protected static java.lang.StringPROP_PROPAGATEINTERRUPTSTATEProperty name for propagateInterruptState.protected static java.lang.StringPROP_REMOVEABANDONEDProperty name for removeAbandoned.protected static java.lang.StringPROP_REMOVEABANDONEDTIMEOUTProperty name for removeAbandonedTimeout.protected static java.lang.StringPROP_ROLLBACKONRETURNProperty name for rollbackOnReturn.protected static java.lang.StringPROP_SUSPECT_TIMEOUTProperty name for suspectTimeout.protected static java.lang.StringPROP_TESTONBORROWProperty name for testOnBorrow.protected static java.lang.StringPROP_TESTONCONNECTProperty name for testOnConnect.protected static java.lang.StringPROP_TESTONRETURNProperty name for testOnReturn.protected static java.lang.StringPROP_TESTWHILEIDLEProperty name for testWhileIdle.protected static java.lang.StringPROP_TIMEBETWEENEVICTIONRUNSMILLISProperty name for timeBetweenEvictionRunsMillis.protected static java.lang.StringPROP_URLProperty name for url.protected static java.lang.StringPROP_USE_CON_LOCKProperty name for useLock.protected static java.lang.StringPROP_USE_EQUALSProperty name for useEquals.protected static java.lang.StringPROP_USEDISPOSABLECONNECTIONFACADEProperty name for useDisposableConnectionFacade.protected static java.lang.StringPROP_USERNAMEProperty name for username.protected static java.lang.StringPROP_USESTATEMENTFACADEProperty name for useStatementFacade.protected static java.lang.StringPROP_VALIDATIONINTERVALProperty name for validationInterval.protected static java.lang.StringPROP_VALIDATIONQUERYProperty name for validationQuery.protected static java.lang.StringPROP_VALIDATIONQUERY_TIMEOUTProperty name for validationQueryTimeout.protected static java.lang.StringPROP_VALIDATOR_CLASS_NAMEProperty name for validatorClassName.static intUNKNOWN_TRANSACTIONISOLATIONValue indicating an unknown transaction isolation level.
-
Constructor Summary
Constructors Constructor Description DataSourceFactory()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.sql.DataSourcecreateDataSource(java.util.Properties properties)Creates and configures aDataSourceinstance based on the given properties.javax.sql.DataSourcecreateDataSource(java.util.Properties properties, javax.naming.Context context, boolean XA)Creates and configures aDataSourceinstance based on the given properties.java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment)Create and return a newBasicDataSourceinstance.protected static java.util.PropertiesgetProperties(java.lang.String propText)Parse properties from the string.static PoolConfigurationparsePoolProperties(java.util.Properties properties)Parse the given properties into a PoolConfiguration.voidperformJNDILookup(javax.naming.Context context, PoolConfiguration poolProperties)Perform a JNDI lookup for the data source.
-
-
-
Field Detail
-
PROP_DEFAULTAUTOCOMMIT
protected static final java.lang.String PROP_DEFAULTAUTOCOMMIT
Property name for defaultAutoCommit.- See Also:
- Constant Field Values
-
PROP_DEFAULTREADONLY
protected static final java.lang.String PROP_DEFAULTREADONLY
Property name for defaultReadOnly.- See Also:
- Constant Field Values
-
PROP_DEFAULTTRANSACTIONISOLATION
protected static final java.lang.String PROP_DEFAULTTRANSACTIONISOLATION
Property name for defaultTransactionIsolation.- See Also:
- Constant Field Values
-
PROP_DEFAULTCATALOG
protected static final java.lang.String PROP_DEFAULTCATALOG
Property name for defaultCatalog.- See Also:
- Constant Field Values
-
PROP_DRIVERCLASSNAME
protected static final java.lang.String PROP_DRIVERCLASSNAME
Property name for driverClassName.- See Also:
- Constant Field Values
-
PROP_PASSWORD
protected static final java.lang.String PROP_PASSWORD
Property name for password.- See Also:
- Constant Field Values
-
PROP_URL
protected static final java.lang.String PROP_URL
Property name for url.- See Also:
- Constant Field Values
-
PROP_USERNAME
protected static final java.lang.String PROP_USERNAME
Property name for username.- See Also:
- Constant Field Values
-
PROP_MAXACTIVE
protected static final java.lang.String PROP_MAXACTIVE
Property name for maxActive.- See Also:
- Constant Field Values
-
PROP_MAXIDLE
protected static final java.lang.String PROP_MAXIDLE
Property name for maxIdle.- See Also:
- Constant Field Values
-
PROP_MINIDLE
protected static final java.lang.String PROP_MINIDLE
Property name for minIdle.- See Also:
- Constant Field Values
-
PROP_INITIALSIZE
protected static final java.lang.String PROP_INITIALSIZE
Property name for initialSize.- See Also:
- Constant Field Values
-
PROP_MAXWAIT
protected static final java.lang.String PROP_MAXWAIT
Property name for maxWait.- See Also:
- Constant Field Values
-
PROP_MAXAGE
protected static final java.lang.String PROP_MAXAGE
Property name for maxAge.- See Also:
- Constant Field Values
-
PROP_TESTONBORROW
protected static final java.lang.String PROP_TESTONBORROW
Property name for testOnBorrow.- See Also:
- Constant Field Values
-
PROP_TESTONRETURN
protected static final java.lang.String PROP_TESTONRETURN
Property name for testOnReturn.- See Also:
- Constant Field Values
-
PROP_TESTWHILEIDLE
protected static final java.lang.String PROP_TESTWHILEIDLE
Property name for testWhileIdle.- See Also:
- Constant Field Values
-
PROP_TESTONCONNECT
protected static final java.lang.String PROP_TESTONCONNECT
Property name for testOnConnect.- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY
protected static final java.lang.String PROP_VALIDATIONQUERY
Property name for validationQuery.- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY_TIMEOUT
protected static final java.lang.String PROP_VALIDATIONQUERY_TIMEOUT
Property name for validationQueryTimeout.- See Also:
- Constant Field Values
-
PROP_VALIDATOR_CLASS_NAME
protected static final java.lang.String PROP_VALIDATOR_CLASS_NAME
Property name for validatorClassName.- See Also:
- Constant Field Values
-
PROP_NUMTESTSPEREVICTIONRUN
protected static final java.lang.String PROP_NUMTESTSPEREVICTIONRUN
Property name for numTestsPerEvictionRun.- See Also:
- Constant Field Values
-
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
protected static final java.lang.String PROP_TIMEBETWEENEVICTIONRUNSMILLIS
Property name for timeBetweenEvictionRunsMillis.- See Also:
- Constant Field Values
-
PROP_MINEVICTABLEIDLETIMEMILLIS
protected static final java.lang.String PROP_MINEVICTABLEIDLETIMEMILLIS
Property name for minEvictableIdleTimeMillis.- See Also:
- Constant Field Values
-
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
protected static final java.lang.String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
Property name for accessToUnderlyingConnectionAllowed.- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONED
protected static final java.lang.String PROP_REMOVEABANDONED
Property name for removeAbandoned.- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONEDTIMEOUT
protected static final java.lang.String PROP_REMOVEABANDONEDTIMEOUT
Property name for removeAbandonedTimeout.- See Also:
- Constant Field Values
-
PROP_LOGABANDONED
protected static final java.lang.String PROP_LOGABANDONED
Property name for logAbandoned.- See Also:
- Constant Field Values
-
PROP_ABANDONWHENPERCENTAGEFULL
protected static final java.lang.String PROP_ABANDONWHENPERCENTAGEFULL
Property name for abandonWhenPercentageFull.- See Also:
- Constant Field Values
-
PROP_POOLPREPAREDSTATEMENTS
protected static final java.lang.String PROP_POOLPREPAREDSTATEMENTS
Property name for poolPreparedStatements.- See Also:
- Constant Field Values
-
PROP_MAXOPENPREPAREDSTATEMENTS
protected static final java.lang.String PROP_MAXOPENPREPAREDSTATEMENTS
Property name for maxOpenPreparedStatements.- See Also:
- Constant Field Values
-
PROP_CONNECTIONPROPERTIES
protected static final java.lang.String PROP_CONNECTIONPROPERTIES
Property name for connectionProperties.- See Also:
- Constant Field Values
-
PROP_INITSQL
protected static final java.lang.String PROP_INITSQL
Property name for initSQL.- See Also:
- Constant Field Values
-
PROP_INTERCEPTORS
protected static final java.lang.String PROP_INTERCEPTORS
Property name for jdbcInterceptors.- See Also:
- Constant Field Values
-
PROP_VALIDATIONINTERVAL
protected static final java.lang.String PROP_VALIDATIONINTERVAL
Property name for validationInterval.- See Also:
- Constant Field Values
-
PROP_JMX_ENABLED
protected static final java.lang.String PROP_JMX_ENABLED
Property name for jmxEnabled.- See Also:
- Constant Field Values
-
PROP_FAIR_QUEUE
protected static final java.lang.String PROP_FAIR_QUEUE
Property name for fairQueue.- See Also:
- Constant Field Values
-
PROP_USE_EQUALS
protected static final java.lang.String PROP_USE_EQUALS
Property name for useEquals.- See Also:
- Constant Field Values
-
PROP_USE_CON_LOCK
protected static final java.lang.String PROP_USE_CON_LOCK
Property name for useLock.- See Also:
- Constant Field Values
-
PROP_DATASOURCE
protected static final java.lang.String PROP_DATASOURCE
Property name for dataSource.- See Also:
- Constant Field Values
-
PROP_DATASOURCE_JNDI
protected static final java.lang.String PROP_DATASOURCE_JNDI
Property name for dataSourceJNDI.- See Also:
- Constant Field Values
-
PROP_SUSPECT_TIMEOUT
protected static final java.lang.String PROP_SUSPECT_TIMEOUT
Property name for suspectTimeout.- See Also:
- Constant Field Values
-
PROP_ALTERNATE_USERNAME_ALLOWED
protected static final java.lang.String PROP_ALTERNATE_USERNAME_ALLOWED
Property name for alternateUsernameAllowed.- See Also:
- Constant Field Values
-
PROP_COMMITONRETURN
protected static final java.lang.String PROP_COMMITONRETURN
Property name for commitOnReturn.- See Also:
- Constant Field Values
-
PROP_ROLLBACKONRETURN
protected static final java.lang.String PROP_ROLLBACKONRETURN
Property name for rollbackOnReturn.- See Also:
- Constant Field Values
-
PROP_USEDISPOSABLECONNECTIONFACADE
protected static final java.lang.String PROP_USEDISPOSABLECONNECTIONFACADE
Property name for useDisposableConnectionFacade.- See Also:
- Constant Field Values
-
PROP_LOGVALIDATIONERRORS
protected static final java.lang.String PROP_LOGVALIDATIONERRORS
Property name for logValidationErrors.- See Also:
- Constant Field Values
-
PROP_PROPAGATEINTERRUPTSTATE
protected static final java.lang.String PROP_PROPAGATEINTERRUPTSTATE
Property name for propagateInterruptState.- See Also:
- Constant Field Values
-
PROP_IGNOREEXCEPTIONONPRELOAD
protected static final java.lang.String PROP_IGNOREEXCEPTIONONPRELOAD
Property name for ignoreExceptionOnPreLoad.- See Also:
- Constant Field Values
-
PROP_USESTATEMENTFACADE
protected static final java.lang.String PROP_USESTATEMENTFACADE
Property name for useStatementFacade.- See Also:
- Constant Field Values
-
UNKNOWN_TRANSACTIONISOLATION
public static final int UNKNOWN_TRANSACTIONISOLATION
Value indicating an unknown transaction isolation level.- See Also:
- Constant Field Values
-
OBJECT_NAME
public static final java.lang.String OBJECT_NAME
Property name for the JMX object name.- See Also:
- Constant Field Values
-
ALL_PROPERTIES
protected static final java.lang.String[] ALL_PROPERTIES
Array of all supported property names.
-
-
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.ExceptionCreate and return a new
BasicDataSourceinstance. If no instance can be created, returnnullinstead.- Specified by:
getObjectInstancein 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 tonameCtxnameCtx- The context relative to which thenameparameter is specified, ornullifnameis 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)
Parse the given properties into a PoolConfiguration.- Parameters:
properties- The properties to parse- Returns:
- The configured PoolConfiguration
-
createDataSource
public javax.sql.DataSource createDataSource(java.util.Properties properties) throws java.lang.ExceptionCreates and configures aDataSourceinstance 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.ExceptionCreates and configures aDataSourceinstance based on the given properties.- Parameters:
properties- The datasource configuration propertiescontext- The JNDI contextXA-trueto create an XA data source- Returns:
- The configured datasource
- Throws:
java.lang.Exception- if an error occurs creating the data source
-
performJNDILookup
public void performJNDILookup(javax.naming.Context context, PoolConfiguration poolProperties)Perform a JNDI lookup for the data source.- Parameters:
context- The JNDI contextpoolProperties- The pool configuration
-
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
-
-