tyrex.resource.jdbc.xa
Class XAConnectionImpl

java.lang.Object
  extended bytyrex.resource.jdbc.xa.XAConnectionImpl
All Implemented Interfaces:
javax.sql.PooledConnection, javax.sql.XAConnection, javax.transaction.xa.XAResource

public final class XAConnectionImpl
extends java.lang.Object
implements javax.sql.XAConnection, javax.transaction.xa.XAResource

Implements an X/A connection that can be pooled and managed from inside a transaction monitor. This is the XA connection returned to the application server from the XADataSourceImpl and will be used to obtain ClientConnection for the application.

If the transaction is managed through the JDBC interface, this connection will reference the underlying JDBC connection directly. If this resource is enlisted with a global transaction through the XAResource interface, it will reference a transactional connection, or TxConnection. Such a connection may be shared by two or more XA connections enlisted with the same transaction.

Version:
1.0
Author:
Assaf Arkin
See Also:
ClientConnection, ConnectionEventListener, TxConnection

Field Summary
(package private)  java.sql.Connection _underlying
          This is the underlying JDBC connection represented by this pooled connection.
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
(package private) XAConnectionImpl(XADataSourceImpl resManager, java.sql.Connection underlying, java.lang.String userName, java.lang.String password)
          Construct a new XA/pooled connection with the underlying JDBC connection suitable for this driver only.
 
Method Summary
 void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
           
 void close()
           
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
           
 void end(javax.transaction.xa.Xid xid, int flags)
           
protected  void finalize()
           
 void forget(javax.transaction.xa.Xid xid)
           
 java.sql.Connection getConnection()
           
 int getTransactionTimeout()
           
(package private)  java.sql.Connection getUnderlying(int clientId)
          Called to obtain the underlying connections.
 javax.transaction.xa.XAResource getXAResource()
           
(package private)  boolean insideGlobalTx()
          Returns true if this connection is inside a global transaction.
 boolean isSameRM(javax.transaction.xa.XAResource xaRes)
           
(package private)  void notifyClose(int clientId)
          Called by ClientConnection to notify that the application has attempted to close the connection.
(package private)  void notifyError(int clientId, java.sql.SQLException except)
          Called by ClientConnection to notify that an error occured with the underlying connection.
 int prepare(javax.transaction.xa.Xid xid)
           
 javax.transaction.xa.Xid[] recover(int flags)
           
 void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
           
 void rollback(javax.transaction.xa.Xid xid)
           
 boolean setTransactionTimeout(int seconds)
           
 void start(javax.transaction.xa.Xid xid, int flags)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_underlying

java.sql.Connection _underlying
This is the underlying JDBC connection represented by this pooled connection. This variable may initially be null, in which case getUnderlying(int) will return a new connection and set this variable. This variable is mutually exclusive with #_txConn and is always null for connections inside a transaction.

Constructor Detail

XAConnectionImpl

XAConnectionImpl(XADataSourceImpl resManager,
                 java.sql.Connection underlying,
                 java.lang.String userName,
                 java.lang.String password)
           throws java.sql.SQLException
Construct a new XA/pooled connection with the underlying JDBC connection suitable for this driver only. This is a one to one mapping between this connection and the underlying connection. The underlying connection is provided for pooled connections. XA connections are suspect of being enlisted with a global transaction which might already bear an underlying connection. If not, one will be created later on.

Parameters:
resManager - the resource manager for the underlying connections
underlying - the underlying connection. Can be null.
userName - the user name for the underlying connection. Can be null.
password - the password for the underlying connection. Can be null.
Method Detail

close

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

getXAResource

public javax.transaction.xa.XAResource getXAResource()
Specified by:
getXAResource in interface javax.sql.XAConnection

addConnectionEventListener

public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
Specified by:
addConnectionEventListener in interface javax.sql.PooledConnection

removeConnectionEventListener

public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
Specified by:
removeConnectionEventListener in interface javax.sql.PooledConnection

getConnection

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

notifyClose

void notifyClose(int clientId)
Called by ClientConnection to notify that the application has attempted to close the connection. After this call, the client connection is no longer useable and this pooled connection can be reused. The event listener is notified immediately.

Parameters:
clientId - The ClientConnection identifier

notifyError

void notifyError(int clientId,
                 java.sql.SQLException except)
Called by ClientConnection to notify that an error occured with the underlying connection. If the error is critical, the underlying connection is closed and the listener is notified.

Parameters:
clientId - The ClientConnection identifier
except - The exception raised by the underlying connection

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

toString

public java.lang.String toString()

start

public void start(javax.transaction.xa.Xid xid,
                  int flags)
           throws javax.transaction.xa.XAException
Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

end

public void end(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.XAException
Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

recover

public javax.transaction.xa.Xid[] recover(int flags)
                                   throws javax.transaction.xa.XAException
Specified by:
recover in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException
Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xaRes)
                 throws javax.transaction.xa.XAException
Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws javax.transaction.xa.XAException
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

getTransactionTimeout

public int getTransactionTimeout()
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource

insideGlobalTx

boolean insideGlobalTx()
Returns true if this connection is inside a global transaction. If the connection is inside a global transaction it will not allow commit/rollback directly from the Connection interface.


getUnderlying

java.sql.Connection getUnderlying(int clientId)
                            throws java.sql.SQLException
Called to obtain the underlying connections. If this connection is part of a transaction, the transction's underlying connection is returned, or an exception is thrown if the connection was terminated due to timeout. If this connection is not part of a transaction, a non-transactional connection is returned.

Parameters:
clientId - The ClientConnection identifier
Throws:
java.sql.SQLException


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.