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
DataSource- orXADataSource, when the reference names a type to be built as XA - configured from theRefAddrvalues of the specifiedReference. Address names are matched against the pool properties listed inALL_PROPERTIES; they are the attributes of the pool documented withPoolConfiguration's setters, not the property set of any other pool implementation.The factory applies a strict reading of the reference: an attribute whose value is blank leaves its property at the
PoolPropertiesdefault, and a value the property cannot take fails the lookup with an exception naming the attribute instead of being silently ignored. The legacy settingsnumTestsPerEvictionRun,accessToUnderlyingConnectionAllowed,poolPreparedStatementsandmaxOpenPreparedStatementsare the exception: they are accepted for configuration compatibility but have no effect, so a non-blank value is reported with a warning rather than failing the lookup.
-
-
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_ABANDONWHENPERCENTAGEFULLTheabandonWhenPercentageFullproperty name.protected static java.lang.StringPROP_ACCESSTOUNDERLYINGCONNECTIONALLOWEDTheaccessToUnderlyingConnectionAllowedproperty name.protected static java.lang.StringPROP_ALTERNATE_USERNAME_ALLOWEDThealternateUsernameAllowedproperty name.protected static java.lang.StringPROP_COMMITONRETURNThecommitOnReturnproperty name.protected static java.lang.StringPROP_CONNECTIONPROPERTIESTheconnectionPropertiesproperty name.protected static java.lang.StringPROP_DATASOURCEThedataSourceproperty name.protected static java.lang.StringPROP_DATASOURCE_JNDIThedataSourceJNDIproperty name.protected static java.lang.StringPROP_DEFAULTAUTOCOMMITThedefaultAutoCommitproperty name.protected static java.lang.StringPROP_DEFAULTCATALOGThedefaultCatalogproperty name.protected static java.lang.StringPROP_DEFAULTREADONLYThedefaultReadOnlyproperty name.protected static java.lang.StringPROP_DEFAULTTRANSACTIONISOLATIONThedefaultTransactionIsolationproperty name.protected static java.lang.StringPROP_DRIVERCLASSNAMEThedriverClassNameproperty name.protected static java.lang.StringPROP_FAIR_QUEUEThefairQueueproperty name.protected static java.lang.StringPROP_IGNOREEXCEPTIONONPRELOADTheignoreExceptionOnPreLoadproperty name.protected static java.lang.StringPROP_INITIALSIZETheinitialSizeproperty name.protected static java.lang.StringPROP_INITSQLTheinitSQLproperty name.protected static java.lang.StringPROP_INTERCEPTORSThejdbcInterceptorsproperty name.protected static java.lang.StringPROP_JMX_ENABLEDThejmxEnabledproperty name.protected static java.lang.StringPROP_LOGABANDONEDThelogAbandonedproperty name.protected static java.lang.StringPROP_LOGVALIDATIONERRORSThelogValidationErrorsproperty name.protected static java.lang.StringPROP_MAXACTIVEThemaxActiveproperty name.protected static java.lang.StringPROP_MAXAGEThemaxAgeproperty name.protected static java.lang.StringPROP_MAXIDLEThemaxIdleproperty name.protected static java.lang.StringPROP_MAXOPENPREPAREDSTATEMENTSThemaxOpenPreparedStatementsproperty name.protected static java.lang.StringPROP_MAXWAITThemaxWaitproperty name.protected static java.lang.StringPROP_MINEVICTABLEIDLETIMEMILLISTheminEvictableIdleTimeMillisproperty name.protected static java.lang.StringPROP_MINIDLETheminIdleproperty name.protected static java.lang.StringPROP_NUMTESTSPEREVICTIONRUNThenumTestsPerEvictionRunproperty name.protected static java.lang.StringPROP_PASSWORDThepasswordproperty name.protected static java.lang.StringPROP_POOLPREPAREDSTATEMENTSThepoolPreparedStatementsproperty name.protected static java.lang.StringPROP_PROPAGATEINTERRUPTSTATEThepropagateInterruptStateproperty name.protected static java.lang.StringPROP_REMOVEABANDONEDTheremoveAbandonedproperty name.protected static java.lang.StringPROP_REMOVEABANDONEDTIMEOUTTheremoveAbandonedTimeoutproperty name.protected static java.lang.StringPROP_ROLLBACKONRETURNTherollbackOnReturnproperty name.protected static java.lang.StringPROP_SUSPECT_TIMEOUTThesuspectTimeoutproperty name.protected static java.lang.StringPROP_TESTONBORROWThetestOnBorrowproperty name.protected static java.lang.StringPROP_TESTONCONNECTThetestOnConnectproperty name.protected static java.lang.StringPROP_TESTONRETURNThetestOnReturnproperty name.protected static java.lang.StringPROP_TESTWHILEIDLEThetestWhileIdleproperty name.protected static java.lang.StringPROP_TIMEBETWEENEVICTIONRUNSMILLISThetimeBetweenEvictionRunsMillisproperty name.protected static java.lang.StringPROP_URLTheurlproperty name.protected static java.lang.StringPROP_USE_EQUALSTheuseEqualsproperty name.protected static java.lang.StringPROP_USE_LOCKTheuseLockproperty name.protected static java.lang.StringPROP_USEDISPOSABLECONNECTIONFACADEProperty name for useDisposableConnectionFacade.protected static java.lang.StringPROP_USERNAMETheusernameproperty name.protected static java.lang.StringPROP_USESTATEMENTFACADEProperty name for useStatementFacade.protected static java.lang.StringPROP_VALIDATIONINTERVALThevalidationIntervalproperty name.protected static java.lang.StringPROP_VALIDATIONQUERYThevalidationQueryproperty name.protected static java.lang.StringPROP_VALIDATIONQUERY_TIMEOUTThevalidationQueryTimeoutproperty name.protected static java.lang.StringPROP_VALIDATOR_CLASS_NAMEThevalidatorClassNameproperty name.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.protected javax.sql.DataSourcecreateDataSource(java.util.Properties properties, javax.naming.Context context, boolean XA, java.lang.Object dataSourceObject)Creates and configures aDataSourceinstance based on the given properties, with an optional live data source for the pool to wrap.java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment)Creates and returns the pooled data source that the givenReferencedescribes: anDataSource, or anXADataSourcewhen the reference namesjavax.sql.XADataSourceor the pool's own XA class.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
ThedefaultAutoCommitproperty name.- See Also:
- Constant Field Values
-
PROP_DEFAULTREADONLY
protected static final java.lang.String PROP_DEFAULTREADONLY
ThedefaultReadOnlyproperty name.- See Also:
- Constant Field Values
-
PROP_DEFAULTTRANSACTIONISOLATION
protected static final java.lang.String PROP_DEFAULTTRANSACTIONISOLATION
ThedefaultTransactionIsolationproperty name.- See Also:
- Constant Field Values
-
PROP_DEFAULTCATALOG
protected static final java.lang.String PROP_DEFAULTCATALOG
ThedefaultCatalogproperty name.- See Also:
- Constant Field Values
-
PROP_DRIVERCLASSNAME
protected static final java.lang.String PROP_DRIVERCLASSNAME
ThedriverClassNameproperty name.- See Also:
- Constant Field Values
-
PROP_PASSWORD
protected static final java.lang.String PROP_PASSWORD
Thepasswordproperty name.- See Also:
- Constant Field Values
-
PROP_URL
protected static final java.lang.String PROP_URL
Theurlproperty name.- See Also:
- Constant Field Values
-
PROP_USERNAME
protected static final java.lang.String PROP_USERNAME
Theusernameproperty name.- See Also:
- Constant Field Values
-
PROP_MAXACTIVE
protected static final java.lang.String PROP_MAXACTIVE
ThemaxActiveproperty name.- See Also:
- Constant Field Values
-
PROP_MAXIDLE
protected static final java.lang.String PROP_MAXIDLE
ThemaxIdleproperty name.- See Also:
- Constant Field Values
-
PROP_MINIDLE
protected static final java.lang.String PROP_MINIDLE
TheminIdleproperty name.- See Also:
- Constant Field Values
-
PROP_INITIALSIZE
protected static final java.lang.String PROP_INITIALSIZE
TheinitialSizeproperty name.- See Also:
- Constant Field Values
-
PROP_MAXWAIT
protected static final java.lang.String PROP_MAXWAIT
ThemaxWaitproperty name.- See Also:
- Constant Field Values
-
PROP_MAXAGE
protected static final java.lang.String PROP_MAXAGE
ThemaxAgeproperty name.- See Also:
- Constant Field Values
-
PROP_TESTONBORROW
protected static final java.lang.String PROP_TESTONBORROW
ThetestOnBorrowproperty name.- See Also:
- Constant Field Values
-
PROP_TESTONRETURN
protected static final java.lang.String PROP_TESTONRETURN
ThetestOnReturnproperty name.- See Also:
- Constant Field Values
-
PROP_TESTWHILEIDLE
protected static final java.lang.String PROP_TESTWHILEIDLE
ThetestWhileIdleproperty name.- See Also:
- Constant Field Values
-
PROP_TESTONCONNECT
protected static final java.lang.String PROP_TESTONCONNECT
ThetestOnConnectproperty name.- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY
protected static final java.lang.String PROP_VALIDATIONQUERY
ThevalidationQueryproperty name.- See Also:
- Constant Field Values
-
PROP_VALIDATIONQUERY_TIMEOUT
protected static final java.lang.String PROP_VALIDATIONQUERY_TIMEOUT
ThevalidationQueryTimeoutproperty name.- See Also:
- Constant Field Values
-
PROP_VALIDATOR_CLASS_NAME
protected static final java.lang.String PROP_VALIDATOR_CLASS_NAME
ThevalidatorClassNameproperty name.- See Also:
- Constant Field Values
-
PROP_NUMTESTSPEREVICTIONRUN
protected static final java.lang.String PROP_NUMTESTSPEREVICTIONRUN
ThenumTestsPerEvictionRunproperty name.- See Also:
- Constant Field Values
-
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
protected static final java.lang.String PROP_TIMEBETWEENEVICTIONRUNSMILLIS
ThetimeBetweenEvictionRunsMillisproperty name.- See Also:
- Constant Field Values
-
PROP_MINEVICTABLEIDLETIMEMILLIS
protected static final java.lang.String PROP_MINEVICTABLEIDLETIMEMILLIS
TheminEvictableIdleTimeMillisproperty name.- See Also:
- Constant Field Values
-
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
protected static final java.lang.String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
TheaccessToUnderlyingConnectionAllowedproperty name.- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONED
protected static final java.lang.String PROP_REMOVEABANDONED
TheremoveAbandonedproperty name.- See Also:
- Constant Field Values
-
PROP_REMOVEABANDONEDTIMEOUT
protected static final java.lang.String PROP_REMOVEABANDONEDTIMEOUT
TheremoveAbandonedTimeoutproperty name.- See Also:
- Constant Field Values
-
PROP_LOGABANDONED
protected static final java.lang.String PROP_LOGABANDONED
ThelogAbandonedproperty name.- See Also:
- Constant Field Values
-
PROP_ABANDONWHENPERCENTAGEFULL
protected static final java.lang.String PROP_ABANDONWHENPERCENTAGEFULL
TheabandonWhenPercentageFullproperty name.- See Also:
- Constant Field Values
-
PROP_POOLPREPAREDSTATEMENTS
protected static final java.lang.String PROP_POOLPREPAREDSTATEMENTS
ThepoolPreparedStatementsproperty name.- See Also:
- Constant Field Values
-
PROP_MAXOPENPREPAREDSTATEMENTS
protected static final java.lang.String PROP_MAXOPENPREPAREDSTATEMENTS
ThemaxOpenPreparedStatementsproperty name.- See Also:
- Constant Field Values
-
PROP_CONNECTIONPROPERTIES
protected static final java.lang.String PROP_CONNECTIONPROPERTIES
TheconnectionPropertiesproperty name.- See Also:
- Constant Field Values
-
PROP_INITSQL
protected static final java.lang.String PROP_INITSQL
TheinitSQLproperty name.- See Also:
- Constant Field Values
-
PROP_INTERCEPTORS
protected static final java.lang.String PROP_INTERCEPTORS
ThejdbcInterceptorsproperty name.- See Also:
- Constant Field Values
-
PROP_VALIDATIONINTERVAL
protected static final java.lang.String PROP_VALIDATIONINTERVAL
ThevalidationIntervalproperty name.- See Also:
- Constant Field Values
-
PROP_JMX_ENABLED
protected static final java.lang.String PROP_JMX_ENABLED
ThejmxEnabledproperty name.- See Also:
- Constant Field Values
-
PROP_FAIR_QUEUE
protected static final java.lang.String PROP_FAIR_QUEUE
ThefairQueueproperty name.- See Also:
- Constant Field Values
-
PROP_USE_EQUALS
protected static final java.lang.String PROP_USE_EQUALS
TheuseEqualsproperty name.- See Also:
- Constant Field Values
-
PROP_USE_LOCK
protected static final java.lang.String PROP_USE_LOCK
TheuseLockproperty name.- See Also:
- Constant Field Values
-
PROP_DATASOURCE
protected static final java.lang.String PROP_DATASOURCE
ThedataSourceproperty name.- See Also:
- Constant Field Values
-
PROP_DATASOURCE_JNDI
protected static final java.lang.String PROP_DATASOURCE_JNDI
ThedataSourceJNDIproperty name.- See Also:
- Constant Field Values
-
PROP_SUSPECT_TIMEOUT
protected static final java.lang.String PROP_SUSPECT_TIMEOUT
ThesuspectTimeoutproperty name.- See Also:
- Constant Field Values
-
PROP_ALTERNATE_USERNAME_ALLOWED
protected static final java.lang.String PROP_ALTERNATE_USERNAME_ALLOWED
ThealternateUsernameAllowedproperty name.- See Also:
- Constant Field Values
-
PROP_COMMITONRETURN
protected static final java.lang.String PROP_COMMITONRETURN
ThecommitOnReturnproperty name.- See Also:
- Constant Field Values
-
PROP_ROLLBACKONRETURN
protected static final java.lang.String PROP_ROLLBACKONRETURN
TherollbackOnReturnproperty name.- See Also:
- Constant Field Values
-
PROP_USEDISPOSABLECONNECTIONFACADE
protected static final java.lang.String PROP_USEDISPOSABLECONNECTIONFACADE
Property name for useDisposableConnectionFacade. The property is deprecated and has no effect; the disposable connection facade is always used.- See Also:
- Constant Field Values
-
PROP_LOGVALIDATIONERRORS
protected static final java.lang.String PROP_LOGVALIDATIONERRORS
ThelogValidationErrorsproperty name.- See Also:
- Constant Field Values
-
PROP_PROPAGATEINTERRUPTSTATE
protected static final java.lang.String PROP_PROPAGATEINTERRUPTSTATE
ThepropagateInterruptStateproperty name.- See Also:
- Constant Field Values
-
PROP_IGNOREEXCEPTIONONPRELOAD
protected static final java.lang.String PROP_IGNOREEXCEPTIONONPRELOAD
TheignoreExceptionOnPreLoadproperty name.- See Also:
- Constant Field Values
-
PROP_USESTATEMENTFACADE
protected static final java.lang.String PROP_USESTATEMENTFACADE
Property name for useStatementFacade. The property is deprecated and has no effect; the statement facade is always used.- 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.ExceptionCreates and returns the pooled data source that the given
Referencedescribes: anDataSource, or anXADataSourcewhen the reference namesjavax.sql.XADataSourceor the pool's own XA class.- 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- Returns:
- the configured data source, or
nullifobjis not aReferenceor names a class this factory does not build (the latter is logged) - Throws:
java.lang.IllegalArgumentException- if an attribute carries a value its property cannot take: an unusable boolean, numeric or transaction-isolation value, or adataSourceattribute holding a String or another connection pooljavax.naming.NamingException- if the name given by thedataSourceJNDIattribute does not resolve to a data source that can back the pooljava.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.A blank attribute value - empty or whitespace only, the shape a cleared template attribute yields - leaves the property at its
PoolPropertiesdefault. A value the property cannot take fails the parse naming the attribute, rather than being silently dropped the way unparsed values used to be. Numeric, boolean, transaction-isolation and class-name (driverClassNameandvalidatorClassName) attributes apply their trimmed value, and so does the lookup of the name given bydataSourceJNDI: whitespace around a number, a keyword or a class or JNDI name is always noise. Other string values are stored verbatim - a catalog, a validation query, a credential or a URL can legitimately carry surrounding whitespace.Two attributes are not plain property assignments:
connectionPropertiesis resolved into the driver properties throughPoolProperties.setConnectionProperties(String), andusername/passwordare merged into that same driver property set afterwards, so credentials configured as their own attributes override auserorpasswordpair insideconnectionProperties.- Parameters:
properties- The properties to parse- Returns:
- The configured PoolConfiguration
- Throws:
java.lang.IllegalArgumentException- if an attribute carries a value its property cannot take
-
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
-
createDataSource
protected javax.sql.DataSource createDataSource(java.util.Properties properties, javax.naming.Context context, boolean XA, java.lang.Object dataSourceObject) throws java.lang.ExceptionCreates and configures aDataSourceinstance based on the given properties, with an optional live data source for the pool to wrap.When
dataSourceObjectis notnull, it is set on the pool configuration before the pool is created, and thedataSourceJNDIlookup is skipped: the pool is built around the object that was handed to the factory directly. The object is one of the data source types the pool's connect path accepts (javax.sql.DataSource,javax.sql.XADataSourceorjavax.sql.ConnectionPoolDataSource), not necessarily ajavax.sql.DataSource.- Parameters:
properties- The datasource configuration propertiescontext- The JNDI contextXA-trueto create an XA data sourcedataSourceObject- A live data source object the pool should wrap, ornull- 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) throws javax.naming.NamingExceptionPerform a JNDI lookup for the data source.- Parameters:
context- The JNDI contextpoolProperties- The pool configuration- Throws:
javax.naming.NamingException- if the name configured through the dataSourceJNDI property cannot be resolved, or resolves to an object the pool cannot create connections from. The name was configured specifically to supply the connections for the pool, so a pool without that data source is not a usable fallback and the failure is reported instead of being deferred to the first connection request.
-
getProperties
protected static java.util.Properties getProperties(java.lang.String propText)
Parse properties from the string. Format of the string must be [propertyName=property;]*.Kept as a protected extension point for subclasses that parse property strings of their own; this factory no longer calls it, as its
connectionPropertiesattribute goes through the canonicalPoolProperties.setConnectionProperties(String), which parses with the same delegate used here.- Parameters:
propText- The properties string- Returns:
- the properties
-
-