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 capability comes 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.
What the getXAConnection methods return is nevertheless not that configured data source's own handle: it is
a session borrowed from the pool, whose close() returns the session to the pool instead of closing the
physical connection. The deviations from the javax.sql contract that follow from this are stated on those
methods.
-
Field Summary
Fields inherited from class DataSource
onameFields inherited from class DataSourceProxy
pool, poolPropertiesFields inherited from interface ConnectionPoolMBean
FAILED_QUERY_NOTIFICATION, NOTIFY_ABANDON, NOTIFY_CONNECT, NOTIFY_INIT, POOL_EMPTY, SLOW_QUERY_NOTIFICATION, SUSPECT_ABANDONED_NOTIFICATION, SUSPECT_RETURNED_NOTIFICATIONFields inherited from interface PoolConfiguration
PKG_PREFIX -
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, publishJmx, registerJmx, unregisterJmxMethods inherited from class DataSourceProxy
checkAbandoned, checkIdle, close, closePool, 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, takePoolForClose, testIdle, toString, unwrapMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilder, getParentLoggerMethods inherited from interface ConnectionPoolDataSource
createPooledConnectionBuilder, getLoginTimeout, getLogWriter, getPooledConnection, getPooledConnection, setLoginTimeout, setLogWriterMethods inherited from interface ConnectionPoolMBean
checkAbandoned, checkIdle, getActive, getBorrowedCount, getCreatedCount, getIdle, getNumActive, getNumIdle, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getReturnedCount, getSize, getWaitCount, purge, purgeOnReturn, resetStats, testIdleMethods inherited from interface DataSource
createConnectionBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriterMethods inherited from interface PoolConfiguration
getAbandonWhenPercentageFull, getCommitOnReturn, getConnectionProperties, getDataSource, getDataSourceJNDI, getDbProperties, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassName, getInitialSize, getInitSQL, getJdbcInterceptors, getJdbcInterceptorsAsArray, getLogValidationErrors, getMaxActive, getMaxAge, getMaxIdle, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getName, getNumTestsPerEvictionRun, getPassword, getPoolName, getPropagateInterruptState, getRemoveAbandonedTimeout, getRollbackOnReturn, getSuspectTimeout, getTimeBetweenEvictionRunsMillis, getUrl, getUseDisposableConnectionFacade, getUseLock, getUsername, getUseStatementFacade, getValidationInterval, getValidationQuery, getValidationQueryTimeout, getValidator, getValidatorClassName, isAccessToUnderlyingConnectionAllowed, isAlternateUsernameAllowed, isDefaultAutoCommit, isDefaultReadOnly, isFairQueue, isIgnoreExceptionOnPreLoad, isJmxEnabled, isLogAbandoned, isPoolSweeperEnabled, isRemoveAbandoned, isTestOnBorrow, isTestOnConnect, isTestOnReturn, isTestWhileIdle, isUseEquals, setAbandonWhenPercentageFull, setAccessToUnderlyingConnectionAllowed, setAlternateUsernameAllowed, setCommitOnReturn, setConnectionProperties, setDataSource, setDataSourceJNDI, setDbProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassName, setFairQueue, setIgnoreExceptionOnPreLoad, setInitialSize, setInitSQL, setJdbcInterceptors, setJmxEnabled, setLogAbandoned, setLogValidationErrors, setMaxActive, setMaxAge, setMaxIdle, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setName, setNumTestsPerEvictionRun, setPassword, setPropagateInterruptState, setRemoveAbandoned, setRemoveAbandonedTimeout, setRollbackOnReturn, setSuspectTimeout, setTestOnBorrow, setTestOnConnect, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUseDisposableConnectionFacade, setUseEquals, setUseLock, setUsername, setUseStatementFacade, setValidationInterval, setValidationQuery, setValidationQueryTimeout, setValidator, setValidatorClassNameMethods inherited from interface Wrapper
isWrapperFor, unwrapMethods inherited from interface XADataSource
createXAConnectionBuilder, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
-
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.
Deviation from the
javax.sqlcontract: the returnedXAConnectionis a handle borrowed from the pool, not a freshly opened physical connection, so under load this call blocks waiting for a free session or fails with pool exhaustion rather than with a database error. Itsclose()returns the session to the pool instead of closing the physical connection; every XA branch started through the returnedXAResourcemust therefore be completed - committed or rolled back - beforeclose(), and neither the handle nor itsXAResourcemay be used after it. A handle closed while a branch stands unresolved is not returned to the pool: the pool's return-time rollback unwinds only local work and can never resolve a branch that stands prepared, so the pool closes the session instead of handing another borrower a connection that carries that branch and the database locks held for it. The transaction manager's late commit or rollback of the abandoned branch then fails against the closed session rather than landing, silently, on a session that does not carry it.The connection obtained from the returned handle's
PooledConnection.getConnection()is the driver's raw logical session, not a pool-managed connection: the pool's interceptors and features do not apply to it, and closing it invalidates the session under the pool's own notion of a live connection. Release the borrowed session by closing the handle, not that connection.- 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. The returned handle deviates from the
javax.sqlcontract as described ongetXAConnection(), and carries one deviation of its own: the given credentials are honored only whenalternateUsernameAllowedis enabled, which it is not by default; otherwise the borrow proceeds under the pool's configured user name, exactly asDataSourceProxy.getConnection(String, String)does, and every XA branch started through this handle'sXAResourceruns under that identity, not the one passed in here.- Specified by:
getXAConnectionin interfaceXADataSource- Overrides:
getXAConnectionin classDataSourceProxy- Parameters:
username- The user namepassword- The password- Returns:
- the connection
- Throws:
SQLException- Connection error
-