Package org.apache.derby.impl.drda
Class DRDAXAProtocol
- java.lang.Object
-
- org.apache.derby.impl.drda.DRDAXAProtocol
-
class DRDAXAProtocol extends java.lang.ObjectThis class translates DRDA XA protocol from an application requester to XA calls for Derby and then translates the results from Derby to DRDA for return to the application requester. This class requires the use of javax.transaction.xa classes from j2ee, so is separated from DRDAConnThread, because of the additional library requirements
-
-
Field Summary
Fields Modifier and Type Field Description private DRDAConnThreadconnThreadprivate DDMReaderreaderprivate DDMWriterwriterprivate javax.transaction.xa.XidxidHolds the Xid of the global transaction associated with the corresponding DRDAConnThread (and connection itself).
-
Constructor Summary
Constructors Constructor Description DRDAXAProtocol(DRDAConnThread connThread)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcommitLocalTransaction()Commit local transaction.private voidcommitTransaction(javax.transaction.xa.Xid xid, int xaflags)Commit the xa transaction.private voidcommitXATransaction(javax.transaction.xa.Xid xid, int xaflags)Commit the xa transaction.private voidendXA(javax.transaction.xa.Xid xid, int xaflags)End the xa transaction.private voidforgetXATransaction(javax.transaction.xa.Xid xid)Forget the xa transaction.(package private) ResourceAdaptergetResourceAdapter()private javax.transaction.xa.XAResourcegetXAResource()get XAResource for the connectionprotected voidparseSYNCCTL()Parse SYNCCTL - Parse SYNCCTL command for XAMGR lvl 7protected intparseSYNCTYPE()parse SYNCTYPE for XAMGR lvl 7 return synctype value CodePoint.SYNCTYPE_NEW_UOW -> XAResource.start() CodePoint.SYNCTYPE_END_UOW -> XAResource.end() CodePoint.SYNCTYPE_PREPARE -> XAResource.prepare() CodePoint.SYNCTYPE_MIGRATE -> not supported //SYNCPT MGR LEVEL 5 CodePoint.SYNCTYPE_REQ_COMMIT -> not supported //SYNCPT MGR LEVEL 5 CodePoint.SYNCTYPE_COMMITTED -> XAResource.commit() or local commit for null XID CodePoint.SYNCTYPE_REQ_LOG -> not supported CodePoint.SYNCTYPE_REQ_FORGET -> XAResource.forget() CodePoint.SYNCTYPE_ROLLBACK -> XAResource.rollback() CodePoint.SYNCTYPE_MIGRATED -> not supported CodePoint.SYNCTYPE_INDOUBT -> XAResource.recover();private intparseXAFlags()parse XAFlagsprivate longparseXATimeout()Parses a XA transaction timout value.private javax.transaction.xa.XidparseXID()Parse XID formatId -1 translates into a null XID and a local transactionprivate voidprepareXATransaction(javax.transaction.xa.Xid xid)Prepare the xa transaction.private intprocessXAException(javax.transaction.xa.XAException xe)return xa exception errorCode.private voidrecoverXA()private voidrecoverXA(int xaflags)Call recover.(package private) voidrollbackCurrentTransaction()This function rollbacks the current global transaction associated with the XAResource or a local transaction.private voidrollbackLocalTransaction(boolean sendSYNCCRD)Rollback a local transaction.private voidrollbackTransaction(javax.transaction.xa.Xid xid, boolean sendSYNCCRD)Rollback transaction.private voidrollbackXATransaction(javax.transaction.xa.Xid xid, boolean sendSYNCCRD)Rollback the xa transaction.private voidstartXATransaction(javax.transaction.xa.Xid xid, int xaflags, long xaTimeout)Start the xa transaction.private java.lang.StringsyncTypeToString(int syncType)printable syncType for debug outputprivate voidwritePRPHRCLST(javax.transaction.xa.Xid[] xids)write PRPHRCLST (indoubt list)private voidwriteSYNCCRD(int synctype, int xaRetVal, javax.transaction.xa.Xid[] xids)Write SYNCCRD (SYNCCTL response)private voidwriteXID(javax.transaction.xa.Xid xid)write XIDprivate java.lang.StringxaflagsToString(int xaflags)printable xaflags
-
-
-
Field Detail
-
connThread
private DRDAConnThread connThread
-
reader
private DDMReader reader
-
writer
private DDMWriter writer
-
xid
private javax.transaction.xa.Xid xid
Holds the Xid of the global transaction associated with the corresponding DRDAConnThread (and connection itself).
-
-
Constructor Detail
-
DRDAXAProtocol
DRDAXAProtocol(DRDAConnThread connThread)
-
-
Method Detail
-
parseSYNCCTL
protected void parseSYNCCTL() throws DRDAProtocolExceptionParse SYNCCTL - Parse SYNCCTL command for XAMGR lvl 7- Throws:
DRDAProtocolException
-
parseSYNCTYPE
protected int parseSYNCTYPE() throws DRDAProtocolExceptionparse SYNCTYPE for XAMGR lvl 7 return synctype value CodePoint.SYNCTYPE_NEW_UOW -> XAResource.start() CodePoint.SYNCTYPE_END_UOW -> XAResource.end() CodePoint.SYNCTYPE_PREPARE -> XAResource.prepare() CodePoint.SYNCTYPE_MIGRATE -> not supported //SYNCPT MGR LEVEL 5 CodePoint.SYNCTYPE_REQ_COMMIT -> not supported //SYNCPT MGR LEVEL 5 CodePoint.SYNCTYPE_COMMITTED -> XAResource.commit() or local commit for null XID CodePoint.SYNCTYPE_REQ_LOG -> not supported CodePoint.SYNCTYPE_REQ_FORGET -> XAResource.forget() CodePoint.SYNCTYPE_ROLLBACK -> XAResource.rollback() CodePoint.SYNCTYPE_MIGRATED -> not supported CodePoint.SYNCTYPE_INDOUBT -> XAResource.recover();- Throws:
DRDAProtocolException
-
parseXID
private javax.transaction.xa.Xid parseXID() throws DRDAProtocolExceptionParse XID formatId -1 translates into a null XID and a local transaction- Throws:
DRDAProtocolException
-
parseXAFlags
private int parseXAFlags() throws DRDAProtocolExceptionparse XAFlags- Returns:
- XAFlags value
- Throws:
DRDAProtocolException
-
parseXATimeout
private long parseXATimeout() throws DRDAProtocolExceptionParses a XA transaction timout value.- Returns:
- A timeout value.
- Throws:
DRDAProtocolException
-
startXATransaction
private void startXATransaction(javax.transaction.xa.Xid xid, int xaflags, long xaTimeout) throws DRDAProtocolExceptionStart the xa transaction. Send SYNCRRD response- Parameters:
xid- - XID (formatId = -1 for local transaction)xaflags- - xaflagsxaTimeout- - The timeout for the global transaction in millis (or -1 if not specified)- Throws:
DRDAProtocolException
-
commitTransaction
private void commitTransaction(javax.transaction.xa.Xid xid, int xaflags) throws DRDAProtocolExceptionCommit the xa transaction. Send SYNCCRD response- Parameters:
xid- - XID (formatId = -1 for local transaction)xaflags- - xaflags- Throws:
DRDAProtocolException
-
commitLocalTransaction
private void commitLocalTransaction() throws DRDAProtocolExceptionCommit local transaction. Send SYNCCRD response.- Throws:
DRDAProtocolException
-
commitXATransaction
private void commitXATransaction(javax.transaction.xa.Xid xid, int xaflags) throws DRDAProtocolExceptionCommit the xa transaction. Send SYNCCRD response.- Parameters:
xid- - XIDxaflags- - xaflags- Throws:
DRDAProtocolException
-
rollbackTransaction
private void rollbackTransaction(javax.transaction.xa.Xid xid, boolean sendSYNCCRD) throws DRDAProtocolExceptionRollback transaction. Optionally send SYNCCRD response.- Parameters:
xid- Xid for rollback for global transaction. If xid formatid is -1 it represents a local transactionsendSYNCCRD- Indicates whether the function should send a SYNCCRD response- Throws:
DRDAProtocolException
-
rollbackLocalTransaction
private void rollbackLocalTransaction(boolean sendSYNCCRD) throws DRDAProtocolExceptionRollback a local transaction. Optionally send SYNCCRD response.- Parameters:
sendSYNCCRD- Indicates whether the function should send a SYNCCRD response- Throws:
DRDAProtocolException
-
rollbackXATransaction
private void rollbackXATransaction(javax.transaction.xa.Xid xid, boolean sendSYNCCRD) throws DRDAProtocolExceptionRollback the xa transaction. Optionally send SYNCCRD response.- Parameters:
xid- - XIDsendSYNCCRD- Indicates whether the function should send a SYNCCRD response- Throws:
DRDAProtocolException
-
endXA
private void endXA(javax.transaction.xa.Xid xid, int xaflags) throws DRDAProtocolExceptionEnd the xa transaction. Send SYNCRRD response- Parameters:
xid- - XIDxaflags- - xaflags- Throws:
DRDAProtocolException
-
prepareXATransaction
private void prepareXATransaction(javax.transaction.xa.Xid xid) throws DRDAProtocolExceptionPrepare the xa transaction. Send SYNCCRD response.- Parameters:
xid- - XID- Throws:
DRDAProtocolException
-
forgetXATransaction
private void forgetXATransaction(javax.transaction.xa.Xid xid) throws DRDAProtocolExceptionForget the xa transaction. Send SYNCCRD response.- Parameters:
xid- - XID- Throws:
DRDAProtocolException
-
recoverXA
private void recoverXA() throws DRDAProtocolException- Throws:
DRDAProtocolException
-
recoverXA
private void recoverXA(int xaflags) throws DRDAProtocolExceptionCall recover. Send SYNCCRD response with indoubt list- Throws:
DRDAProtocolException
-
writeSYNCCRD
private void writeSYNCCRD(int synctype, int xaRetVal, javax.transaction.xa.Xid[] xids) throws DRDAProtocolExceptionWrite SYNCCRD (SYNCCTL response)- Parameters:
synctype- - XA Command to send response for see parseSYNCTYPExaRetVal- - return value from XA commandxids- - list of xids to return for recover. null for other commands- Throws:
DRDAProtocolException
-
writePRPHRCLST
private void writePRPHRCLST(javax.transaction.xa.Xid[] xids) throws DRDAProtocolExceptionwrite PRPHRCLST (indoubt list)- Parameters:
xids- - list of indoubt xa transactions obtained from recover- Throws:
DRDAProtocolException
-
writeXID
private void writeXID(javax.transaction.xa.Xid xid) throws DRDAProtocolExceptionwrite XID- Parameters:
xid- - XID to write- Throws:
DRDAProtocolException
-
getXAResource
private javax.transaction.xa.XAResource getXAResource()
get XAResource for the connection- Returns:
- XAResource
-
syncTypeToString
private java.lang.String syncTypeToString(int syncType)
printable syncType for debug output- Parameters:
syncType-- Returns:
- - sync type meaning
-
xaflagsToString
private java.lang.String xaflagsToString(int xaflags)
printable xaflags- Parameters:
xaflags-- Returns:
- printable xaflags for debug output
-
processXAException
private int processXAException(javax.transaction.xa.XAException xe)
return xa exception errorCode. print to console for debug output.- Parameters:
xe- - XA Exception
-
getResourceAdapter
ResourceAdapter getResourceAdapter()
- Returns:
- The ResourceAdapter instance for the underlying database.
-
rollbackCurrentTransaction
void rollbackCurrentTransaction()
This function rollbacks the current global transaction associated with the XAResource or a local transaction. The function should be called only in exceptional cases - like client socket is closed.
-
-