Class XADataSource
- All Implemented Interfaces:
Wrapper, MBeanRegistration, CommonDataSource, ConnectionPoolDataSource, DataSource, XADataSource, ConnectionPoolMBean, PoolConfiguration
Note that XA support is not provided by this class itself: XA connections are obtained from the data source
configured through the dataSource or dataSourceJNDI attribute, which must implement
XADataSource (see PoolConfiguration.setDataSource(Object)). A pool configured with only
driverClassName and url pools plain JDBC connections; a request for an XA connection from such a pool
fails with an explicit message naming the missing configuration rather than later, inside the transaction manager.
-
Field Summary
Fields inherited from class DataSource
onameModifier and TypeFieldDescriptionprotected ObjectNameThe JMX ObjectName for the connection pool MBean.Fields inherited from class DataSourceProxy
pool, poolPropertiesModifier and TypeFieldDescriptionprotected ConnectionPoolThe underlying connection pool.protected PoolConfigurationThe pool configuration properties.Fields inherited from interface ConnectionPoolMBean
FAILED_QUERY_NOTIFICATION, NOTIFY_ABANDON, NOTIFY_CONNECT, NOTIFY_INIT, POOL_EMPTY, SLOW_QUERY_NOTIFICATION, SUSPECT_ABANDONED_NOTIFICATION, SUSPECT_RETURNED_NOTIFICATIONModifier and TypeFieldDescriptionstatic final StringNotification type sent when theSlowQueryReportJmxinterceptor reports a query that failed.static final StringNotification type sent when a connection that has been checked out longer than the remove-abandoned timeout is abandoned and removed from the pool.static final StringNotification type sent when the pool cannot establish a physical connection to the database.static final StringNotification type sent when the initialization of the pool fails, because an interceptor could not be started or because an initial connection of the pool could not be created and the failure is not ignored throughignoreExceptionOnPreLoad.static final StringNotification type sent when a borrow from the pool fails because the pool is empty: the borrower was not willing to wait for a connection or its wait timed out.static final StringNotification type sent when theSlowQueryReportJmxinterceptor reports a query that took longer than its configured threshold.static final StringNotification type sent when the pool marks a connection as suspect because it has been checked out longer than the suspect timeout and is therefore suspected of having been abandoned.static final StringNotification type sent when a connection that the pool had marked as suspect is returned to the pool.Fields inherited from interface PoolConfiguration
PKG_PREFIXModifier and TypeFieldDescriptionstatic final StringJMX prefix for interceptors that register themselves with JMX -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for reflection only.XADataSource(PoolConfiguration poolProperties) Constructs a DataSource object wrapping a connection -
Method Summary
Modifier and TypeMethodDescriptionGet a database connection.getXAConnection(String username, String password) Get a database connection.Methods inherited from class DataSource
close, createObjectName, postDeregister, postRegister, preDeregister, preRegister, registerJmx, unregisterJmxModifier and TypeMethodDescriptionvoidclose(boolean all) Unregisters the connection pool MBean before closing the pool, so a dead pool does not keep reporting stale statistics under a live object name (and does not pin the closed pool, its credentials and its JDBC driver class loader in the MBean server).
Close the connection pool.createObjectName(ObjectName original) Creates the ObjectName for the ConnectionPoolMBean object to be registeredvoidUnregisters the underlying connection pool mbean.
voidpostRegister(Boolean registrationDone) Releases the pool MBean thatDataSource.preRegister(MBeanServer, ObjectName)published when the MBean server did not complete this DataSource's own registration.voidno-op
preRegister(MBeanServer server, ObjectName name) If the connection pool MBean exists, it will be registered during this operation.
protected voidRegisters the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource.protected voidunregisterJmx(ObjectName name) Unregisters the ConnectionPoolMBean published under the given name.Methods inherited from class DataSourceProxy
checkAbandoned, checkIdle, close, createPool, getAbandonWhenPercentageFull, getActive, getBorrowedCount, getCommitOnReturn, getConnection, getConnection, getConnectionAsync, getConnectionProperties, getCreatedCount, getDataSource, getDataSourceJNDI, getDbProperties, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassName, getIdle, getInitialSize, getInitSQL, getJdbcInterceptors, getJdbcInterceptorsAsArray, getLoginTimeout, getLogValidationErrors, getLogWriter, getMaxActive, getMaxAge, getMaxIdle, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getName, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getPassword, getPool, getPooledConnection, getPooledConnection, getPoolName, getPoolProperties, getPoolSize, getPropagateInterruptState, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getRemoveAbandonedTimeout, getReturnedCount, getRollbackOnReturn, getSize, getSuspectTimeout, getTimeBetweenEvictionRunsMillis, getUrl, getUseDisposableConnectionFacade, getUseLock, getUsername, getUseStatementFacade, getValidationInterval, getValidationQuery, getValidationQueryTimeout, getValidator, getValidatorClassName, getWaitCount, isAccessToUnderlyingConnectionAllowed, isAlternateUsernameAllowed, isDefaultAutoCommit, isDefaultReadOnly, isFairQueue, isIgnoreExceptionOnPreLoad, isJmxEnabled, isLogAbandoned, isPoolSweeperEnabled, isRemoveAbandoned, isTestOnBorrow, isTestOnConnect, isTestOnReturn, isTestWhileIdle, isUseEquals, isWrapperFor, purge, purgeOnReturn, resetStats, setAbandonWhenPercentageFull, setAccessToUnderlyingConnectionAllowed, setAlternateUsernameAllowed, setCommitOnReturn, setConnectionProperties, setDataSource, setDataSourceJNDI, setDbProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassName, setFairQueue, setIgnoreExceptionOnPreLoad, setInitialSize, setInitSQL, setJdbcInterceptors, setJmxEnabled, setLogAbandoned, setLoginTimeout, setLogValidationErrors, setLogWriter, setMaxActive, setMaxAge, setMaxIdle, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setName, setNumTestsPerEvictionRun, setPassword, setPoolProperties, setPropagateInterruptState, setRemoveAbandoned, setRemoveAbandonedTimeout, setRollbackOnReturn, setSuspectTimeout, setTestOnBorrow, setTestOnConnect, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUseDisposableConnectionFacade, setUseEquals, setUseLock, setUsername, setUseStatementFacade, setValidationInterval, setValidationQuery, setValidationQueryTimeout, setValidator, setValidatorClassName, testIdle, toString, unwrapModifier and TypeMethodDescriptionvoidForces an abandon check on the connection pool.voidForces a check for resizing of the idle connectionsvoidclose()Close the connection pool, returning connections to the database.Sets up the connection pool, by creating a pooling driver.intConnections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.intReturns the number of connections currently in use by the application.longThe total number of connections borrowed from this pool.booleanReturns whether the pool commits any pending transaction when a connection is returned.Get a database connection.getConnection(String username, String password) Get a database connection.Invokes an sync operation to retrieve the connection.The connection properties that will be sent to the JDBC driver when establishing new connections.longThe total number of connections created by this pool.Returns a datasource, if one exists that is being used to create connections.Returns the JNDI string configured for data source usage.Returns a copy of the database properties with the password removed.The default auto-commit state of connections created by this pool.If non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value.If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.intReturns the default transaction isolation level.The fully qualified Java class name of the JDBC driver to be used.intgetIdle()If the pool has not been created, it will be created during this call.intReturns the number of connections that will be established when the connection pool is started.A custom query to be run when a connection is first created.A semicolon separated list of classnames extendingJdbcInterceptorclass.Returns thePoolConfiguration.getJdbcInterceptors()as an array of objects with properties and the classes.intbooleanReturns true if errors that happen during validation will be loggedintThe maximum number of active connections that can be allocated from this pool at the same time.longTime in milliseconds to keep this connection before reconnecting.intThe maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false.intThe maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception.intThe minimum amount of time an object must sit idle in the pool before it is eligible for eviction.intThe minimum number of established connections that should be kept in the pool at all times.getName()Returns the name of the connection pool.intReturns the number of connections currently in use by the application.intintProperty not usedReturns the password used when establishing connections to the database.getPool()Return the underlying connection pool, creating it if necessary.Get a database connection.getPooledConnection(String username, String password) Get a database connection.Returns the name of the connection pool.Return the pool configuration properties.intReturn the current number of connections in the pool.booleanReturns true if the pool is configured to propagate interrupt state of a thread.longThe total number of connections reconnected by this pool.longThe total number of connections released from this pool.longThe total number of connections released by eviction.longThe total number of connections released by remove abandoned.intThe time in seconds before a connection can be considered abandoned.longThe total number of connections returned to this pool.booleanReturns whether the pool rolls back any pending transaction when a connection is returned.intgetSize()Returns the current total number of connections in the pool.intReturns the time in seconds to pass before a connection is marked an abandoned suspect.intThe number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.getUrl()The URL used to connect to the databasebooleanDeprecated.The disposable connection facade is always used, so this property no longer has any effect.booleanReturn true if a lock should be used when operations are performed on the connection object.Returns the username used to establish the connection withbooleanDeprecated.The statement facade is always used, so this property no longer has any effect.longavoid excess validation, only run validation at most at this frequency - time in milliseconds.The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.intThe timeout in seconds before a connection validation queries fail.Returns the validator object used for connection validation.Return the name of the optional validator class - may be null.intReturns the number of threads currently waiting for a connection from the pool.booleanProperty not used.booleanReturns true if the callgetConnection(username,password)is allowed.The default auto-commit state of connections created by this pool.If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.booleanReturnstrueif a fair queue is being used by the connection poolbooleanReturns whether exceptions during connection creation at pool initialization should be ignored.booleanIf set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool.booleanboolean flag to set if stack traces should be logged for application code which abandoned a Connection.booleanReturns true if the pool sweeper is enabled for the connection pool.booleanboolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.booleanThe indication of whether objects will be validated before being borrowed from the pool.booleanReturns true if we should run the validation query when connecting to the database for the first time on a connection.booleanThe indication of whether objects will be validated after being returned to the pool.booleanSet to true if query validation should take place while the connection is idle.booleanSet to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names.booleanisWrapperFor(Class<?> iface) Check if this proxy implements, or wraps an instance of, the given interface.voidpurge()Purge all connections from the pool.voidEnable purging of connections on return to the pool.voidreset the statistics of this pool.voidsetAbandonWhenPercentageFull(int percentage) Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.voidsetAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) No-opvoidsetAlternateUsernameAllowed(boolean alternateUsernameAllowed) Set to true if the callgetConnection(username,password)is allowed and honored..voidsetCommitOnReturn(boolean commitOnReturn) Set to true if you want the connection pool to commit any pending transaction when a connection is returned.voidsetConnectionProperties(String properties) The properties that will be passed intoDriver.connect(String, Properties)method.voidsetDataSource(Object ds) Injects a datasource that will be used to retrieve/create connections.voidsetDataSourceJNDI(String jndiDS) Configure the connection pool to use a DataSource according toPoolConfiguration.setDataSource(Object)But instead of injecting the object, specify the JNDI location.voidsetDbProperties(Properties dbProperties) Overrides the database properties passed into theDriver.connect(String, Properties)method.voidsetDefaultAutoCommit(Boolean autocommit) The default auto-commit state of connections created by this pool.voidsetDefaultCatalog(String catalog) If non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value.voidsetDefaultReadOnly(Boolean defaultReadOnly) If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.voidsetDefaultTransactionIsolation(int defaultTransactionIsolation) If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONthe methodConnection.setTransactionIsolation(int)will not be called during connection creation.voidsetDriverClassName(String driverClassName) The fully qualified Java class name of the JDBC driver to be used.voidsetFairQueue(boolean fairQueue) Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion.voidsetIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad) Set to true if you want to ignore error of connection creation while initializing the pool.voidsetInitialSize(int initialSize) Set the number of connections that will be established when the connection pool is started.voidsetInitSQL(String initSQL) A custom query to be run when a connection is first created.voidsetJdbcInterceptors(String interceptors) A semicolon separated list of classnames extendingJdbcInterceptorclass.voidsetJmxEnabled(boolean enabled) If set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool.voidsetLogAbandoned(boolean logAbandoned) boolean flag to set if stack traces should be logged for application code which abandoned a Connection.voidsetLoginTimeout(int i) voidsetLogValidationErrors(boolean logValidationErrors) Set to true if you wish that errors from validation should be logged as error messages.voidsetLogWriter(PrintWriter out) voidsetMaxActive(int maxActive) The maximum number of active connections that can be allocated from this pool at the same time.voidsetMaxAge(long maxAge) Time in milliseconds to keep this connection before reconnecting.voidsetMaxIdle(int maxIdle) The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false.voidsetMaxWait(int maxWait) The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception.voidsetMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.voidsetMinIdle(int minIdle) The minimum number of established connections that should be kept in the pool at all times.voidSets the name of the connection poolvoidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun) Property not usedvoidsetPassword(String password) Sets the password used to establish connections with, and mirrors it into thepassworddatabase property.voidsetPoolProperties(PoolConfiguration poolProperties) Set the pool configuration properties directly.voidsetPropagateInterruptState(boolean propagateInterruptState) Configure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aPoolExhaustedExceptionIf set to true, this behavior will change, while thePoolExhaustedExceptionis still thrown, the threads interrupted state is still set.voidsetRemoveAbandoned(boolean removeAbandoned) boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.voidsetRemoveAbandonedTimeout(int removeAbandonedTimeout) The time in seconds before a connection can be considered abandoned.voidsetRollbackOnReturn(boolean rollbackOnReturn) Set to true if you want the connection pool to rollback any pending transaction when a connection is returned.voidsetSuspectTimeout(int seconds) Similar toPoolConfiguration.setRemoveAbandonedTimeout(int)but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning ifPoolConfiguration.isLogAbandoned()returns true.voidsetTestOnBorrow(boolean testOnBorrow) The indication of whether objects will be validated before being borrowed from the pool.voidsetTestOnConnect(boolean testOnConnect) Set to true if we should run the validation query when connecting to the database for the first time on a connection.voidsetTestOnReturn(boolean testOnReturn) The indication of whether objects will be validated after being returned to the pool.voidsetTestWhileIdle(boolean testWhileIdle) Set to true if query validation should take place while the connection is idle.voidsetTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.voidSets the URL used to connect to the databasevoidsetUseDisposableConnectionFacade(boolean useDisposableConnectionFacade) Deprecated.The disposable connection facade is always used, so this property no longer has any effect.voidsetUseEquals(boolean useEquals) Set to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names.voidsetUseLock(boolean useLock) Set to true if a lock should be used when operations are performed on the connection object.voidsetUsername(String username) Sets the user name used to establish connections with, and mirrors it into theuserdatabase property.voidsetUseStatementFacade(boolean useStatementFacade) Deprecated.The statement facade is always used, so this property no longer has any effect.voidsetValidationInterval(long validationInterval) avoid excess validation, only run validation at most at this frequency - time in milliseconds.voidsetValidationQuery(String validationQuery) The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.voidsetValidationQueryTimeout(int validationQueryTimeout) The timeout in seconds before a connection validation queries fail.voidsetValidator(Validator validator) Sets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.voidsetValidatorClassName(String className) Set the name for an optional validator class which will be used in place of test queries.voidtestIdle()Performs a validation on idle connections.toString()<T> TUnwrap the proxy to the given interface.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CommonDataSource
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriterMethods inherited from interface ConnectionPoolDataSource
getPooledConnection, getPooledConnectionMethods inherited from interface ConnectionPoolMBean
checkAbandoned, checkIdle, getActive, getBorrowedCount, getCreatedCount, getIdle, getNumActive, getNumIdle, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getReturnedCount, getSize, getWaitCount, purge, purgeOnReturn, resetStats, testIdleModifier and TypeMethodDescriptionvoidChecks for and removes abandoned connections from the pool.voidChecks and cleans up idle connections in the pool.intReturns the number of active (in-use) connections.longReturns the total number of connections borrowed since pool creation.longReturns the total number of connections created since pool creation.intgetIdle()Returns the number of idle connections in the pool.intReturns the number of active (in-use) connections.intReturns the number of idle connections in the pool.longReturns the total number of reconnections since pool creation.longReturns the total number of connections released since pool creation.longReturns the total number of idle connections released by the pool cleaner.longReturns the total number of connections removed due to abandonment.longReturns the total number of connections returned since pool creation.intgetSize()Returns the total number of connections in the pool.intReturns the number of threads waiting for a connection.voidpurge()Purges all connections in the pool.voidPurges connections when they are returned from the pool.voidreset the statistics of this pool.voidtestIdle()Validates all idle connections in the pool.Methods inherited from interface DataSource
getConnection, getConnectionMethods inherited from interface Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
XADataSource
public XADataSource()Constructor for reflection only. A default set of pool properties will be created. -
XADataSource
Constructs a DataSource object wrapping a connection- Parameters:
poolProperties- The pool configuration
-
-
Method Details
-
getXAConnection
Get a database connection.XADataSource.getXAConnection()This implementation first checks that the pool can provide XA connections at all, and fails with an explicit configuration hint when it cannot.
- Specified by:
getXAConnectionin interfaceXADataSource- Overrides:
getXAConnectionin classDataSourceProxy- Returns:
- the connection
- Throws:
SQLException- Connection error
-
getXAConnection
Get a database connection.XADataSource.getXAConnection(String, String)This implementation first checks that the pool can provide XA connections at all, and fails with an explicit configuration hint when it cannot.
- Specified by:
getXAConnectionin interfaceXADataSource- Overrides:
getXAConnectionin classDataSourceProxy- Parameters:
username- The user namepassword- The password- Returns:
- the connection
- Throws:
SQLException- Connection error
-