Java Code Examples for javax.transaction.xa.XAException#XAER_NOTA

The following examples show how to use javax.transaction.xa.XAException#XAER_NOTA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericXaResource.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.transaction.xa.XAResource#start(javax.transaction.xa.Xid xid, int flag)
 */
public void start(Xid xid, int flag) throws XAException {
    if (this.active) {
        if (this.xid != null && this.xid.equals(xid)) {
            throw new XAException(XAException.XAER_DUPID);
        }
        throw new XAException(XAException.XAER_PROTO);
    }
    if (this.xid != null && !this.xid.equals(xid)) {
        throw new XAException(XAException.XAER_NOTA);
    }

    this.setName("GenericXaResource-Thread");
    this.setDaemon(true);
    this.active = true;
    this.xid = xid;
    this.start();
}
 
Example 2
Source File: TransactionCoordinator.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** supports suspend only, for tcc transaction manager. */
public void end(Xid xid, int flags) throws XAException {
	if (XAResource.TMSUSPEND != flags) {
		throw new XAException(XAException.XAER_INVAL);
	}
	TransactionManager transactionManager = this.beanFactory.getTransactionManager();
	XidFactory xidFactory = this.beanFactory.getXidFactory();
	Transaction transaction = transactionManager.getTransactionQuietly();
	if (transaction == null) {
		throw new XAException(XAException.XAER_NOTA);
	}
	TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionXid transactionXid = transactionContext.getXid();

	TransactionXid branchXid = (TransactionXid) xid;
	TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId());

	if (CommonUtils.equals(globalXid, transactionXid) == false) {
		throw new XAException(XAException.XAER_INVAL);
	}
	transactionManager.desociateThread();
}
 
Example 3
Source File: GenericXaResource.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.transaction.xa.XAResource#end(javax.transaction.xa.Xid xid, int flag)
 */
public void end(Xid xid, int flag) throws XAException {
    if (!this.active) {
        throw new XAException(XAException.XAER_PROTO);
    }

    if (this.xid == null || !this.xid.equals(xid)) {
        throw new XAException(XAException.XAER_NOTA);
    }
    this.active = false;
}
 
Example 4
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void invokeOnePhaseCommit(XAResourceArchive archive) throws XAException {
	try {
		archive.commit(archive.getXid(), true);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
		case XAException.XA_HEURHAZ:
		case XAException.XA_HEURMIX:
		case XAException.XA_HEURRB:
			logger.warn("An error occurred in one phase commit: {}, transaction has been completed!",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw xaex;
		case XAException.XAER_RMFAIL:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw xaex;
		case XAException.XAER_NOTA:
		case XAException.XAER_INVAL:
		case XAException.XAER_PROTO:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw new XAException(XAException.XAER_RMERR);
		case XAException.XAER_RMERR:
		case XAException.XA_RBCOMMFAIL:
		case XAException.XA_RBDEADLOCK:
		case XAException.XA_RBINTEGRITY:
		case XAException.XA_RBOTHER:
		case XAException.XA_RBPROTO:
		case XAException.XA_RBROLLBACK:
		case XAException.XA_RBTIMEOUT:
		case XAException.XA_RBTRANSIENT:
		default:
			logger.warn("An error occurred in one phase commit: {}, transaction has been rolled back!",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw new XAException(XAException.XA_HEURRB);
		}
	}
}
 
Example 5
Source File: GenericXaResource.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.transaction.xa.XAResource#prepare(javax.transaction.xa.Xid xid)
 */
public int prepare(Xid xid) throws XAException {
    if (this.xid == null || !this.xid.equals(xid)) {
        throw new XAException(XAException.XAER_NOTA);
    }
    return XA_OK;
}
 
Example 6
Source File: ServiceXaWrapper.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.transaction.xa.XAResource#commit(javax.transaction.xa.Xid xid, boolean onePhase)
 */
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
    if (Debug.verboseOn()) Debug.logVerbose("ServiceXaWrapper#commit() : " + onePhase + " / " + xid.toString(), module);
    // the commit listener
    if (this.active) {
        Debug.logWarning("commit() called without end()", module);
    }
    if (this.xid == null || !this.xid.equals(xid)) {
        throw new XAException(XAException.XAER_NOTA);
    }

    final String service = commitService;
    final Map<String, ? extends Object> context = commitContext;
    final boolean persist = commitAsyncPersist;
    final boolean async = commitAsync;

    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                runService(service, context, persist, (async ? MODE_ASYNC : MODE_SYNC), TYPE_COMMIT);
            } catch (XAException e) {
                Debug.logError(e, module);
            }
        }
    };
    thread.start();

    this.xid = null;
    this.active = false;
}
 
Example 7
Source File: ServiceXaWrapper.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.transaction.xa.XAResource#rollback(javax.transaction.xa.Xid xid)
 */
@Override
public void rollback(Xid xid) throws XAException {
    if (Debug.verboseOn()) Debug.logVerbose("ServiceXaWrapper#rollback() : " + xid.toString(), module);
    // the rollback listener
    if (this.active) {
        Debug.logWarning("rollback() called without end()", module);
    }
    if (this.xid == null || !this.xid.equals(xid)) {
        throw new XAException(XAException.XAER_NOTA);
    }

    final String service = rollbackService;
    final Map<String, ? extends Object> context = rollbackContext;
    final boolean persist = rollbackAsyncPersist;
    final boolean async = rollbackAsync;

    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                runService(service, context, persist, (async ? MODE_ASYNC : MODE_SYNC), TYPE_ROLLBACK);
            } catch (XAException e) {
                Debug.logError(e, module);
            }
        }
    };
    thread.start();

    this.xid = null;
    this.active = false;
}
 
Example 8
Source File: XAXactId.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
   * Construct an Xid using an external Xid.
   * <p>
   * @exception XAException invalid external xid
   */
  public XAXactId(Xid xid) throws XAException
  {
if (xid == null)
	throw new XAException(XAException.XAER_NOTA);
	
      copy_init_xid(
			  xid.getFormatId(),
			  xid.getGlobalTransactionId(),
			  xid.getBranchQualifier());
  }
 
Example 9
Source File: XAXactId.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * Construct an Xid using an external Xid.
   * <p>
   * @exception XAException invalid external xid
   */
  public XAXactId(Xid xid) throws XAException
  {
if (xid == null)
	throw new XAException(XAException.XAER_NOTA);
	
      copy_init_xid(
			  xid.getFormatId(),
			  xid.getGlobalTransactionId(),
			  xid.getBranchQualifier());
  }
 
Example 10
Source File: EhcacheXAResource.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Override
public void forget(Xid xid) throws XAException {
  TransactionId transactionId = new TransactionId(xid);
  if (journal.isInDoubt(transactionId)) {
    throw new EhcacheXAException("Cannot forget in-doubt XID : " + xid, XAException.XAER_PROTO);
  }
  if (!journal.isHeuristicallyTerminated(transactionId)) {
    throw new EhcacheXAException("Cannot forget unknown XID : " + xid, XAException.XAER_NOTA);
  }
  journal.forget(transactionId);
}
 
Example 11
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forget(Xid xid) throws XAException {
	for (int i = 0; i < this.resources.size(); i++) {
		XAResourceArchive archive = this.resources.get(i);
		Xid currentXid = archive.getXid();
		if (archive.isHeuristic() == false) {
			continue;
		}

		try {
			Xid branchXid = archive.getXid();
			archive.forget(branchXid);
		} catch (XAException xae) {
			// Possible exception values are XAER_RMERR, XAER_RMFAIL
			// , XAER_NOTA, XAER_INVAL, or XAER_PROTO.
			switch (xae.errorCode) {
			case XAException.XAER_RMERR:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_RMFAIL:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_NOTA:
			case XAException.XAER_INVAL:
			case XAException.XAER_PROTO:
				break;
			default:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
			}
		}

	} // end-for
}
 
Example 12
Source File: XAXactId.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * Construct an Xid using an external Xid.
   * <p>
   * @exception XAException invalid external xid
   */
  public XAXactId(Xid xid) throws XAException
  {
if (xid == null)
	throw new XAException(XAException.XAER_NOTA);
	
      copy_init_xid(
			  xid.getFormatId(),
			  xid.getGlobalTransactionId(),
			  xid.getBranchQualifier());
  }
 
Example 13
Source File: XATerminatorOptd.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forget(Xid xid) throws XAException {
	if (this.archive == null) {
		return;
	}

	Xid currentXid = archive.getXid();
	if (archive.isHeuristic()) {
		try {
			Xid branchXid = archive.getXid();
			archive.forget(branchXid);
		} catch (XAException xae) {
			// Possible exception values are XAER_RMERR, XAER_RMFAIL
			// , XAER_NOTA, XAER_INVAL, or XAER_PROTO.
			switch (xae.errorCode) {
			case XAException.XAER_RMERR:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_RMFAIL:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_NOTA:
			case XAException.XAER_INVAL:
			case XAException.XAER_PROTO:
				break;
			default:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
			}
		}
	} // end-if
}
 
Example 14
Source File: xaHelper.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void handleException(Throwable t) throws SQLException
{
	if (t instanceof SQLException)
	{
		// let ij handle it
		throw (SQLException)t;
	}
	if (t instanceof XAException)
	{
		int errorCode = ((XAException)t).errorCode;
		String error = LocalizedResource.getMessage("IJ_IlleValu");

		// XA_RBBASE 100
		// XA_RBROLLBACK 100
		// XA_RBCOMMFAIL 101
		// XA_RBDEADLOCK 102
		// XA_RBINTEGRITY 103
		// XA_RBOTHER 104
		// XA_RBPROTO 105
		// XA_RBTIMEOUT 106
		// XA_RBTRANSIENT 107
		// XA_RBEND 107
		//
		// XA_RDONLY 3
		// XA_RETRY 4
		// XA_HEURMIX 5
		// XA_HEURRB 6
		// XA_HEURCOM 7
		// XA_HEURHAZ 8
		// XA_NOMIGRATE 9
		//
		// XAER_ASYNC -2
		// XAER_RMERR -3
		// XAER_NOTA -4
		// XAER_INVAL -5
		// XAER_PROTO -6
		// XAER_RMFAIL -7
		// XAER_DUPID -8
		// XAER_OUTSIDE -9

		switch(errorCode)
		{
		case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
		case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
		case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
		case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
		case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
			// case XAException.XA_RBBASE : error = "XA_RBBASE "; break;
		case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
		case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
			// case XAException.XA_RBEND : error = "XA_RBEND "; break;
		case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
		case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
		case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
		case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
		case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
		case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
		case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
		case XAException.XA_RETRY : error = "XA_RETRY "; break;
		case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
		case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
		case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
		case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
		case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
		case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
		case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
		case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
		}
		//t.printStackTrace(System.out);
		throw new ijException(error);

	}
	else // StandardException or run time exception, log it first
	{
		String info = LocalizedResource.getMessage("IJ_01SeeLog", t.toString(), t.getMessage());
		//		t.printStackTrace(System.out);
		throw new ijException(info);
	}
}
 
Example 15
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * The {@code internalCommit} method performs the requested commit and may throw an XAException to be interpreted
 * by the caller.
 *
 * @param xid
 *         a {@code Xid} value
 * @param onePhase
 *         a {@code true} if this is not a two-phase commit (not a distributed transaction)
 * @throws XAException
 *         if an error occurs
 */
void internalCommit(Xid xid, boolean onePhase) throws XAException {
    if (log.isTraceEnabled()) log.trace("Commit called: " + xid);
    FbTransaction committingTr = xidMap.get(xid);

    // check that prepare has NOT been called when onePhase = true
    if (onePhase && isPrepared(xid)) {
        throw new FBXAException("Cannot commit one-phase when transaction has been prepared", XAException.XAER_PROTO);
    }

    // check that prepare has been called when onePhase = false
    if (!onePhase && !isPrepared(xid)) {
        throw new FBXAException("Cannot commit two-phase when transaction has not been prepared", XAException.XAER_PROTO);
    }

    if (committingTr == null) {
        throw new FBXAException("Commit called with unknown transaction", XAException.XAER_NOTA);
    }

    try {
        if (committingTr == getGDSHelper().getCurrentTransaction()) {
            throw new FBXAException("Commit called with non-ended xid", XAException.XAER_PROTO);
        }

        committingTr.commit();
    } catch (SQLException ge) {
        if (gdsHelper != null) {
            try {
                committingTr.rollback();
            } catch (SQLException ge2) {
                log.debug("Exception rolling back failed tx: ", ge2);
            }
        } else {
            log.warn("Unable to rollback failed tx, connection closed or lost");
        }
        throw new FBXAException(ge.getMessage(), XAException.XAER_RMERR, ge);
    } finally {
        xidMap.remove(xid);
        preparedXid.remove(xid);
    }
}
 
Example 16
Source File: EmbedXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Inform the resource manager to roll back work done on behalf of a
 * transaction branch
 *
 * @param xid A global transaction identifier
 * @exception XAException - An error has occurred
 */
public final synchronized void rollback(Xid xid) throws XAException {
    checkXAActive();
    
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    
    XATransactionState tranState = getTransactionState(xid_im);
    
    if (tranState == null) {
      // Gemstone changes BEGIN
      throw new XAException(XAException.XAER_NOTA);
      /* original code
        XAResourceManager rm = ra.getXAResourceManager();
        
        ContextManager inDoubtCM = rm.find(xid);
        
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        
        ContextService csf = ContextService.getFactory();
        
        csf.setCurrentContextManager(inDoubtCM);
        try {
            rm.rollback(inDoubtCM, xid_im);
            
            // close the connection/transaction since it can never be used again.
            inDoubtCM.cleanupOnError(StandardException.closeException());
            return;
        } catch (StandardException se) {
            // The rm threw an exception, clean it up in the approprate
            // context.  There is no transactionResource to handle the
            // exception for us.
            inDoubtCM.cleanupOnError(se);
            throw wrapInXAException(se);
        } finally {
            csf.resetCurrentContextManager(inDoubtCM);
        }
      */
   // Gemstone changes END
    }
    
    synchronized (tranState) {
        
        // Check the transaction is no associated with
        // any XAResource.
        switch (tranState.associationState) {
            case XATransactionState.T0_NOT_ASSOCIATED:
            case XATransactionState.TRO_FAIL:
                break;
                
            default:
                throw new XAException(XAException.XAER_PROTO);
        }
        
        if (tranState.suspendedList != null 
                && tranState.suspendedList.size() != 0)
            throw new XAException(XAException.XAER_PROTO);
        
        checkUserCredentials(tranState.creatingResource);
        
        try {
            
            tranState.xa_rollback();
        } catch (SQLException sqle) {
            throw wrapInXAException(sqle);
        } finally {
            returnConnectionToResource(tranState, xid_im);
        }
    }
}
 
Example 17
Source File: EmbedXAResource.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the
 * transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome
 * of the transaction. The possible values are: XA_RDONLY or XA_OK. If the
 * resource manager wants to roll back the transaction, it should do so by
 * raising an appropriate XAException in the prepare method.
 *
 * @exception XAException An error has occurred. Possible exception values
 * are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or
 * XAER_PROTO.
 *
 */
public final synchronized int prepare(Xid xid) throws XAException {
    checkXAActive();
    
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    
    XATransactionState tranState = getTransactionState(xid_im);
    
    if (tranState == null) {
        XAResourceManager rm = ra.getXAResourceManager();
        
        ContextManager inDoubtCM = rm.find(xid);
        
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        
        // cannot prepare in doubt transactions
        throw new XAException(XAException.XAER_PROTO);
        
    }
    
    synchronized (tranState) {
        
        checkUserCredentials(tranState.creatingResource);
        
        // Check the transaction is no associated with
        // any XAResource.
        switch (tranState.associationState) {
            case XATransactionState.T0_NOT_ASSOCIATED:
                break;
                
            case XATransactionState.TRO_FAIL:
                throw new XAException(tranState.rollbackOnlyCode);
                
            default:
                throw new XAException(XAException.XAER_PROTO);
        }
        
        if (tranState.suspendedList != null 
                && !tranState.suspendedList.isEmpty())
            throw new XAException(XAException.XAER_PROTO);
        
        if (tranState.isPrepared)
            throw new XAException(XAException.XAER_PROTO);
        
        try {
            
            int ret = tranState.xa_prepare();
            
            if (ret == XATransactionController.XA_OK) {
                tranState.isPrepared = true;
                
                return XAResource.XA_OK;
            } else {
                
                returnConnectionToResource(tranState, xid_im);

	if (SanityManager.DEBUG) {
		if (con.realConnection != null) {
			SanityManager.ASSERT(
                            con.realConnection.transactionIsIdle(),
                            "real connection should have been idle." +
                            "tranState = " + tranState +
                            "ret = " + ret +
                            "con.realConnection = " + con.realConnection);
                    }
	}
                return XAResource.XA_RDONLY;
            }
        } catch (SQLException sqle) {
            throw wrapInXAException(sqle);
        }
    }
    
}
 
Example 18
Source File: XATransactionState.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
void start(EmbedXAResource resource, int flags) throws XAException {

		synchronized (this) {
			if (associationState == XATransactionState.TRO_FAIL)
				throw new XAException(rollbackOnlyCode);

			boolean isSuspendedByResource = (suspendedList != null) && (suspendedList.get(resource) != null);

			if (flags == XAResource.TMRESUME) {
				if (!isSuspendedByResource)
					throw new XAException(XAException.XAER_PROTO);

			} else {
				// cannot join a transaction we have suspended.
				if (isSuspendedByResource)
					throw new XAException(XAException.XAER_PROTO);
			}

			while (associationState == XATransactionState.T1_ASSOCIATED) {
				
				try {
					wait();
				} catch (InterruptedException ie) {
					throw new XAException(XAException.XA_RETRY);
				}
			}


			switch (associationState) {
			case XATransactionState.T0_NOT_ASSOCIATED:
				break;

            case XATransactionState.TRO_DEADLOCK:
            case XATransactionState.TRO_TIMEOUT:
			case XATransactionState.TRO_FAIL:
				throw new XAException(rollbackOnlyCode);

			default:
				throw new XAException(XAException.XAER_NOTA);
			}

			if (isPrepared)
				throw new XAException(XAException.XAER_PROTO);

			if (isSuspendedByResource) {
				suspendedList.remove(resource);
			}

			associationState = XATransactionState.T1_ASSOCIATED;
			associatedResource = resource;

		}
	}
 
Example 19
Source File: EmbedXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Ends the work performed on behalf of a transaction branch. The resource
 * manager disassociates the XA resource from the transaction branch
 * specified and let the transaction be completed.
 *
 * <p> If TMSUSPEND is specified in flags, the transaction branch is
 * temporarily suspended in incomplete state. The transaction context
 * is in suspened state and must be resumed via start with TMRESUME
 * specified.
 *
 * <p> If TMFAIL is specified, the portion of work has failed. The
 * resource manager may mark the transaction as rollback-only
 *
 * <p> If TMSUCCESS is specified, the portion of work has completed
 * successfully.
 *
 * @param xid A global transaction identifier that is the same as what was
 * used previously in the start method.
 * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND
 *
 * @exception XAException An error has occurred.
 * Possible XAException values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA,
 * XAER_INVAL, XAER_PROTO, or XA_RB*.
 */
public final synchronized void end(Xid xid, int flags) throws XAException {
    checkXAActive();
    
    try {
        // It is possible that the isolation level state in connection
        // handle has gotten out of sync with the real isolation level.
        // This can happen if SLQ instead of JDBC api has been used to
        // set the isolation level. The code below will check if isolation
        // was set using JDBC or SQL and if yes, then it will update the
        // isolation state in BrokeredConnection with EmbedConnection's
        // isolation level.
        if (con.currentConnectionHandle != null)
            con.currentConnectionHandle.getIsolationUptoDate();
    } catch (SQLException sqle) {
        throw wrapInXAException(sqle);
    }
    
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    
    boolean endingCurrentXid = false;
    
    // must match the Xid from start()
    if (currentXid != null) {
        if (!currentXid.equals(xid_im))
            throw new XAException(XAException.XAER_PROTO);
        endingCurrentXid = true;
    }
    
    XATransactionState tranState = getTransactionState(xid_im);
    if (tranState == null)
        throw new XAException(XAException.XAER_NOTA);
    
    boolean rollbackOnly = tranState.end(this, flags, endingCurrentXid);
    
    // RESOLVE - what happens to the connection on a fail
    // where we are not ending the current XID.
    if (endingCurrentXid) {
        currentXid = null;            
        con.realConnection = null;
    }
    
    if (rollbackOnly)
        throw new XAException(tranState.rollbackOnlyCode);        
}
 
Example 20
Source File: EmbedXAResource.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Inform the resource manager to roll back work done on behalf of a
 * transaction branch
 *
 * @param xid A global transaction identifier
 * @exception XAException - An error has occurred
 */
public final synchronized void rollback(Xid xid) throws XAException {
    checkXAActive();
    
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    
    XATransactionState tranState = getTransactionState(xid_im);
    
    if (tranState == null) {
        XAResourceManager rm = ra.getXAResourceManager();
        
        ContextManager inDoubtCM = rm.find(xid);
        
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        
        ContextService csf = ContextService.getFactory();
        
        csf.setCurrentContextManager(inDoubtCM);
        try {
            rm.rollback(inDoubtCM, xid_im);
            
            // close the connection/transaction since it can never be used again.
            inDoubtCM.cleanupOnError(StandardException.closeException(),
                    false);
            return;
        } catch (StandardException se) {
            // The rm threw an exception, clean it up in the approprate
            // context.  There is no transactionResource to handle the
            // exception for us.
            inDoubtCM.cleanupOnError(se, con.isActive());
            throw wrapInXAException(se);
        } finally {
            csf.resetCurrentContextManager(inDoubtCM);
        }
        
    }
    
    synchronized (tranState) {
        
        // Check the transaction is no associated with
        // any XAResource.
        switch (tranState.associationState) {
            case XATransactionState.T0_NOT_ASSOCIATED:
            case XATransactionState.TRO_FAIL:
                break;
                
            default:
                throw new XAException(XAException.XAER_PROTO);
        }
        
        if (tranState.suspendedList != null 
                && !tranState.suspendedList.isEmpty())
            throw new XAException(XAException.XAER_PROTO);
        
        checkUserCredentials(tranState.creatingResource);
        
        try {
            
            tranState.xa_rollback();
        } catch (SQLException sqle) {
            throw wrapInXAException(sqle);
        } finally {
            returnConnectionToResource(tranState, xid_im);
        }
    }
}