Package bitronix.tm.resource.jdbc
Class PoolingDataSource
java.lang.Object
bitronix.tm.resource.common.ResourceBean
bitronix.tm.resource.jdbc.PoolingDataSource
- All Implemented Interfaces:
XAResourceProducer,PoolingDataSourceMBean,Serializable,Wrapper,Referenceable,CommonDataSource,DataSource
public class PoolingDataSource
extends ResourceBean
implements DataSource, XAResourceProducer, PoolingDataSourceMBean
Implementation of a JDBC
DataSource wrapping vendor's XADataSource implementation.- Author:
- lorban, brettw
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnectionCustomizer(ConnectionCustomizer connectionCustomizer) voidclose()Release thisXAResourceProducer's internal resources.createPooledConnection(Object xaFactory, ResourceBean bean) Create aXAStatefulHolderthat will be placed in anXAPool.voidRelease internal resources held after call tostartRecovery().findXAResourceHolder(XAResource xaResource) Find in theXAResourceHolders created by thisXAResourceProducerthe one which thisXAResourcebelongs to.getConnection(String username, String password) longintintPoolingDataSourcemust alway have a unique name so this method builds a reference to this object using the unique name asRefAddr.longvoidinit()Initializes the pool by creating the initial amount of connections.booleanbooleanisFailed()booleanisWrapperFor(Class<?> iface) voidremoveConnectionCustomizer(ConnectionCustomizer connectionCustomizer) voidreset()voidsetCursorHoldability(String cursorHoldability) Set the default cursor holdability for connections.voidsetEnableJdbc4ConnectionTest(boolean enableJdbc4ConnectionTest) When set and the underlying JDBC driver supports JDBC 4 isValid(), a Connection.isValid() call is performed to test the connection before handing it to the caller.voidsetFailed(boolean failed) Mark this resource producer as failed or not.voidsetIsolationLevel(String isolationLevel) Set the default isolation level for connections.voidsetLocalAutoCommit(String localAutoCommit) Set the default local transactions autocommit mode.voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter out) voidsetPreparedStatementCacheSize(int preparedStatementCacheSize) Set the target maximum size of the prepared statement cache.voidsetTestQuery(String testQuery) When set, the specified query will be executed on the connection acquired from the pool before being handed to the caller.Prepare the recoverableXAResourceproducer for recovery.toString()<T> TMethods inherited from class bitronix.tm.resource.common.ResourceBean
getAcquireIncrement, getAcquisitionInterval, getAcquisitionTimeout, getAllowLocalTransactions, getApplyTransactionTimeout, getAutomaticEnlistingEnabled, getClassName, getDeferConnectionRelease, getDriverProperties, getIgnoreRecoveryFailures, getMaxIdleTime, getMaxPoolSize, getMinPoolSize, getShareTransactionConnections, getTwoPcOrderingPosition, getUniqueName, getUseTmJoin, incCreatedResourcesCounter, isDisabled, setAcquireIncrement, setAcquisitionInterval, setAcquisitionTimeout, setAllowLocalTransactions, setApplyTransactionTimeout, setAutomaticEnlistingEnabled, setClassName, setDeferConnectionRelease, setDisabled, setDriverProperties, setIgnoreRecoveryFailures, setMaxIdleTime, setMaxPoolSize, setMinPoolSize, setShareTransactionConnections, setTwoPcOrderingPosition, setUniqueName, setUseTmJoinMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilderMethods inherited from interface bitronix.tm.resource.jdbc.PoolingDataSourceMBean
getMaxPoolSize, getMinPoolSize, isDisabled, setDisabledMethods inherited from interface bitronix.tm.resource.common.XAResourceProducer
getUniqueName
-
Constructor Details
-
PoolingDataSource
public PoolingDataSource() -
PoolingDataSource
-
-
Method Details
-
init
public void init()Initializes the pool by creating the initial amount of connections.- Specified by:
initin interfaceXAResourceProducer
-
getTestQuery
- Returns:
- the query that will be used to test connections.
-
setTestQuery
When set, the specified query will be executed on the connection acquired from the pool before being handed to the caller. The connections won't be tested when not set. Default value is null.- Parameters:
testQuery- the query that will be used to test connections.
-
setEnableJdbc4ConnectionTest
public void setEnableJdbc4ConnectionTest(boolean enableJdbc4ConnectionTest) When set and the underlying JDBC driver supports JDBC 4 isValid(), a Connection.isValid() call is performed to test the connection before handing it to the caller. If both testQuery and enableJdbc4ConnectionTest are set, enableJdbc4ConnectionTest takes precedence.- Parameters:
enableJdbc4ConnectionTest- true if JDBC 4 isValid() testing should be performed, false otherwise.
-
isEnableJdbc4ConnectionTest
public boolean isEnableJdbc4ConnectionTest()- Returns:
- true if JDBC 4 isValid() testing should be performed, false otherwise.
-
getPreparedStatementCacheSize
public int getPreparedStatementCacheSize()- Returns:
- the target maximum prepared statement cache size.
-
setPreparedStatementCacheSize
public void setPreparedStatementCacheSize(int preparedStatementCacheSize) Set the target maximum size of the prepared statement cache. In reality under certain unusual conditions the cache may temporarily drift higher in size.- Parameters:
preparedStatementCacheSize- the target maximum prepared statement cache size.
-
getIsolationLevel
- Returns:
- the default isolation level.
-
setIsolationLevel
Set the default isolation level for connections.- Parameters:
isolationLevel- the default isolation level.
-
getCursorHoldability
- Returns:
- cursorHoldability the default cursor holdability.
-
setCursorHoldability
Set the default cursor holdability for connections.- Parameters:
cursorHoldability- the default cursor holdability.
-
getLocalAutoCommit
- Returns:
- localAutoCommit the default local transactions autocommit mode.
-
setLocalAutoCommit
Set the default local transactions autocommit mode.- Parameters:
localAutoCommit- the default local transactions autocommit mode.
-
addConnectionCustomizer
-
removeConnectionCustomizer
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
toString
-
startRecovery
Description copied from interface:XAResourceProducerPrepare the recoverableXAResourceproducer for recovery.- Specified by:
startRecoveryin interfaceXAResourceProducer- Returns:
- a
XAResourceHolderStateobject that can be used to callrecover(). - Throws:
RecoveryException- thrown when aXAResourceHolderStatecannot be acquired.
-
endRecovery
Description copied from interface:XAResourceProducerRelease internal resources held after call tostartRecovery().- Specified by:
endRecoveryin interfaceXAResourceProducer- Throws:
RecoveryException- thrown when an error occured while releasing reserved resources.
-
setFailed
public void setFailed(boolean failed) Description copied from interface:XAResourceProducerMark this resource producer as failed or not. A resource is considered failed if recovery fails to run on it.- Specified by:
setFailedin interfaceXAResourceProducer- Parameters:
failed- true is the resource must be considered failed, false it it must be considered sane.
-
isFailed
public boolean isFailed()- Specified by:
isFailedin interfacePoolingDataSourceMBean
-
close
public void close()Description copied from interface:XAResourceProducerRelease thisXAResourceProducer's internal resources.- Specified by:
closein interfaceXAResourceProducer
-
createPooledConnection
public XAStatefulHolder createPooledConnection(Object xaFactory, ResourceBean bean) throws Exception Description copied from interface:XAResourceProducerCreate aXAStatefulHolderthat will be placed in anXAPool.- Specified by:
createPooledConnectionin interfaceXAResourceProducer- Parameters:
xaFactory- the vendor's resource-specific XA factory.bean- the resource-specific bean describing the resource parameters.- Returns:
- a
XAStatefulHolderthat will be placed in anXAPool. - Throws:
Exception- thrown when theXAStatefulHoldercannot be created.
-
findXAResourceHolder
Description copied from interface:XAResourceProducerFind in theXAResourceHolders created by thisXAResourceProducerthe one which thisXAResourcebelongs to.- Specified by:
findXAResourceHolderin interfaceXAResourceProducer- Parameters:
xaResource- theXAResourceto look for.- Returns:
- the associated
XAResourceHolderor null if theXAResourcedoes not belong to thisXAResourceProducer.
-
getReference
PoolingDataSourcemust alway have a unique name so this method builds a reference to this object using the unique name asRefAddr.- Specified by:
getReferencein interfaceReferenceable- Returns:
- a reference to this
PoolingDataSource. - Throws:
NamingException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
getInPoolSize
public long getInPoolSize()- Specified by:
getInPoolSizein interfacePoolingDataSourceMBean
-
getTotalPoolSize
public long getTotalPoolSize()- Specified by:
getTotalPoolSizein interfacePoolingDataSourceMBean
-
reset
- Specified by:
resetin interfacePoolingDataSourceMBean- Throws:
Exception
-