tyrex.resource.jdbc.xa

Class XADataSourceImpl

public abstract class XADataSourceImpl extends Object implements DataSource, ConnectionPoolDataSource, XADataSource, Serializable, 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

Field Summary
static intDEFAULT_ISOLATION_LEVEL
The default isolation level is Read Committed
static intDEFAULT_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
voiddebug(PrintWriter writer)
booleangetIgnoreIsolationLevel()
Return true if the isolation level is ignored so that the isolation level is never set on the underlying JDBC connection.
intgetIsolationLevel()
Returns the transaction isolation level to use with all newly created transactions.
abstract PrintWritergetLogWriter()
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.
PooledConnectiongetPooledConnection()
PooledConnectiongetPooledConnection(String user, String password)
floatgetPruneFactor()
Get the factor that specifies the number of connections that are released from the pool.
intgetTransactionTimeout()
Returns the default timeout for all transactions.
TxConnectiongetTxConnection(Xid xid)
Returns an underlying connection for the global transaction, if one has been associated before.
Xid[]getTxRecover()
XXX Not fully implemented yet and no code to really test it.
XAConnectiongetXAConnection()
XAConnectiongetXAConnection(String user, String password)
ConnectionnewConnection(String userName, String password)
Creates a new underlying connection.
voidreleaseConnection(Connection conn, String userName, String password)
Release an unused connection back to the pool.
voidrun()
voidsetIgnoreIsolationLevel(boolean ignoreIsolationLevel)
Tell the data source whether to ignore the isolation level on the underlying JDBC connection.
voidsetIsolationLevel(int isolationLevel)
Set the transaction isolation level to use with all newly created transactions.
voidsetPruneFactor(float pruneFactor)
Set the factor that specifies the number of connections that are released from the pool.
voidsetTransactionTimeout(int seconds)
Sets the default timeout for all new transactions.
TxConnectionsetTxConnection(Xid xid, TxConnection txConn)
Associates the global transaction with an underlying connection, or dissociate it when null is passed.

Field Detail

DEFAULT_ISOLATION_LEVEL

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

DEFAULT_TX_TIMEOUT

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

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

debug

public void debug(PrintWriter writer)

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: XADataSourceImpl XADataSourceImpl

getIsolationLevel

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

Returns: the transaction isolation level to use with all newly created transactions

See Also: XADataSourceImpl XADataSourceImpl

getLogWriter

public abstract 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.

getPooledConnection

public PooledConnection getPooledConnection()

getPooledConnection

public PooledConnection getPooledConnection(String user, String password)

getPruneFactor

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

Returns: the prune factor

getTransactionTimeout

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

Returns: the default timeout for all transactions.

getTxConnection

TxConnection getTxConnection(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

getTxRecover

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

getXAConnection

public XAConnection getXAConnection()

getXAConnection

public XAConnection getXAConnection(String user, String password)

newConnection

Connection newConnection(String userName, String password)
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: SQLException An error occured trying to open a connection

releaseConnection

void releaseConnection(Connection conn, String userName, 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

run

public void run()

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: XADataSourceImpl XADataSourceImpl

setIsolationLevel

public final void setIsolationLevel(int isolationLevel)
Set the transaction isolation level to use with all newly created transactions. If the method XADataSourceImpl 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: 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: XADataSourceImpl XADataSourceImpl

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

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

setTxConnection

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

Parameters: xid The transaction Xid conn The connection to associate, null to dissociate

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.