@Override
   public boolean enlistResource(XAResource resource) throws RollbackException, IllegalStateException, SystemException {
      if (trace) {
         log.tracef("Transaction.enlistResource(%s) invoked in transaction with Xid=%s", resource, xid);
      }
      checkStatusBeforeRegister("resource");

      //avoid duplicates
      for (Map.Entry<XAResource, Integer> otherResourceEntry : resources) {
         try {
            if (otherResourceEntry.getKey().isSameRM(resource)) {
               log.debug("Ignoring resource. It is already there.");
               return true;
            }
         } catch (XAException e) {
            //ignored
         }
      }

      resources.add(new AbstractMap.SimpleEntry<>(resource, null));

      try {
         if (trace) {
            log.tracef("XaResource.start() invoked in transaction with Xid=%s", xid);
         }
         resource.start(xid, XAResource.TMNOFLAGS);
      } catch (XAException e) {
         if (isRollbackCode(e)) {
            RollbackException exception = newRollbackException(format("Resource %s rolled back the transaction while XaResource.start()", resource), e);
            markRollbackOnly(exception);
            log.errorEnlistingResource(e);
            throw exception;
         }
         log.errorEnlistingResource(e);
         throw new SystemException(e.getMessage());
      }
      return true;
   }
@ Override public boolean enlistResource ( XAResource resource ) throws RollbackException , IllegalStateException , SystemException { if ( trace ) { log . tracef ( "Transaction.enlistResource(%s) invoked in transaction with Xid=%s" , resource , xid ) ; } checkStatusBeforeRegister ( "resource" ) ; for ( Map . Entry < XAResource , Integer > otherResourceEntry : resources ) { try { if ( otherResourceEntry . getKey ( ) . isSameRM ( resource ) ) { log . debug ( "Ignoring resource. It is already there." ) ; return true ; } } catch ( XAException e ) { } } resources . add ( new AbstractMap . SimpleEntry < > ( resource , null ) ) ; try { if ( trace ) { log . tracef ( "XaResource.start() invoked in transaction with Xid=%s" , xid ) ; } resource . start ( xid , XAResource . TMNOFLAGS ) ; } catch ( XAException e ) { if ( isRollbackCode ( e ) ) { RollbackException exception = newRollbackException ( format ( "Resource %s rolled back the transaction while XaResource.start()" , resource ) , e ) ; markRollbackOnly ( exception ) ; log . errorEnlistingResource ( e ) ; throw exception ; } log . errorEnlistingResource ( e ) ; throw new SystemException ( e . getMessage ( ) ) ; } return true ; }
Enlist an XA resource with this transaction.

@return <code>true</code> if the resource could be enlisted with this transaction, otherwise <code>false</code>.
@throws RollbackException     If the transaction is marked for rollback only.
@throws IllegalStateException If the transaction is in a state where resources cannot be enlisted. This could be
because the transaction is no longer active, or because it is in the {@link
Status#STATUS_PREPARED prepared state}.
@throws SystemException       If the transaction service fails in an unexpected way.