bitronix.tm.resource.jdbc
Class PoolingDataSource

java.lang.Object
  extended by bitronix.tm.resource.common.ResourceBean
      extended by bitronix.tm.resource.jdbc.PoolingDataSource
All Implemented Interfaces:
XAResourceProducer, java.io.Serializable, java.sql.Wrapper, javax.naming.Referenceable, javax.sql.CommonDataSource, javax.sql.DataSource

public class PoolingDataSource
extends ResourceBean
implements javax.sql.DataSource, XAResourceProducer

Implementation of a JDBC DataSource wrapping vendor's XADataSource implementation.

© Bitronix Software

Author:
lorban
See Also:
Serialized Form

Constructor Summary
PoolingDataSource()
           
 
Method Summary
 void close()
          Release this XAResourceProducer's internal resources.
 java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements)
           
 java.sql.Blob createBlob()
           
 java.sql.Clob createClob()
           
 java.sql.NClob createNClob()
           
 XAStatefulHolder createPooledConnection(java.lang.Object xaFactory, ResourceBean bean)
          Create a XAStatefulHolder that will be placed in an XAPool.
 java.sql.SQLXML createSQLXML()
           
 java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes)
           
 void endRecovery()
          Release internal resources held after call to startRecovery().
 XAResourceHolder findXAResourceHolder(javax.transaction.xa.XAResource xaResource)
          Find in the XAResourceHolders created by this XAResourceProducer the one which this XAResource belongs to.
 java.util.Properties getClientInfo()
           
 java.lang.String getClientInfo(java.lang.String name)
           
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
 java.lang.String getIsolationLevel()
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 int getPreparedStatementCacheSize()
           
 javax.naming.Reference getReference()
          PoolingDataSource must alway have a unique name so this method builds a reference to this object using the unique name as RefAddr.
 java.lang.String getTestQuery()
           
 void init()
          Initializes the pool by creating the initial amount of connections.
 boolean isValid(int timeout)
           
 boolean isWrapperFor(java.lang.Class iface)
           
 void setClientInfo(java.util.Properties properties)
           
 void setClientInfo(java.lang.String name, java.lang.String value)
           
 void setFailed(boolean failed)
          Mark this resource producer as failed or not.
 void setIsolationLevel(java.lang.String isolationLevel)
           
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter out)
           
 void setPreparedStatementCacheSize(int preparedStatementCacheSize)
           
 void setTestQuery(java.lang.String testQuery)
          When set, the specified query will be executed on the connection acquired from the pool before being handed to the caller.
 XAResourceHolderState startRecovery()
          Prepare the recoverable XAResource producer for recovery.
 java.lang.String toString()
           
 java.lang.Object unwrap(java.lang.Class iface)
           
 
Methods inherited from class bitronix.tm.resource.common.ResourceBean
getAcquireIncrement, getAcquisitionInterval, getAcquisitionTimeout, getAllowLocalTransactions, getApplyTransactionTimeout, getAutomaticEnlistingEnabled, getClassName, getDeferConnectionRelease, getDriverProperties, getMaxIdleTime, getMaxPoolSize, getMinPoolSize, getTwoPcOrderingPosition, getUniqueName, getUseTmJoin, incCreatedResourcesCounter, setAcquireIncrement, setAcquisitionInterval, setAcquisitionTimeout, setAllowLocalTransactions, setApplyTransactionTimeout, setAutomaticEnlistingEnabled, setClassName, setDeferConnectionRelease, setDriverProperties, setMaxIdleTime, setMaxPoolSize, setMinPoolSize, setTwoPcOrderingPosition, setUniqueName, setUseTmJoin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface bitronix.tm.resource.common.XAResourceProducer
getUniqueName
 

Constructor Detail

PoolingDataSource

public PoolingDataSource()
Method Detail

init

public void init()
Initializes the pool by creating the initial amount of connections.

Specified by:
init in interface XAResourceProducer

getTestQuery

public java.lang.String getTestQuery()
Returns:
the query that will be used to test connections.

setTestQuery

public void setTestQuery(java.lang.String testQuery)
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.

getPreparedStatementCacheSize

public int getPreparedStatementCacheSize()

setPreparedStatementCacheSize

public void setPreparedStatementCacheSize(int preparedStatementCacheSize)

getIsolationLevel

public java.lang.String getIsolationLevel()

setIsolationLevel

public void setIsolationLevel(java.lang.String isolationLevel)

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

startRecovery

public XAResourceHolderState startRecovery()
                                    throws RecoveryException
Description copied from interface: XAResourceProducer
Prepare the recoverable XAResource producer for recovery.

Specified by:
startRecovery in interface XAResourceProducer
Returns:
a XAResourceHolderState object that can be used to call recover().
Throws:
RecoveryException - thrown when a XAResourceHolderState cannot be acquired.

endRecovery

public void endRecovery()
                 throws RecoveryException
Description copied from interface: XAResourceProducer
Release internal resources held after call to startRecovery().

Specified by:
endRecovery in interface XAResourceProducer
Throws:
RecoveryException - thrown when an error occured while releasing reserved resources.

setFailed

public void setFailed(boolean failed)
Description copied from interface: XAResourceProducer
Mark this resource producer as failed or not. A resource is considered failed if recovery fails to run on it.

Specified by:
setFailed in interface XAResourceProducer
Parameters:
failed - true is the resource must be considered failed, false it it must be considered sane.

close

public void close()
Description copied from interface: XAResourceProducer
Release this XAResourceProducer's internal resources.

Specified by:
close in interface XAResourceProducer

createPooledConnection

public XAStatefulHolder createPooledConnection(java.lang.Object xaFactory,
                                               ResourceBean bean)
                                        throws java.lang.Exception
Description copied from interface: XAResourceProducer
Create a XAStatefulHolder that will be placed in an XAPool.

Specified by:
createPooledConnection in interface XAResourceProducer
Parameters:
xaFactory - the vendor's resource-specific XA factory.
bean - the resource-specific bean describing the resource parameters.
Returns:
a XAStatefulHolder that will be placed in an XAPool.
Throws:
java.lang.Exception - thrown when the XAStatefulHolder cannot be created.

findXAResourceHolder

public XAResourceHolder findXAResourceHolder(javax.transaction.xa.XAResource xaResource)
Description copied from interface: XAResourceProducer
Find in the XAResourceHolders created by this XAResourceProducer the one which this XAResource belongs to.

Specified by:
findXAResourceHolder in interface XAResourceProducer
Parameters:
xaResource - the XAResource to look for.
Returns:
the associated XAResourceHolder or null if the XAResource does not belong to this XAResourceProducer.

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
PoolingDataSource must alway have a unique name so this method builds a reference to this object using the unique name as RefAddr.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
a reference to this PoolingDataSource.
Throws:
javax.naming.NamingException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

createClob

public java.sql.Clob createClob()
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

createBlob

public java.sql.Blob createBlob()
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

createNClob

public java.sql.NClob createNClob()
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

createSQLXML

public java.sql.SQLXML createSQLXML()
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

isValid

public boolean isValid(int timeout)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

setClientInfo

public void setClientInfo(java.lang.String name,
                          java.lang.String value)
                   throws java.sql.SQLClientInfoException
Throws:
java.sql.SQLClientInfoException

setClientInfo

public void setClientInfo(java.util.Properties properties)
                   throws java.sql.SQLClientInfoException
Throws:
java.sql.SQLClientInfoException

getClientInfo

public java.lang.String getClientInfo(java.lang.String name)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

getClientInfo

public java.util.Properties getClientInfo()
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

createArrayOf

public java.sql.Array createArrayOf(java.lang.String typeName,
                                    java.lang.Object[] elements)
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

createStruct

public java.sql.Struct createStruct(java.lang.String typeName,
                                    java.lang.Object[] attributes)
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

unwrap

public java.lang.Object unwrap(java.lang.Class iface)
                        throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException