Class XADataSource
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.DataSourceProxy
-
- org.apache.tomcat.jdbc.pool.DataSource
-
- org.apache.tomcat.jdbc.pool.XADataSource
-
- All Implemented Interfaces:
java.sql.Wrapper,javax.management.MBeanRegistration,javax.sql.CommonDataSource,javax.sql.ConnectionPoolDataSource,javax.sql.DataSource,javax.sql.XADataSource,ConnectionPoolMBean,PoolConfiguration
public class XADataSource extends DataSource implements javax.sql.XADataSource
XA-enabled data source for distributed transaction support.Note that XA support is not provided by this class itself: XA capability comes from the data source configured through the
dataSourceordataSourceJNDIattribute, which must implementXADataSource(seePoolConfiguration.setDataSource(Object)). A pool configured with onlydriverClassNameandurlpools 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
getXAConnectionmethods return is nevertheless not that configured data source's own handle: it is a session borrowed from the pool, whoseclose()returns the session to the pool instead of closing the physical connection. The deviations from thejavax.sqlcontract that follow from this are stated on those methods.
-
-
Field Summary
-
Fields inherited from class org.apache.tomcat.jdbc.pool.DataSource
oname
-
Fields inherited from class org.apache.tomcat.jdbc.pool.DataSourceProxy
pool, poolProperties
-
Fields inherited from interface org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean
FAILED_QUERY_NOTIFICATION, NOTIFY_ABANDON, NOTIFY_CONNECT, NOTIFY_INIT, POOL_EMPTY, SLOW_QUERY_NOTIFICATION, SUSPECT_ABANDONED_NOTIFICATION, SUSPECT_RETURNED_NOTIFICATION
-
Fields inherited from interface org.apache.tomcat.jdbc.pool.PoolConfiguration
PKG_PREFIX
-
-
Constructor Summary
Constructors Constructor Description XADataSource()Constructor for reflection only.XADataSource(PoolConfiguration poolProperties)Constructs a DataSource object wrapping a connection
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.sql.XAConnectiongetXAConnection()Get a database connection.javax.sql.XAConnectiongetXAConnection(java.lang.String username, java.lang.String password)Get a database connection.-
Methods inherited from class org.apache.tomcat.jdbc.pool.DataSource
close, createObjectName, postDeregister, postRegister, preDeregister, preRegister, publishJmx, registerJmx, unregisterJmx
-
Methods inherited from class org.apache.tomcat.jdbc.pool.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, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLogger
-
Methods inherited from interface javax.sql.ConnectionPoolDataSource
createPooledConnectionBuilder, getLoginTimeout, getLogWriter, getPooledConnection, getPooledConnection, setLoginTimeout, setLogWriter
-
Methods inherited from interface org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean
checkAbandoned, checkIdle, getActive, getBorrowedCount, getCreatedCount, getIdle, getNumActive, getNumIdle, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getReturnedCount, getSize, getWaitCount, purge, purgeOnReturn, resetStats, testIdle
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
-
Methods inherited from interface org.apache.tomcat.jdbc.pool.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, setValidatorClassName
-
-
-
-
Constructor Detail
-
XADataSource
public XADataSource()
Constructor for reflection only. A default set of pool properties will be created.
-
XADataSource
public XADataSource(PoolConfiguration poolProperties)
Constructs a DataSource object wrapping a connection- Parameters:
poolProperties- The pool configuration
-
-
Method Detail
-
getXAConnection
public javax.sql.XAConnection getXAConnection() throws java.sql.SQLExceptionGet 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 interfacejavax.sql.XADataSource- Overrides:
getXAConnectionin classDataSourceProxy- Returns:
- the connection
- Throws:
java.sql.SQLException- Connection error
-
getXAConnection
public javax.sql.XAConnection getXAConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLExceptionGet 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 interfacejavax.sql.XADataSource- Overrides:
getXAConnectionin classDataSourceProxy- Parameters:
username- The user namepassword- The password- Returns:
- the connection
- Throws:
java.sql.SQLException- Connection error
-
-