Class DRDAXAProtocol


  • class DRDAXAProtocol
    extends java.lang.Object
    This 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 DRDAConnThread connThread  
      private DDMReader reader  
      private DDMWriter writer  
      private javax.transaction.xa.Xid xid
      Holds the Xid of the global transaction associated with the corresponding DRDAConnThread (and connection itself).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void commitLocalTransaction()
      Commit local transaction.
      private void commitTransaction​(javax.transaction.xa.Xid xid, int xaflags)
      Commit the xa transaction.
      private void commitXATransaction​(javax.transaction.xa.Xid xid, int xaflags)
      Commit the xa transaction.
      private void endXA​(javax.transaction.xa.Xid xid, int xaflags)
      End the xa transaction.
      private void forgetXATransaction​(javax.transaction.xa.Xid xid)
      Forget the xa transaction.
      (package private) ResourceAdapter getResourceAdapter()  
      private javax.transaction.xa.XAResource getXAResource()
      get XAResource for the connection
      protected void parseSYNCCTL()
      Parse SYNCCTL - Parse SYNCCTL command for XAMGR lvl 7
      protected int parseSYNCTYPE()
      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 int parseXAFlags()
      parse XAFlags
      private long parseXATimeout()
      Parses a XA transaction timout value.
      private javax.transaction.xa.Xid parseXID()
      Parse XID formatId -1 translates into a null XID and a local transaction
      private void prepareXATransaction​(javax.transaction.xa.Xid xid)
      Prepare the xa transaction.
      private int processXAException​(javax.transaction.xa.XAException xe)
      return xa exception errorCode.
      private void recoverXA()  
      private void recoverXA​(int xaflags)
      Call recover.
      (package private) void rollbackCurrentTransaction()
      This function rollbacks the current global transaction associated with the XAResource or a local transaction.
      private void rollbackLocalTransaction​(boolean sendSYNCCRD)
      Rollback a local transaction.
      private void rollbackTransaction​(javax.transaction.xa.Xid xid, boolean sendSYNCCRD)
      Rollback transaction.
      private void rollbackXATransaction​(javax.transaction.xa.Xid xid, boolean sendSYNCCRD)
      Rollback the xa transaction.
      private void startXATransaction​(javax.transaction.xa.Xid xid, int xaflags, long xaTimeout)
      Start the xa transaction.
      private java.lang.String syncTypeToString​(int syncType)
      printable syncType for debug output
      private void writePRPHRCLST​(javax.transaction.xa.Xid[] xids)
      write PRPHRCLST (indoubt list)
      private void writeSYNCCRD​(int synctype, int xaRetVal, javax.transaction.xa.Xid[] xids)
      Write SYNCCRD (SYNCCTL response)
      private void writeXID​(javax.transaction.xa.Xid xid)
      write XID
      private java.lang.String xaflagsToString​(int xaflags)
      printable xaflags
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • xid

        private javax.transaction.xa.Xid xid
        Holds the Xid of the global transaction associated with the corresponding DRDAConnThread (and connection itself).
    • Constructor Detail

    • Method Detail

      • parseSYNCTYPE

        protected int parseSYNCTYPE()
                             throws DRDAProtocolException
        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();
        Throws:
        DRDAProtocolException
      • startXATransaction

        private void startXATransaction​(javax.transaction.xa.Xid xid,
                                        int xaflags,
                                        long xaTimeout)
                                 throws DRDAProtocolException
        Start the xa transaction. Send SYNCRRD response
        Parameters:
        xid - - XID (formatId = -1 for local transaction)
        xaflags - - xaflags
        xaTimeout - - 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 DRDAProtocolException
        Commit the xa transaction. Send SYNCCRD response
        Parameters:
        xid - - XID (formatId = -1 for local transaction)
        xaflags - - xaflags
        Throws:
        DRDAProtocolException
      • commitXATransaction

        private void commitXATransaction​(javax.transaction.xa.Xid xid,
                                         int xaflags)
                                  throws DRDAProtocolException
        Commit the xa transaction. Send SYNCCRD response.
        Parameters:
        xid - - XID
        xaflags - - xaflags
        Throws:
        DRDAProtocolException
      • rollbackTransaction

        private void rollbackTransaction​(javax.transaction.xa.Xid xid,
                                         boolean sendSYNCCRD)
                                  throws DRDAProtocolException
        Rollback transaction. Optionally send SYNCCRD response.
        Parameters:
        xid - Xid for rollback for global transaction. If xid formatid is -1 it represents a local transaction
        sendSYNCCRD - Indicates whether the function should send a SYNCCRD response
        Throws:
        DRDAProtocolException
      • rollbackLocalTransaction

        private void rollbackLocalTransaction​(boolean sendSYNCCRD)
                                       throws DRDAProtocolException
        Rollback 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 DRDAProtocolException
        Rollback the xa transaction. Optionally send SYNCCRD response.
        Parameters:
        xid - - XID
        sendSYNCCRD - Indicates whether the function should send a SYNCCRD response
        Throws:
        DRDAProtocolException
      • endXA

        private void endXA​(javax.transaction.xa.Xid xid,
                           int xaflags)
                    throws DRDAProtocolException
        End the xa transaction. Send SYNCRRD response
        Parameters:
        xid - - XID
        xaflags - - xaflags
        Throws:
        DRDAProtocolException
      • prepareXATransaction

        private void prepareXATransaction​(javax.transaction.xa.Xid xid)
                                   throws DRDAProtocolException
        Prepare the xa transaction. Send SYNCCRD response.
        Parameters:
        xid - - XID
        Throws:
        DRDAProtocolException
      • forgetXATransaction

        private void forgetXATransaction​(javax.transaction.xa.Xid xid)
                                  throws DRDAProtocolException
        Forget the xa transaction. Send SYNCCRD response.
        Parameters:
        xid - - XID
        Throws:
        DRDAProtocolException
      • writeSYNCCRD

        private void writeSYNCCRD​(int synctype,
                                  int xaRetVal,
                                  javax.transaction.xa.Xid[] xids)
                           throws DRDAProtocolException
        Write SYNCCRD (SYNCCTL response)
        Parameters:
        synctype - - XA Command to send response for see parseSYNCTYPE
        xaRetVal - - return value from XA command
        xids - - list of xids to return for recover. null for other commands
        Throws:
        DRDAProtocolException
      • writePRPHRCLST

        private void writePRPHRCLST​(javax.transaction.xa.Xid[] xids)
                             throws DRDAProtocolException
        write PRPHRCLST (indoubt list)
        Parameters:
        xids - - list of indoubt xa transactions obtained from recover
        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.