Class DataSourceFactory
java.lang.Object
org.apache.tomcat.jdbc.pool.DataSourceFactory
- All Implemented Interfaces:
ObjectFactory
JNDI object factory that creates an instance of
BasicDataSource that has been configured based on the
RefAddr values of the specified Reference,
which must match the names and data types of the
BasicDataSource 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
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
FieldsModifier and TypeFieldDescriptionprotected static final String[]Array of all supported property names.static final StringProperty name for the JMX object name.protected static final StringProperty name for abandonWhenPercentageFull.protected static final StringProperty name for accessToUnderlyingConnectionAllowed.protected static final StringProperty name for alternateUsernameAllowed.protected static final StringProperty name for commitOnReturn.protected static final StringProperty name for connectionProperties.protected static final StringProperty name for dataSource.protected static final StringProperty name for dataSourceJNDI.protected static final StringProperty name for defaultAutoCommit.protected static final StringProperty name for defaultCatalog.protected static final StringProperty name for defaultReadOnly.protected static final StringProperty name for defaultTransactionIsolation.protected static final StringProperty name for driverClassName.protected static final StringProperty name for fairQueue.protected static final StringProperty name for ignoreExceptionOnPreLoad.protected static final StringProperty name for initialSize.protected static final StringProperty name for initSQL.protected static final StringProperty name for jdbcInterceptors.protected static final StringProperty name for jmxEnabled.protected static final StringProperty name for logAbandoned.protected static final StringProperty name for logValidationErrors.protected static final StringProperty name for maxActive.protected static final StringProperty name for maxAge.protected static final StringProperty name for maxIdle.protected static final StringProperty name for maxOpenPreparedStatements.protected static final StringProperty name for maxWait.protected static final StringProperty name for minEvictableIdleTimeMillis.protected static final StringProperty name for minIdle.protected static final StringProperty name for numTestsPerEvictionRun.protected static final StringProperty name for password.protected static final StringProperty name for poolPreparedStatements.protected static final StringProperty name for propagateInterruptState.protected static final StringProperty name for removeAbandoned.protected static final StringProperty name for removeAbandonedTimeout.protected static final StringProperty name for rollbackOnReturn.protected static final StringProperty name for suspectTimeout.protected static final StringProperty name for testOnBorrow.protected static final StringProperty name for testOnConnect.protected static final StringProperty name for testOnReturn.protected static final StringProperty name for testWhileIdle.protected static final StringProperty name for timeBetweenEvictionRunsMillis.protected static final StringProperty name for url.protected static final StringProperty name for useLock.protected static final StringProperty name for useEquals.protected static final StringProperty name for useDisposableConnectionFacade.protected static final StringProperty name for username.protected static final StringProperty name for useStatementFacade.protected static final StringProperty name for validationInterval.protected static final StringProperty name for validationQuery.protected static final StringProperty name for validationQueryTimeout.protected static final StringProperty name for validatorClassName.static final intValue indicating an unknown transaction isolation level. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateDataSource(Properties properties) Creates and configures aDataSourceinstance based on the given properties.createDataSource(Properties properties, Context context, boolean XA) Creates and configures aDataSourceinstance based on the given properties.getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) Create and return a newBasicDataSourceinstance.protected static PropertiesgetProperties(String propText) Parse properties from the string.static PoolConfigurationparsePoolProperties(Properties properties) Parse the given properties into a PoolConfiguration.voidperformJNDILookup(Context context, PoolConfiguration poolProperties) Perform a JNDI lookup for the data source.
-
Field Details
-
PROP_DEFAULTAUTOCOMMIT
-
PROP_DEFAULTREADONLY
-
PROP_DEFAULTTRANSACTIONISOLATION
Property name for defaultTransactionIsolation.- See Also:
-
PROP_DEFAULTCATALOG
-
PROP_DRIVERCLASSNAME
-
PROP_PASSWORD
-
PROP_URL
-
PROP_USERNAME
-
PROP_MAXACTIVE
-
PROP_MAXIDLE
-
PROP_MINIDLE
-
PROP_INITIALSIZE
-
PROP_MAXWAIT
-
PROP_MAXAGE
-
PROP_TESTONBORROW
-
PROP_TESTONRETURN
-
PROP_TESTWHILEIDLE
-
PROP_TESTONCONNECT
-
PROP_VALIDATIONQUERY
-
PROP_VALIDATIONQUERY_TIMEOUT
Property name for validationQueryTimeout.- See Also:
-
PROP_VALIDATOR_CLASS_NAME
Property name for validatorClassName.- See Also:
-
PROP_NUMTESTSPEREVICTIONRUN
Property name for numTestsPerEvictionRun.- See Also:
-
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
Property name for timeBetweenEvictionRunsMillis.- See Also:
-
PROP_MINEVICTABLEIDLETIMEMILLIS
Property name for minEvictableIdleTimeMillis.- See Also:
-
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
Property name for accessToUnderlyingConnectionAllowed.- See Also:
-
PROP_REMOVEABANDONED
-
PROP_REMOVEABANDONEDTIMEOUT
Property name for removeAbandonedTimeout.- See Also:
-
PROP_LOGABANDONED
-
PROP_ABANDONWHENPERCENTAGEFULL
Property name for abandonWhenPercentageFull.- See Also:
-
PROP_POOLPREPAREDSTATEMENTS
Property name for poolPreparedStatements.- See Also:
-
PROP_MAXOPENPREPAREDSTATEMENTS
Property name for maxOpenPreparedStatements.- See Also:
-
PROP_CONNECTIONPROPERTIES
Property name for connectionProperties.- See Also:
-
PROP_INITSQL
-
PROP_INTERCEPTORS
-
PROP_VALIDATIONINTERVAL
Property name for validationInterval.- See Also:
-
PROP_JMX_ENABLED
-
PROP_FAIR_QUEUE
-
PROP_USE_EQUALS
-
PROP_USE_CON_LOCK
-
PROP_DATASOURCE
-
PROP_DATASOURCE_JNDI
-
PROP_SUSPECT_TIMEOUT
-
PROP_ALTERNATE_USERNAME_ALLOWED
Property name for alternateUsernameAllowed.- See Also:
-
PROP_COMMITONRETURN
-
PROP_ROLLBACKONRETURN
-
PROP_USEDISPOSABLECONNECTIONFACADE
Property name for useDisposableConnectionFacade.- See Also:
-
PROP_LOGVALIDATIONERRORS
Property name for logValidationErrors.- See Also:
-
PROP_PROPAGATEINTERRUPTSTATE
Property name for propagateInterruptState.- See Also:
-
PROP_IGNOREEXCEPTIONONPRELOAD
Property name for ignoreExceptionOnPreLoad.- See Also:
-
PROP_USESTATEMENTFACADE
Property name for useStatementFacade.- See Also:
-
UNKNOWN_TRANSACTIONISOLATION
public static final int UNKNOWN_TRANSACTIONISOLATIONValue indicating an unknown transaction isolation level.- See Also:
-
OBJECT_NAME
-
ALL_PROPERTIES
Array of all supported property names.
-
-
Constructor Details
-
DataSourceFactory
public DataSourceFactory()Default constructor.
-
-
Method Details
-
getObjectInstance
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws ExceptionCreate and return a new
BasicDataSourceinstance. If no instance can be created, returnnullinstead.- Specified by:
getObjectInstancein interfaceObjectFactory- 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:
Exception- if an exception occurs creating the instance
-
parsePoolProperties
Parse the given properties into a PoolConfiguration.- Parameters:
properties- The properties to parse- Returns:
- The configured PoolConfiguration
-
createDataSource
Creates and configures aDataSourceinstance based on the given properties.- Parameters:
properties- the datasource configuration properties- Returns:
- the datasource
- Throws:
Exception- if an error occurs creating the data source
-
createDataSource
public DataSource createDataSource(Properties properties, Context context, boolean XA) throws Exception Creates 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:
Exception- if an error occurs creating the data source
-
performJNDILookup
Perform a JNDI lookup for the data source.- Parameters:
context- The JNDI contextpoolProperties- The pool configuration
-
getProperties
Parse properties from the string. Format of the string must be [propertyName=property;]*.- Parameters:
propText- The properties string- Returns:
- the properties
-