tyrex.resource.jdbc.xa
Class XADataSourceImpl

java.lang.Object
  extended bytyrex.resource.jdbc.xa.XADataSourceImpl
All Implemented Interfaces:
javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, java.lang.Runnable, java.io.Serializable, javax.sql.XADataSource
Direct Known Subclasses:
EnabledDataSource

public abstract class XADataSourceImpl
extends java.lang.Object
implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource, java.io.Serializable, java.lang.Runnable

Implements a JDBC 2.0 XADataSource for any JDBC driver with JNDI persistance support. The base implementation is actually provided by a different DataSource class; although this is the super class, it only provides the pooling and XA specific implementation.

Version:
1.0
Author:
Assaf Arkin
See Also:
Serialized Form

Field Summary
static int DEFAULT_ISOLATION_LEVEL
          The default isolation level is Read Committed
static int DEFAULT_TX_TIMEOUT
          The default timeout for all new transactions is 10 seconds.
 
Constructor Summary
XADataSourceImpl()
          Implementation details: If two XAConnections are associated with the same transaction (one with a start the other with a join) they must use the same underlying JDBC connection.
 
Method Summary
 void debug(java.io.PrintWriter writer)
           
 boolean getIgnoreIsolationLevel()
          Return true if the isolation level is ignored so that the isolation level is never set on the underlying JDBC connection.
 int getIsolationLevel()
          Returns the transaction isolation level to use with all newly created transactions.
abstract  java.io.PrintWriter getLogWriter()
          This method is defined in the interface and implemented in the derived class, we re-define it just to make sure it does not throw an SQLException and that we do not need to catch one.
 javax.sql.PooledConnection getPooledConnection()
           
 javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password)
           
 float getPruneFactor()
          Get the factor that specifies the number of connections that are released from the pool.
 int getTransactionTimeout()
          Returns the default timeout for all transactions.
(package private)  TxConnection getTxConnection(javax.transaction.xa.Xid xid)
          Returns an underlying connection for the global transaction, if one has been associated before.
(package private)  javax.transaction.xa.Xid[] getTxRecover()
          XXX Not fully implemented yet and no code to really test it.
 javax.sql.XAConnection getXAConnection()
           
 javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password)
           
(package private)  java.sql.Connection newConnection(java.lang.String userName, java.lang.String password)
          Creates a new underlying connection.
(package private)  void releaseConnection(java.sql.Connection conn, java.lang.String userName, java.lang.String password)
          Release an unused connection back to the pool.
 void run()
           
 void setIgnoreIsolationLevel(boolean ignoreIsolationLevel)
          Tell the data source whether to ignore the isolation level on the underlying JDBC connection.
 void setIsolationLevel(int isolationLevel)
          Set the transaction isolation level to use with all newly created transactions.
 void setPruneFactor(float pruneFactor)
          Set the factor that specifies the number of connections that are released from the pool.
 void setTransactionTimeout(int seconds)
          Sets the default timeout for all new transactions.
(package private)  TxConnection setTxConnection(javax.transaction.xa.Xid xid, TxConnection txConn)
          Associates the global transaction with an underlying connection, or dissociate it when null is passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.sql.DataSource
getConnection, getConnection, getLoginTimeout, setLoginTimeout, setLogWriter
 
Methods inherited from interface javax.sql.ConnectionPoolDataSource
getLoginTimeout, setLoginTimeout, setLogWriter
 
Methods inherited from interface javax.sql.XADataSource
getLoginTimeout, setLoginTimeout, setLogWriter
 

Field Detail

DEFAULT_TX_TIMEOUT

public static final int DEFAULT_TX_TIMEOUT
The default timeout for all new transactions is 10 seconds.

See Also:
Constant Field Values

DEFAULT_ISOLATION_LEVEL

public static final int DEFAULT_ISOLATION_LEVEL
The default isolation level is Read Committed

See Also:
Constant Field Values
Constructor Detail

XADataSourceImpl

public XADataSourceImpl()
Implementation details: If two XAConnections are associated with the same transaction (one with a start the other with a join) they must use the same underlying JDBC connection. They lookup the underlying JDBC connection based on the transaction's Xid in the originating XADataSource. Currently the XADataSource must be the exact same object, this should be changed so all XADataSources that are equal share a table of all enlisted connections To test is two connections should fall under the same transaction we match the resource managers by comparing the database/user they fall under using a comparison of the XADataSource properties.

Method Detail

getXAConnection

public javax.sql.XAConnection getXAConnection()
                                       throws java.sql.SQLException
Specified by:
getXAConnection in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

getXAConnection

public javax.sql.XAConnection getXAConnection(java.lang.String user,
                                              java.lang.String password)
                                       throws java.sql.SQLException
Specified by:
getXAConnection in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

getPooledConnection

public javax.sql.PooledConnection getPooledConnection()
                                               throws java.sql.SQLException
Specified by:
getPooledConnection in interface javax.sql.ConnectionPoolDataSource
Throws:
java.sql.SQLException

getPooledConnection

public javax.sql.PooledConnection getPooledConnection(java.lang.String user,
                                                      java.lang.String password)
                                               throws java.sql.SQLException
Specified by:
getPooledConnection in interface javax.sql.ConnectionPoolDataSource
Throws:
java.sql.SQLException

getTransactionTimeout

public final int getTransactionTimeout()
Returns the default timeout for all transactions.

Returns:
the default timeout for all transactions.

getLogWriter

public abstract java.io.PrintWriter getLogWriter()
This method is defined in the interface and implemented in the derived class, we re-define it just to make sure it does not throw an SQLException and that we do not need to catch one.

Specified by:
getLogWriter in interface javax.sql.DataSource

setTransactionTimeout

public final void setTransactionTimeout(int seconds)
Sets the default timeout for all new transactions. The timeout is specified in seconds. Use zero or less for the default timeout.

Parameters:
seconds - The timeout in seconds

getTxConnection

TxConnection getTxConnection(javax.transaction.xa.Xid xid)
Returns an underlying connection for the global transaction, if one has been associated before.

Parameters:
xid - The transaction Xid
Returns:
A connection associated with that transaction, or null

setTxConnection

TxConnection setTxConnection(javax.transaction.xa.Xid xid,
                             TxConnection txConn)
Associates the global transaction with an underlying connection, or dissociate it when null is passed.

Parameters:
xid - The transaction Xid

releaseConnection

void releaseConnection(java.sql.Connection conn,
                       java.lang.String userName,
                       java.lang.String password)
Release an unused connection back to the pool. If an XA connection has been asked to join an existing transaction, it will no longer use it's own connection and make it available to newly created connections.

Parameters:
conn - An open connection that is no longer in use
userName - the user name for the connection
password - the password for the connection

newConnection

java.sql.Connection newConnection(java.lang.String userName,
                                  java.lang.String password)
                            throws java.sql.SQLException
Creates a new underlying connection. Used by XA connection that lost it's underlying connection when joining a transaction and is now asked to produce a new connection.

Parameters:
userName - the userName
password - the password
Returns:
An open connection ready for use
Throws:
java.sql.SQLException - An error occured trying to open a connection

getTxRecover

javax.transaction.xa.Xid[] getTxRecover()
XXX Not fully implemented yet and no code to really test it.


getIgnoreIsolationLevel

public final boolean getIgnoreIsolationLevel()
Return true if the isolation level is ignored so that the isolation level is never set on the underlying JDBC connection. This is useful for those JDBC connection that do not support isolation levels at all. However the transaction isolation level can be set directly on the connection which is outside of the control of this method, for now.

Returns:
true if the isolation level is ignored
See Also:
getIsolationLevel(), setIsolationLevel(int)

setIgnoreIsolationLevel

public final void setIgnoreIsolationLevel(boolean ignoreIsolationLevel)
Tell the data source whether to ignore the isolation level on the underlying JDBC connection. This is useful for those JDBC connection that do not support isolation levels at all. However the transaction isolation level can be set directly on the connection which is outside of the control of this method, for now.

Parameters:
ignoreIsolationLevel - true if the isolation level is ignored
See Also:
getIsolationLevel(), setIsolationLevel(int)

getIsolationLevel

public final int getIsolationLevel()
Returns the transaction isolation level to use with all newly created transactions. If the method getIgnoreIsolationLevel() returns true the isloation level is ignored.

Returns:
the transaction isolation level to use with all newly created transactions
See Also:
getIgnoreIsolationLevel(), setIgnoreIsolationLevel(boolean)

setIsolationLevel

public final void setIsolationLevel(int isolationLevel)
Set the transaction isolation level to use with all newly created transactions. If the method getIgnoreIsolationLevel() returns true the isloation level is ignored.

The isolation level of java.sql.Connection.TRANSACTION_NONE is not supported.

Parameters:
isolationLevel - the new isolation level
Throws:
java.lang.IllegalArgumentException - if the specified isolation level is not one of the following java.sql.Connection.TRANSACTION_READ_UNCOMMITTED, java.sql.Connection.TRANSACTION_READ_COMMITTED, java.sql.Connection.TRANSACTION_REPEATABLE_READ, java.sql.Connection.TRANSACTION_SERIALIZABLE
See Also:
getIgnoreIsolationLevel(), setIgnoreIsolationLevel(boolean)

getPruneFactor

public final float getPruneFactor()
Get the factor that specifies the number of connections that are released from the pool.

Returns:
the prune factor

setPruneFactor

public final void setPruneFactor(float pruneFactor)
Set the factor that specifies the number of connections that are released from the pool.

Parameters:
pruneFactor - the prune factor. 0 <= pruneFactor <= 1

run

public void run()
Specified by:
run in interface java.lang.Runnable

debug

public void debug(java.io.PrintWriter writer)


Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.