Class DataSourceFactory
- All Implemented Interfaces:
ObjectFactory
JNDI object factory that creates an instance of
DataSource - or XADataSource, when the
reference names a type to be built as XA - configured from the RefAddr
values of the specified Reference. Address names are matched against the
pool properties listed in ALL_PROPERTIES; they are the attributes of the
pool documented with PoolConfiguration'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 PoolProperties default, and a value the
property cannot take fails the lookup with an exception naming the attribute
instead of being silently ignored. The legacy settings
numTestsPerEvictionRun, accessToUnderlyingConnectionAllowed,
poolPreparedStatements and maxOpenPreparedStatements are 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
FieldsModifier and TypeFieldDescriptionprotected static final String[]Array of all supported property names.static final StringProperty name for the JMX object name.protected static final StringTheabandonWhenPercentageFullproperty name.protected static final StringTheaccessToUnderlyingConnectionAllowedproperty name.protected static final StringThealternateUsernameAllowedproperty name.protected static final StringThecommitOnReturnproperty name.protected static final StringTheconnectionPropertiesproperty name.protected static final StringThedataSourceproperty name.protected static final StringThedataSourceJNDIproperty name.protected static final StringThedefaultAutoCommitproperty name.protected static final StringThedefaultCatalogproperty name.protected static final StringThedefaultReadOnlyproperty name.protected static final StringThedefaultTransactionIsolationproperty name.protected static final StringThedriverClassNameproperty name.protected static final StringThefairQueueproperty name.protected static final StringTheignoreExceptionOnPreLoadproperty name.protected static final StringTheinitialSizeproperty name.protected static final StringTheinitSQLproperty name.protected static final StringThejdbcInterceptorsproperty name.protected static final StringThejmxEnabledproperty name.protected static final StringThelogAbandonedproperty name.protected static final StringThelogValidationErrorsproperty name.protected static final StringThemaxActiveproperty name.protected static final StringThemaxAgeproperty name.protected static final StringThemaxIdleproperty name.protected static final StringThemaxOpenPreparedStatementsproperty name.protected static final StringThemaxWaitproperty name.protected static final StringTheminEvictableIdleTimeMillisproperty name.protected static final StringTheminIdleproperty name.protected static final StringThenumTestsPerEvictionRunproperty name.protected static final StringThepasswordproperty name.protected static final StringThepoolPreparedStatementsproperty name.protected static final StringThepropagateInterruptStateproperty name.protected static final StringTheremoveAbandonedproperty name.protected static final StringTheremoveAbandonedTimeoutproperty name.protected static final StringTherollbackOnReturnproperty name.protected static final StringThesuspectTimeoutproperty name.protected static final StringThetestOnBorrowproperty name.protected static final StringThetestOnConnectproperty name.protected static final StringThetestOnReturnproperty name.protected static final StringThetestWhileIdleproperty name.protected static final StringThetimeBetweenEvictionRunsMillisproperty name.protected static final StringTheurlproperty name.protected static final StringTheuseEqualsproperty name.protected static final StringTheuseLockproperty name.protected static final StringProperty name for useDisposableConnectionFacade.protected static final StringTheusernameproperty name.protected static final StringProperty name for useStatementFacade.protected static final StringThevalidationIntervalproperty name.protected static final StringThevalidationQueryproperty name.protected static final StringThevalidationQueryTimeoutproperty name.protected static final StringThevalidatorClassNameproperty name.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.protected DataSourcecreateDataSource(Properties properties, Context context, boolean XA, Object dataSourceObject) Creates and configures aDataSourceinstance based on the given properties, with an optional live data source for the pool to wrap.getObjectInstance(Object obj, Name name, Context nameCtx, 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 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
ThedefaultTransactionIsolationproperty name.- 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
ThevalidationQueryTimeoutproperty name.- See Also:
-
PROP_VALIDATOR_CLASS_NAME
ThevalidatorClassNameproperty name.- See Also:
-
PROP_NUMTESTSPEREVICTIONRUN
ThenumTestsPerEvictionRunproperty name.- See Also:
-
PROP_TIMEBETWEENEVICTIONRUNSMILLIS
ThetimeBetweenEvictionRunsMillisproperty name.- See Also:
-
PROP_MINEVICTABLEIDLETIMEMILLIS
TheminEvictableIdleTimeMillisproperty name.- See Also:
-
PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED
TheaccessToUnderlyingConnectionAllowedproperty name.- See Also:
-
PROP_REMOVEABANDONED
-
PROP_REMOVEABANDONEDTIMEOUT
TheremoveAbandonedTimeoutproperty name.- See Also:
-
PROP_LOGABANDONED
-
PROP_ABANDONWHENPERCENTAGEFULL
TheabandonWhenPercentageFullproperty name.- See Also:
-
PROP_POOLPREPAREDSTATEMENTS
ThepoolPreparedStatementsproperty name.- See Also:
-
PROP_MAXOPENPREPAREDSTATEMENTS
ThemaxOpenPreparedStatementsproperty name.- See Also:
-
PROP_CONNECTIONPROPERTIES
TheconnectionPropertiesproperty name.- See Also:
-
PROP_INITSQL
-
PROP_INTERCEPTORS
-
PROP_VALIDATIONINTERVAL
ThevalidationIntervalproperty name.- See Also:
-
PROP_JMX_ENABLED
-
PROP_FAIR_QUEUE
-
PROP_USE_EQUALS
-
PROP_USE_LOCK
-
PROP_DATASOURCE
-
PROP_DATASOURCE_JNDI
-
PROP_SUSPECT_TIMEOUT
-
PROP_ALTERNATE_USERNAME_ALLOWED
ThealternateUsernameAllowedproperty name.- See Also:
-
PROP_COMMITONRETURN
-
PROP_ROLLBACKONRETURN
-
PROP_USEDISPOSABLECONNECTIONFACADE
Property name for useDisposableConnectionFacade. The property is deprecated and has no effect; the disposable connection facade is always used.- See Also:
-
PROP_LOGVALIDATIONERRORS
ThelogValidationErrorsproperty name.- See Also:
-
PROP_PROPAGATEINTERRUPTSTATE
ThepropagateInterruptStateproperty name.- See Also:
-
PROP_IGNOREEXCEPTIONONPRELOAD
TheignoreExceptionOnPreLoadproperty name.- See Also:
-
PROP_USESTATEMENTFACADE
Property name for useStatementFacade. The property is deprecated and has no effect; the statement facade is always used.- 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 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 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- Returns:
- the configured data source, or
nullifobjis not aReferenceor names a class this factory does not build (the latter is logged) - Throws:
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 poolNamingException- if the name given by thedataSourceJNDIattribute does not resolve to a data source that can back the poolException- if an exception occurs creating the instance
-
parsePoolProperties
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:
IllegalArgumentException- if an attribute carries a value its property cannot take
-
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
-
createDataSource
protected DataSource createDataSource(Properties properties, Context context, boolean XA, Object dataSourceObject) throws Exception Creates 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:
Exception- if an error occurs creating the data source
-
performJNDILookup
public void performJNDILookup(Context context, PoolConfiguration poolProperties) throws NamingException Perform a JNDI lookup for the data source.- Parameters:
context- The JNDI contextpoolProperties- The pool configuration- Throws:
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
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
-