Package com.atomikos.datasource.xa

Examples of com.atomikos.datasource.xa.XAResourceTransaction


    // MM patch: synchronized to allow threaded access
    private synchronized XAResourceTransaction findXAResourceTransaction (
            XAResource xares )
    {
        XAResourceTransaction ret = null;
        ret = (XAResourceTransaction) xaresToTxMap_.get ( new XAResourceKey (
                xares ) );

        return ret;
    }
View Full Code Here


            throws javax.transaction.RollbackException,
            javax.transaction.SystemException, IllegalStateException
    {
        TransactionalResource res = null;
        XATransactionalResource xatxres = null;
        XAResourceTransaction restx = null;
        Stack errors = new Stack ();

        if ( getStatus () == Status.STATUS_MARKED_ROLLBACK ) {
          String msg =  "Transaction is already marked for rollback - enlisting more resources is useless.";
          Configuration.logWarning ( msg );
            throw new javax.transaction.RollbackException ( msg );
        }

        Enumeration enumm = Configuration.getResources ();

        while ( enumm.hasMoreElements () ) {
            RecoverableResource rres = (RecoverableResource) enumm
                    .nextElement ();
            if ( rres instanceof XATransactionalResource ) {
                xatxres = (XATransactionalResource) rres;

                if ( xatxres.usesXAResource ( xares ) )
                    res = xatxres;

            }

        }

        printMsg ( "enlistResource ( " + xares + " ) with transaction "
                + toString (), Console.INFO );

        if ( res == null ) {

            if ( autoRegistration_ ) {

                synchronized ( Configuration.class ) {
                  // synchronized to avoid case 61740
                                  
          // ADDED with new recovery: unknown resources can be tolerated
          // by adding a new TemporaryXATransactionalResource
                  res = new TemporaryXATransactionalResource(xares);
                 
                  // cf case 61740: check for concurrent additions before this synch block was entered
                  if ( Configuration.getResource ( res.getName() ) == null ) {
                    printMsg("constructing new temporary resource "
              + "for unknown XAResource: " + xares, Console.DEBUG);
                    Configuration.addResource ( res );
                  }
        }

            } else {
              String msg = "There is no registered resource that can recover the given XAResource instance. " + "\n" +
                "Either enable automatic resource registration, or register a corresponding resource.";
              Configuration.logWarning ( msg );
                throw new javax.transaction.SystemException ( msg );
            }
        }

       
        // if this xares was suspended then it will still be in the map
        XAResourceTransaction active = findXAResourceTransaction ( xares );

        if ( active != null ) {

            // following violates XA state tables
            // and the invariant of the xaresToTxMap table
            if ( !active.isXaSuspended () ) {
              String msg = "The given XAResource instance is being enlisted a second time without delist in between?";
              Configuration.logWarning ( msg );
                throw new IllegalStateException ( msg );
            }

            // note: for suspended XAResources, the lookup MUST SUCCEED
            // since the TMRESUME must be called on the SAME XAResource
            // INSTANCE, and lookup also works on the instance level
            try {
                // ADDED: resume should also refresh the xaresource
                restx.setXAResource ( xares );
                active.xaResume ();
            } catch ( XAException xaerr ) {
                if ( (XAException.XA_RBBASE <= xaerr.errorCode)
                        && (xaerr.errorCode <= XAException.XA_RBEND) )
                    throw new javax.transaction.RollbackException (
                            "Transaction was already rolled back inside the back-end resource. Further enlists are useless." );
View Full Code Here

          Configuration.logWarning ( msg );
            throw new javax.transaction.SystemException ( msg );
        }

   
        XAResourceTransaction active = findXAResourceTransaction ( xares );

        // NOTE: the lookup MUST have succeeded since the delist must be
        // done by the same XAResource INSTANCE as the enlist before,
        // and lookup also uses instance comparison.
        if ( active == null ) {
          String msg = "Illegal attempt to delist an XAResource instance that was not previously enlisted.";
          Configuration.logWarning ( msg );
            throw new IllegalStateException ( msg );
        }

        if ( flag == XAResource.TMSUCCESS || flag == XAResource.TMFAIL ) {

            try {
                active.suspend ();
            } catch ( ResourceException re ) {
                errors.push ( re );
                throw new ExtendedSystemException ( "Error in delisting the given XAResource", errors );
            }
            removeXAResourceTransaction ( xares );

            // NOTE: if failure, then make sure no rollback can happen
            if ( flag == XAResource.TMFAIL )
                setRollbackOnly ();
        } else if ( flag == XAResource.TMSUSPEND ) {
            // call suspend on active xaresource.

            try {
                active.xaSuspend ();
            } catch ( XAException xaerr ) {
                errors.push ( xaerr );
                throw new ExtendedSystemException ( "Error in delisting the given XAResource", errors );
            }
View Full Code Here

  void suspendEnlistedXaResources() throws ExtendedSystemException
  {
    // cf case 61305
    Iterator xaResourceTransactions = xaresToTxMap_.values().iterator();
    while ( xaResourceTransactions.hasNext() ) {
      XAResourceTransaction resTx = (XAResourceTransaction) xaResourceTransactions.next();     
      try {
        resTx.xaSuspend();
      } catch (XAException e) {
        Stack errors = new Stack();
        errors.push ( e );
              throw new ExtendedSystemException ( "Error in delisting the given XAResource", errors );
      }
View Full Code Here

  }

  private synchronized XAResourceTransaction findXAResourceTransaction (
            XAResource xares )
    {
        XAResourceTransaction ret = null;
        ret = xaResourceToResourceTransactionMap_.get ( new XAResourceKey ( xares ) );
        if (ret != null) assertActiveOrSuspended(ret);
        return ret;
    }
View Full Code Here

    public boolean enlistResource(XAResource xares)
            throws javax.transaction.RollbackException,
            javax.transaction.SystemException, IllegalStateException
    {
        TransactionalResource res = null;
        XAResourceTransaction restx = null;
        Stack errors = new Stack();

        int status = getStatus();
        switch (status) {
          case Status.STATUS_MARKED_ROLLBACK:
          case Status.STATUS_ROLLEDBACK:
          case Status.STATUS_ROLLING_BACK:
            String msg =  "Transaction rollback - enlisting more resources is useless.";
              LOGGER.logWarning ( msg );
                throw new javax.transaction.RollbackException ( msg );
          case Status.STATUS_COMMITTED:
          case Status.STATUS_PREPARED:
          case Status.STATUS_UNKNOWN:
            msg =  "Enlisting more resources is no longer permitted: transaction is in state " + ct_.getState();
              LOGGER.logWarning ( msg );
                throw new IllegalStateException ( msg );
        }
     

        XAResourceTransaction suspendedXAResourceTransaction = findXAResourceTransaction ( xares );

        if ( suspendedXAResourceTransaction != null ) {

            if ( !suspendedXAResourceTransaction.isXaSuspended () ) {
              String msg = "The given XAResource instance is being enlisted a second time without delist in between?";
              LOGGER.logWarning ( msg );
                throw new IllegalStateException ( msg );
            }

            // note: for suspended XAResources, the lookup MUST SUCCEED
            // since the TMRESUME must be called on the SAME XAResource
            // INSTANCE, and lookup also works on the instance level
            try {
                suspendedXAResourceTransaction.setXAResource ( xares );
                suspendedXAResourceTransaction.xaResume ();
            } catch ( XAException xaerr ) {
                if ( (XAException.XA_RBBASE <= xaerr.errorCode)
                        && (xaerr.errorCode <= XAException.XA_RBEND) )
                  rethrowAsJtaRollbackException (
                            "Transaction was already rolled back inside the back-end resource. Further enlists are useless." , xaerr );
View Full Code Here

        if(LOGGER.isInfoEnabled()){
          LOGGER.logInfo( "delistResource ( " + xares + " ) with transaction "
                    + toString ());
        }

        XAResourceTransaction active = findXAResourceTransaction ( xares );
        // NOTE: the lookup MUST have succeeded since the delist must be
        // done by the same XAResource INSTANCE as the enlist before,
        // and lookup also uses instance comparison.
        if ( active == null ) {
          String msg = "Illegal attempt to delist an XAResource instance that was not previously enlisted.";
          LOGGER.logWarning ( msg );
            throw new IllegalStateException ( msg );
        }

        if ( flag == XAResource.TMSUCCESS || flag == XAResource.TMFAIL ) {

            try {
                active.suspend ();
            } catch ( ResourceException re ) {
                errors.push ( re );
                throw new ExtendedSystemException ( "Error in delisting the given XAResource", errors );
            }
            removeXAResourceTransaction ( xares );
            if ( flag == XAResource.TMFAIL ) setRollbackOnly ();

        } else if ( flag == XAResource.TMSUSPEND ) {
            try {
                active.xaSuspend ();
            } catch ( XAException xaerr ) {
                errors.push ( xaerr );
                throw new ExtendedSystemException ( "Error in delisting the given XAResource", errors );
            }
View Full Code Here

  void suspendEnlistedXaResources() throws ExtendedSystemException
  {
    // cf case 61305
    Iterator xaResourceTransactions = xaResourceToResourceTransactionMap_.values().iterator();
    while ( xaResourceTransactions.hasNext() ) {
      XAResourceTransaction resTx = (XAResourceTransaction) xaResourceTransactions.next();
      try {
        resTx.xaSuspend();
      } catch (XAException e) {
        Stack errors = new Stack();
        errors.push ( e );
              throw new ExtendedSystemException ( "Error in suspending the given XAResource", errors );
      }
View Full Code Here

  void resumeEnlistedXaReources() throws ExtendedSystemException
  {
    Iterator xaResourceTransactions = xaResourceToResourceTransactionMap_.values().iterator();
    while ( xaResourceTransactions.hasNext() ) {
      XAResourceTransaction resTx = (XAResourceTransaction) xaResourceTransactions.next();
      try {
        resTx.xaResume();
        xaResourceTransactions.remove();
      } catch (XAException e) {
        Stack errors = new Stack();
        errors.push ( e );
              throw new ExtendedSystemException ( "Error in resuming the given XAResource", errors );
View Full Code Here

    // MM patch: synchronized to allow threaded access
    private synchronized XAResourceTransaction findXAResourceTransaction (
            XAResource xares )
    {
        XAResourceTransaction ret = null;
        ret = (XAResourceTransaction) xaresToTxMap_.get ( new XAResourceKey (
                xares ) );

        return ret;
    }
View Full Code Here

TOP

Related Classes of com.atomikos.datasource.xa.XAResourceTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.