Package org.h2.jdbcx
Class JdbcXAConnection
- java.lang.Object
-
- org.h2.message.TraceObject
-
- org.h2.jdbcx.JdbcXAConnection
-
- All Implemented Interfaces:
javax.sql.PooledConnection,javax.sql.XAConnection,javax.transaction.xa.XAResource
public final class JdbcXAConnection extends TraceObject implements javax.sql.XAConnection, javax.transaction.xa.XAResource
This class provides support for distributed transactions. An application developer usually does not use this interface. It is used by the transaction manager internally.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classJdbcXAConnection.PooledJdbcConnectionA pooled connection.
-
Field Summary
Fields Modifier and Type Field Description private javax.transaction.xa.XidcurrentTransactionprivate JdbcDataSourceFactoryfactoryprivate java.sql.ConnectionhandleConnprivate java.util.ArrayList<javax.sql.ConnectionEventListener>listenersprivate JdbcConnectionphysicalConnprivate booleanprepared-
Fields inherited from class org.h2.message.TraceObject
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQLXML, STATEMENT, trace, XA_DATA_SOURCE, XID
-
-
Constructor Summary
Constructors Constructor Description JdbcXAConnection(JdbcDataSourceFactory factory, int id, JdbcConnection physicalConn)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionEventListener(javax.sql.ConnectionEventListener listener)Register a new listener for the connection.voidaddStatementEventListener(javax.sql.StatementEventListener listener)[Not supported] Add a statement event listener.private voidcheckOpen()voidclose()Close the physical connection.(package private) voidclosedHandle()INTERNALvoidcommit(javax.transaction.xa.Xid xid, boolean onePhase)Commit a transaction.private static javax.transaction.xa.XAExceptionconvertException(java.sql.SQLException e)voidend(javax.transaction.xa.Xid xid, int flags)End a transaction.voidforget(javax.transaction.xa.Xid xid)Forget a transaction.java.sql.ConnectiongetConnection()Get a connection that is a handle to the physical connection.intgetTransactionTimeout()Get the transaction timeout.javax.transaction.xa.XAResourcegetXAResource()Get the XAResource object.booleanisSameRM(javax.transaction.xa.XAResource xares)Checks if this is the same XAResource.intprepare(javax.transaction.xa.Xid xid)Prepare a transaction.private static java.lang.StringquoteFlags(int flags)private static java.lang.StringquoteXid(javax.transaction.xa.Xid xid)javax.transaction.xa.Xid[]recover(int flag)Get the list of prepared transaction branches.voidremoveConnectionEventListener(javax.sql.ConnectionEventListener listener)Remove the event listener.voidremoveStatementEventListener(javax.sql.StatementEventListener listener)[Not supported] Remove a statement event listener.voidrollback(javax.transaction.xa.Xid xid)Roll back a transaction.booleansetTransactionTimeout(int seconds)Set the transaction timeout.voidstart(javax.transaction.xa.Xid xid, int flags)Start or continue to work on a transaction.java.lang.StringtoString()INTERNAL-
Methods inherited from class org.h2.message.TraceObject
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
-
-
-
-
Field Detail
-
factory
private final JdbcDataSourceFactory factory
-
physicalConn
private JdbcConnection physicalConn
-
handleConn
private volatile java.sql.Connection handleConn
-
listeners
private final java.util.ArrayList<javax.sql.ConnectionEventListener> listeners
-
currentTransaction
private javax.transaction.xa.Xid currentTransaction
-
prepared
private boolean prepared
-
-
Constructor Detail
-
JdbcXAConnection
JdbcXAConnection(JdbcDataSourceFactory factory, int id, JdbcConnection physicalConn)
-
-
Method Detail
-
getXAResource
public javax.transaction.xa.XAResource getXAResource()
Get the XAResource object.- Specified by:
getXAResourcein interfacejavax.sql.XAConnection- Returns:
- itself
-
close
public void close() throws java.sql.SQLExceptionClose the physical connection. This method is usually called by the connection pool.- Specified by:
closein interfacejavax.sql.PooledConnection- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionGet a connection that is a handle to the physical connection. This method is usually called by the connection pool. This method closes the last connection handle if one exists.- Specified by:
getConnectionin interfacejavax.sql.PooledConnection- Returns:
- the connection
- Throws:
java.sql.SQLException
-
addConnectionEventListener
public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
Register a new listener for the connection.- Specified by:
addConnectionEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- the event listener
-
removeConnectionEventListener
public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
Remove the event listener.- Specified by:
removeConnectionEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- the event listener
-
closedHandle
void closedHandle()
INTERNAL
-
getTransactionTimeout
public int getTransactionTimeout()
Get the transaction timeout.- Specified by:
getTransactionTimeoutin interfacejavax.transaction.xa.XAResource- Returns:
- 0
-
setTransactionTimeout
public boolean setTransactionTimeout(int seconds)
Set the transaction timeout.- Specified by:
setTransactionTimeoutin interfacejavax.transaction.xa.XAResource- Parameters:
seconds- ignored- Returns:
- false
-
isSameRM
public boolean isSameRM(javax.transaction.xa.XAResource xares)
Checks if this is the same XAResource.- Specified by:
isSameRMin interfacejavax.transaction.xa.XAResource- Parameters:
xares- the other object- Returns:
- true if this is the same object
-
recover
public javax.transaction.xa.Xid[] recover(int flag) throws javax.transaction.xa.XAExceptionGet the list of prepared transaction branches. This method is called by the transaction manager during recovery.- Specified by:
recoverin interfacejavax.transaction.xa.XAResource- Parameters:
flag- TMSTARTRSCAN, TMENDRSCAN, or TMNOFLAGS. If no other flags are set, TMNOFLAGS must be used.- Returns:
- zero or more Xid objects
- Throws:
javax.transaction.xa.XAException
-
prepare
public int prepare(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAExceptionPrepare a transaction.- Specified by:
preparein interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction id- Returns:
- XA_OK
- Throws:
javax.transaction.xa.XAException
-
forget
public void forget(javax.transaction.xa.Xid xid)
Forget a transaction. This method does not have an effect for this database.- Specified by:
forgetin interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction id
-
rollback
public void rollback(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAExceptionRoll back a transaction.- Specified by:
rollbackin interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction id- Throws:
javax.transaction.xa.XAException
-
end
public void end(javax.transaction.xa.Xid xid, int flags) throws javax.transaction.xa.XAExceptionEnd a transaction.- Specified by:
endin interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction idflags- TMSUCCESS, TMFAIL, or TMSUSPEND- Throws:
javax.transaction.xa.XAException
-
start
public void start(javax.transaction.xa.Xid xid, int flags) throws javax.transaction.xa.XAExceptionStart or continue to work on a transaction.- Specified by:
startin interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction idflags- TMNOFLAGS, TMJOIN, or TMRESUME- Throws:
javax.transaction.xa.XAException
-
commit
public void commit(javax.transaction.xa.Xid xid, boolean onePhase) throws javax.transaction.xa.XAExceptionCommit a transaction.- Specified by:
commitin interfacejavax.transaction.xa.XAResource- Parameters:
xid- the transaction idonePhase- use a one-phase protocol if true- Throws:
javax.transaction.xa.XAException
-
addStatementEventListener
public void addStatementEventListener(javax.sql.StatementEventListener listener)
[Not supported] Add a statement event listener.- Specified by:
addStatementEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- the new statement event listener
-
removeStatementEventListener
public void removeStatementEventListener(javax.sql.StatementEventListener listener)
[Not supported] Remove a statement event listener.- Specified by:
removeStatementEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- the statement event listener
-
toString
public java.lang.String toString()
INTERNAL- Overrides:
toStringin classjava.lang.Object
-
convertException
private static javax.transaction.xa.XAException convertException(java.sql.SQLException e)
-
quoteXid
private static java.lang.String quoteXid(javax.transaction.xa.Xid xid)
-
quoteFlags
private static java.lang.String quoteFlags(int flags)
-
checkOpen
private void checkOpen() throws javax.transaction.xa.XAException- Throws:
javax.transaction.xa.XAException
-
-