Package com.atomikos.datasource

Examples of com.atomikos.datasource.TransactionalResource


            }

          
            factory_ = JtaQueueConnectionFactory.getOrCreate ( resourceName_,
                    xaFactory_, xidFactory );
            TransactionalResource res = factory_.getTransactionalResource ();
            if ( Configuration.getResource ( res.getName () ) == null )
                Configuration.addResource ( res );
           
            StringBuffer msg = new StringBuffer();
            msg.append ( "QueueConnectionFactoryBean configured with [" );
            msg.append ( "resourceName=" ).append(resourceName_).append (", ");
View Full Code Here


                  }
              }
             
              factory_ = JtaTopicConnectionFactory.getOrCreate ( resourceName_,
                      xaFactory_, xidFactory );
              TransactionalResource res = factory_.getTransactionalResource ();
              if ( Configuration.getResource ( res.getName () ) == null )
                  Configuration.addResource ( res );
             
              StringBuffer msg = new StringBuffer();
              msg.append ( "TopicConnectionFactoryBean configured with [" );
              msg.append ( "resourceName=" ).append(resourceName_).append (", ");
View Full Code Here

    public boolean enlistResource ( XAResource xares )
            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." );

                errors.push ( xaerr );
                throw new ExtendedSystemException ( "Unexpected error during enlist", errors );
            }

        } else {

            try {
                restx = (XAResourceTransaction) res
                        .getResourceTransaction ( ct_ );

                // next, we MUST set the xa resource again,
                // because ONLY the instance we got as argument
                // is available for use now !
View Full Code Here

            throws java.lang.IllegalStateException,
            javax.transaction.SystemException
    {
        Stack errors = new Stack ();

        TransactionalResource res = null;
        Enumeration enumm = Configuration.getResources ();
        while ( enumm.hasMoreElements () ) {
            RecoverableResource rres = (RecoverableResource) enumm
                    .nextElement ();
            if ( rres instanceof XATransactionalResource ) {
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 );

                errors.push ( xaerr );
                throw new ExtendedSystemException ( "Unexpected error during enlist", errors );
            }

        } else {

            res = findRecoverableResourceForXaResource(xares);

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

            if ( res == null ) {
                  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.";
                  LOGGER.logWarning ( msg );
                    throw new javax.transaction.SystemException ( msg );
            }

            try {
                restx = (XAResourceTransaction) res.getResourceTransaction ( ct_ );

                // next, we MUST set the xa resource again,
                // because ONLY the instance we got as argument
                // is available for use now !
                // older instances (set in restx from previous sibling)
View Full Code Here

        return true;
    }

  private TransactionalResource findRecoverableResourceForXaResource(
      XAResource xares ) {
    TransactionalResource ret = null;
    XATransactionalResource xatxres;
   
    Enumeration enumm = Configuration.getResources ();
        while ( enumm.hasMoreElements () ) {
            RecoverableResource rres = (RecoverableResource) enumm.nextElement ();
            if ( rres instanceof XATransactionalResource ) {
                xatxres = (XATransactionalResource) rres;
                if ( xatxres.usesXAResource ( xares ) ) ret = xatxres;
            }

        }

        if ( ret == null && autoRegistration_ ) {

            synchronized ( Configuration.class ) {
              // synchronized to avoid case 61740
             
              ret = new TemporaryXATransactionalResource(xares);
              // cf case 61740: check for concurrent additions before this synch block was entered
              if ( Configuration.getResource ( ret.getName() ) == null ) {
                if(LOGGER.isDebugEnabled()){
                  LOGGER.logDebug("constructing new temporary resource "
                    + "for unknown XAResource: " + xares);
                }
                Configuration.addResource ( ret );
View Full Code Here

            }

          
            factory_ = JtaQueueConnectionFactory.getOrCreate ( resourceName_,
                    xaFactory_, xidFactory );
            TransactionalResource res = factory_.getTransactionalResource ();
            if ( Configuration.getResource ( res.getName () ) == null )
                Configuration.addResource ( res );
           
            StringBuffer msg = new StringBuffer();
            msg.append ( "QueueConnectionFactoryBean configured with [" );
            msg.append ( "resourceName=" ).append(resourceName_).append (", ");
View Full Code Here

                  }
              }
             
              factory_ = JtaTopicConnectionFactory.getOrCreate ( resourceName_,
                      xaFactory_, xidFactory );
              TransactionalResource res = factory_.getTransactionalResource ();
              if ( Configuration.getResource ( res.getName () ) == null )
                  Configuration.addResource ( res );
             
              StringBuffer msg = new StringBuffer();
              msg.append ( "TopicConnectionFactoryBean configured with [" );
              msg.append ( "resourceName=" ).append(resourceName_).append (", ");
View Full Code Here

    public boolean enlistResource ( XAResource xares )
            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.";
          LOGGER.logWarning ( msg );
            throw new javax.transaction.RollbackException ( 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?";
              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 {
                // ADDED: resume should also refresh the xaresource
                active.setXAResource ( xares );
                active.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 );

                errors.push ( xaerr );
                throw new ExtendedSystemException ( "Unexpected error during enlist", errors );
            }

        } else {

            res = findRecoverableResourceForXaResource(xares);

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

            if ( res == null ) {
                  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.";
                  LOGGER.logWarning ( msg );
                    throw new javax.transaction.SystemException ( msg );
            }

            try {
                restx = (XAResourceTransaction) res
                        .getResourceTransaction ( ct_ );

                // next, we MUST set the xa resource again,
                // because ONLY the instance we got as argument
                // is available for use now !
View Full Code Here

        return true;
    }

  private TransactionalResource findRecoverableResourceForXaResource(
      XAResource xares ) {
    TransactionalResource ret = null;
    XATransactionalResource xatxres;
    Enumeration enumm = Configuration.getResources ();

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

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

            }

        }

        if ( ret == null && autoRegistration_ ) {

            synchronized ( Configuration.class ) {
              // synchronized to avoid case 61740

              ret = new TemporaryXATransactionalResource(xares);
              // cf case 61740: check for concurrent additions before this synch block was entered
              if ( Configuration.getResource ( ret.getName() ) == null ) {
                if(LOGGER.isDebugEnabled()){
                  LOGGER.logDebug("constructing new temporary resource "
                    + "for unknown XAResource: " + xares);
                }
                Configuration.addResource ( ret );
View Full Code Here

TOP

Related Classes of com.atomikos.datasource.TransactionalResource

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.