MySQL Connector/J size='-1'>5.1.6

com.mysql.jdbc.jdbc2.optional
Class MysqlXAConnection

java.lang.Object
  extended by com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection
      extended by com.mysql.jdbc.jdbc2.optional.MysqlXAConnection
All Implemented Interfaces:
javax.sql.PooledConnection, javax.sql.XAConnection, javax.transaction.xa.XAResource
Direct Known Subclasses:
JDBC4MysqlXAConnection

public class MysqlXAConnection
extends MysqlPooledConnection
implements javax.sql.XAConnection, javax.transaction.xa.XAResource

An object that provides support for distributed transactions. An XAConnection object may be enlisted in a distributed transaction by means of an XAResource object. A transaction manager, usually part of a middle tier server, manages an XAConnection object through the XAResource object.

An application programmer does not use this interface directly; rather, it is used by a transaction manager working in the middle tier server.

Since:
1.4

Field Summary
protected  boolean logXaCommands
           
 
Fields inherited from class com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection
CONNECTION_CLOSED_EVENT, CONNECTION_ERROR_EVENT
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
MysqlXAConnection(ConnectionImpl connection, boolean logXaCommands)
           
 
Method Summary
 void addStatementEventListener(javax.sql.StatementEventListener listener)
           
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
          Commits the global transaction specified by xid.
 void end(javax.transaction.xa.Xid xid, int flags)
          Ends the work performed on behalf of a transaction branch.
 void forget(javax.transaction.xa.Xid xid)
          Tells the resource manager to forget about a heuristically completed transaction branch.
 java.sql.Connection getConnection()
          Invoked by the container.
protected static MysqlXAConnection getInstance(ConnectionImpl mysqlConnection, boolean logXaCommands)
           
 int getTransactionTimeout()
          Obtains the current transaction timeout value set for this XAResource instance.
 javax.transaction.xa.XAResource getXAResource()
          Retrieves an XAResource object that the transaction manager will use to manage this XAConnection object's participation in a distributed transaction.
 boolean isSameRM(javax.transaction.xa.XAResource xares)
          This method is called to determine if the resource manager instance represented by the target object is the same as the resouce manager instance represented by the parameter xares.
protected static javax.transaction.xa.XAException mapXAExceptionFromSQLException(java.sql.SQLException sqlEx)
           
 int prepare(javax.transaction.xa.Xid xid)
          Asks the resource manager to prepare for a transaction commit of the transaction specified in xid.
protected static javax.transaction.xa.Xid[] recover(java.sql.Connection c, int flag)
           
 javax.transaction.xa.Xid[] recover(int flag)
          This method is called to obtain a list of prepared transaction branches from a resource manager.
 void removeStatementEventListener(javax.sql.StatementEventListener listener)
           
 void rollback(javax.transaction.xa.Xid xid)
          Informs the resource manager to roll back work done on behalf of a transaction branch.
 boolean setTransactionTimeout(int arg0)
          Sets the current transaction timeout value for this XAResource instance.
 void start(javax.transaction.xa.Xid xid, int flags)
          Starts work on behalf of a transaction branch specified in xid.
 
Methods inherited from class com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection
addConnectionEventListener, callConnectionEventListeners, close, getConnection, getInstance, removeConnectionEventListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.sql.PooledConnection
addConnectionEventListener, close, removeConnectionEventListener
 

Field Detail

logXaCommands

protected boolean logXaCommands
Constructor Detail

MysqlXAConnection

public MysqlXAConnection(ConnectionImpl connection,
                         boolean logXaCommands)
                  throws java.sql.SQLException
Parameters:
connection -
Throws:
java.sql.SQLException
Method Detail

getInstance

protected static MysqlXAConnection getInstance(ConnectionImpl mysqlConnection,
                                               boolean logXaCommands)
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getXAResource

public javax.transaction.xa.XAResource getXAResource()
                                              throws java.sql.SQLException
Retrieves an XAResource object that the transaction manager will use to manage this XAConnection object's participation in a distributed transaction.

Specified by:
getXAResource in interface javax.sql.XAConnection
Returns:
the XAResource object
Throws:
java.sql.SQLException - if a database access error occurs

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Obtains the current transaction timeout value set for this XAResource instance. If XAResource.setTransactionTimeout was not used prior to invoking this method, the return value is the default timeout set for the resource manager; otherwise, the value used in the previous setTransactionTimeout call is returned.

Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Returns:
the transaction timeout value in seconds.
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exception values are XAER_RMERR and XAER_RMFAIL.

setTransactionTimeout

public boolean setTransactionTimeout(int arg0)
                              throws javax.transaction.xa.XAException
Sets the current transaction timeout value for this XAResource instance. Once set, this timeout value is effective until setTransactionTimeout is invoked again with a different value. To reset the timeout value to the default value used by the resource manager, set the value to zero. If the timeout operation is performed successfully, the method returns true; otherwise false. If a resource manager does not support explicitly setting the transaction timeout value, this method returns false.

Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Returns:
true if the transaction timeout value is set successfully; otherwise false.
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xares)
                 throws javax.transaction.xa.XAException
This method is called to determine if the resource manager instance represented by the target object is the same as the resouce manager instance represented by the parameter xares.

Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Returns:
true if it's the same RM instance; otherwise false.
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exception values are XAER_RMERR and XAER_RMFAIL.

recover

public javax.transaction.xa.Xid[] recover(int flag)
                                   throws javax.transaction.xa.XAException
This method is called to obtain a list of prepared transaction branches from a resource manager. The transaction manager calls this method during recovery to obtain the list of transaction branches that are currently in prepared or heuristically completed states. The flag parameter indicates where the recover scan should start or end, or start and end. This method may be invoked one or more times during a recovery scan. The resource manager maintains a cursor which marks the current position of the prepared or heuristically completed transaction list. Each invocation of the recover method moves the cursor passed the set of Xids that are returned. Two consecutive invocation of this method that starts from the beginning of the list must return the same list of transaction branches unless one of the following takes place: - the transaction manager invokes the commit, forget, prepare, or rollback method for that resource manager, between the two consecutive invocation of the recovery scan. - the resource manager heuristically completes some transaction branches between the two invocation of the recovery scan.

Specified by:
recover in interface javax.transaction.xa.XAResource
Parameters:
flag - One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in the parameter.
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.

recover

protected static javax.transaction.xa.Xid[] recover(java.sql.Connection c,
                                                    int flag)
                                             throws javax.transaction.xa.XAException
Throws:
javax.transaction.xa.XAException

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Asks the resource manager to prepare for a transaction commit of the transaction specified in xid.

Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Tells the resource manager to forget about a heuristically completed transaction branch.

Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Informs the resource manager to roll back work done on behalf of a transaction branch.

Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO. If the transaction branch is already marked rollback-only the resource manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work and has released all held resources.

end

public void end(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.XAException
Ends the work performed on behalf of a transaction branch. The resource manager disassociates the XA resource from the transaction branch specified and lets the transaction complete. If TMSUSPEND is specified in the flags, the transaction branch is temporarily suspended in an incomplete state. The transaction context is in a suspended state and must be resumed via the start method with TMRESUME specified. If TMFAIL is specified, the portion of work has failed. The resource manager may mark the transaction as rollback-only If TMSUCCESS is specified, the portion of work has completed successfully.

Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - - An error has occurred. Possible XAException values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, XAER_PROTO, or XA_RB*.

start

public void start(javax.transaction.xa.Xid xid,
                  int flags)
           throws javax.transaction.xa.XAException
Starts work on behalf of a transaction branch specified in xid. If TMJOIN is specified, the start applies to joining a transaction previously seen by the resource manager. If TMRESUME is specified, the start applies to resuming a suspended transaction specified in the parameter xid. If neither TMJOIN nor TMRESUME is specified and the transaction specified by xid has previously been seen by the resource manager, the resource manager throws the XAException exception with XAER_DUPID error code.

Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible exceptions are XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO.

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException
Commits the global transaction specified by xid.

Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO. If the resource manager did not commit the transaction and the parameter onePhase is set to true, the resource manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work and has released all held resources.

mapXAExceptionFromSQLException

protected static javax.transaction.xa.XAException mapXAExceptionFromSQLException(java.sql.SQLException sqlEx)

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Description copied from class: MysqlPooledConnection
Invoked by the container. Return a logicalHandle object that wraps a physical connection.

Specified by:
getConnection in interface javax.sql.PooledConnection
Overrides:
getConnection in class MysqlPooledConnection
Throws:
java.sql.SQLException
See Also:
java.sql.DataSource#getConnection()

addStatementEventListener

public void addStatementEventListener(javax.sql.StatementEventListener listener)
Specified by:
addStatementEventListener in interface javax.sql.PooledConnection
Overrides:
addStatementEventListener in class MysqlPooledConnection

removeStatementEventListener

public void removeStatementEventListener(javax.sql.StatementEventListener listener)
Specified by:
removeStatementEventListener in interface javax.sql.PooledConnection
Overrides:
removeStatementEventListener in class MysqlPooledConnection

MySQL Connector/J size='-1'>5.1.6