當前位置: 首頁>>代碼示例>>Java>>正文


Java XAException類代碼示例

本文整理匯總了Java中javax.transaction.xa.XAException的典型用法代碼示例。如果您正苦於以下問題:Java XAException類的具體用法?Java XAException怎麽用?Java XAException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XAException類屬於javax.transaction.xa包,在下文中一共展示了XAException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateXid

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * @throws XAException if the given Xid is the not the Xid of the
 *                     current transaction for this XAResource object.
 */
private void validateXid(Xid xid) throws XAException {

    if (xid == null) {
        throw new XAException("Null Xid");
    }

    if (this.xid == null) {
        throw new XAException(
            "There is no live transaction for this XAResource");
    }

    if (!xid.equals(this.xid)) {
        throw new XAException(
            "Given Xid is not that associated with this XAResource object");
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:21,代碼來源:JDBCXAResource.java

示例2: commit

import javax.transaction.xa.XAException; //導入依賴的package包/類
@Override
public void commit(Xid xid, boolean onePhase) throws XAException
{
	if (logger.logDebug())
	{
		debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)"));
	}

	if (xid == null)
	{
		throw new CloudSpannerXAException("xid must not be null", Code.INVALID_ARGUMENT, XAException.XAER_INVAL);
	}

	if (onePhase)
	{
		commitOnePhase(xid);
	}
	else
	{
		commitPrepared(xid);
	}
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:23,代碼來源:CloudSpannerXAConnection.java

示例3: testBug69506

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * Tests fix for BUG#69506 - XAER_DUPID error code is not returned when a duplicate XID is offered in Java.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug69506() throws Exception {
    MysqlXADataSource dataSource = new MysqlXADataSource();

    dataSource.setUrl(dbUrl);

    XAConnection testXAConn1 = dataSource.getXAConnection();
    XAConnection testXAConn2 = dataSource.getXAConnection();

    Xid duplicateXID = new MysqlXid("1".getBytes(), "1".getBytes(), 1);

    testXAConn1.getXAResource().start(duplicateXID, 0);

    try {
        testXAConn2.getXAResource().start(duplicateXID, 0);
        fail("XAException was expected.");
    } catch (XAException e) {
        assertEquals("Wrong error code retured for duplicated XID.", XAException.XAER_DUPID, e.errorCode);
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:26,代碼來源:ConnectionRegressionTest.java

示例4: end

import javax.transaction.xa.XAException; //導入依賴的package包/類
public void end(Xid xid, int flags) throws XAException {

        validateXid(xid);

        if (state != XA_STATE_STARTED) {
            throw new XAException("Invalid XAResource state");
        }

        try {
            connection.setAutoCommit(originalAutoCommitMode);    // real/phys.
        } catch (SQLException se) {
            throw new XAException(se.getMessage());
        }

        state = XA_STATE_ENDED;
    }
 
開發者ID:s-store,項目名稱:s-store,代碼行數:17,代碼來源:JDBCXAResource.java

示例5: forget

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * The XAResource API spec indicates implies that this is only for
 * 2-phase transactions.
 * I guess that one-phase transactions need to call rollback() to abort.
 *
 * I think we want this JDBCXAResource instance to be garbage-collectable
 * after (a) this method is called, and (b) the tx manager releases its
 * handle to it.
 *
 * @see javax.transaction.xa.XAResource#forget(Xid)
 */
public void forget(Xid xid) throws XAException {

    /**
     * Should this method not attempt to clean up the aborted
     * transaction by rolling back or something?  Maybe the
     * tx manager will already have called rollback() if
     * it were necessasry?
     */
    validateXid(xid);

    if (state != XA_STATE_PREPARED) {
        throw new XAException(
            "Attempted to forget a XAResource that "
            + "is not in a heuristically completed state");
    }

    dispose();

    state = XA_STATE_INITIAL;
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:32,代碼來源:JDBCXAResource.java

示例6: rollbackThis

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * This rolls back the connection associated with <i>this</i> XAResource.
 *
 * @throws javax.transaction.xa.XAException generically, since the more
 * specific exceptions require a JTA API to compile.
 */
/* @throws javax.transaction.HeuristicCommitException
 *         if work was committed.
 * @throws javax.transaction.HeuristicMixedException
 *         if some work was committed and some work was rolled back
 */
public void rollbackThis() throws XAException {

    if (state != XA_STATE_PREPARED && state != XA_STATE_ENDED) {
        throw new XAException("Invalid XAResource state");
    }

    try {

        /**
         * @todo:  Determine if work was committed, rolled back, or both,
         * and return appropriate Heuristic Exception.
         */
        connection.rollback();    // real/phys.
    } catch (SQLException se) {
        throw new XAException(se.toString());
    }

    dispose();
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:31,代碼來源:JDBCXAResource.java

示例7: validateXid

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 *
 * @throws XAException if the given Xid is the not the Xid of the current
 *   transaction for this XAResource object.
 * @param xid Xid
 */
private void validateXid(Xid xid) throws XAException {

    if (xid == null) {
        throw new XAException("Null Xid");
    }

    if (this.xid == null) {
        throw new XAException(
            "There is no live transaction for this XAResource");
    }

    if (!xid.equals(this.xid)) {
        throw new XAException(
            "Given Xid is not that associated with this XAResource object");
    }
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:23,代碼來源:JDBCXAResource.java

示例8: start

import javax.transaction.xa.XAException; //導入依賴的package包/類
public void start(Xid xid, int flag) throws XAException {
    if (flag == XAResource.TMNOFLAGS) {
        // first time in this transaction
        if (this.xid != null) {
            throw new XAException("already enlisted");
        }
        this.xid = xid;
        try {
            localTransaction.begin();
        } catch (ResourceException e) {
            throw (XAException) new XAException("could not start local tx").initCause(e);
        }
    } else if (flag == XAResource.TMRESUME) {
        if (xid != this.xid) {
            throw new XAException("attempting to resume in different transaction");
        }
    } else {
        throw new XAException("unknown state");
    }
}
 
開發者ID:ops4j,項目名稱:org.ops4j.pax.transx,代碼行數:21,代碼來源:LocalXAResource.java

示例9: start

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * Starts work on behalf of a transaction branch specified in xid.
 * 
 * If TMJOIN is specified, the start applies to joining a transaction
 * previously seen by the resource manager.
 * 
 * If TMRESUME is specified, the start applies to resuming a suspended
 * transaction specified in the parameter xid.
 * 
 * If neither TMJOIN nor TMRESUME is specified and the transaction specified
 * by xid has previously been seen by the resource manager, the resource
 * manager throws the XAException exception with XAER_DUPID error code.
 * 
 * @parameter xid A global transaction identifier to be associated with the
 *            resource.
 * 
 * @parameter flags One of TMNOFLAGS, TMJOIN, or TMRESUME.
 * 
 * @throws XAException
 *             An error has occurred. Possible exceptions are XA_RB*,
 *             XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, XAER_NOTA,
 *             XAER_INVAL, or XAER_PROTO.
 */
public void start(Xid xid, int flags) throws XAException {
    StringBuilder commandBuf = new StringBuilder(MAX_COMMAND_LENGTH);
    commandBuf.append("XA START ");
    appendXid(commandBuf, xid);

    switch (flags) {
        case TMJOIN:
            commandBuf.append(" JOIN");
            break;
        case TMRESUME:
            commandBuf.append(" RESUME");
            break;
        case TMNOFLAGS:
            // no-op
            break;
        default:
            throw new XAException(XAException.XAER_INVAL);
    }

    dispatchCommand(commandBuf.toString());

    this.underlyingConnection.setInGlobalTx(true);
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:47,代碼來源:MysqlXAConnection.java

示例10: switchToXid

import javax.transaction.xa.XAException; //導入依賴的package包/類
private synchronized void switchToXid(Xid xid) throws XAException {
    if (xid == null) {
        throw new XAException();
    }

    try {
        if (!xid.equals(this.currentXid)) {
            XAConnection toSwitchTo = findConnectionForXid(this.underlyingConnection, xid);
            this.currentXAConnection = toSwitchTo;
            this.currentXid = xid;
            this.currentXAResource = toSwitchTo.getXAResource();
        }
    } catch (SQLException sqlEx) {
        throw new XAException();
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:17,代碼來源:SuspendableXAConnection.java

示例11: rollbackXaTranInner

import javax.transaction.xa.XAException; //導入依賴的package包/類
private int rollbackXaTranInner(List<Map> xaList){
	boolean flag=true;
	for(Map xaInfo:xaList){
		XAResource xaResource=(XAResource) xaInfo.get("xaResource");
		MyXid myXid=(MyXid) xaInfo.get("myXid");
		try {
			xaResource.rollback(myXid);
		} catch (XAException e) {
			flag=false;
			e.printStackTrace();
		}
	}
	if(flag==false){
		return 1;
	}
	return 0;		
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:18,代碼來源:WsXaTranCmdHandler.java

示例12: commit

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
     * Per the JDBC 3.0 spec, this commits the transaction for the specified
     * Xid, not necessarily for the transaction associated with this XAResource
     * object.
     *
     * @param xid Xid
     * @param onePhase boolean
     * @throws XAException
     */
    public void commit(Xid xid, boolean onePhase) throws XAException {

        // Comment out following debug statement before public release:
/*
        System.err.println("Performing a " + (onePhase ? "1-phase"
                                                       : "2-phase") + " commit on "
                                                       + xid);
*/
        JDBCXAResource resource = xaDataSource.getResource(xid);

        if (resource == null) {
            throw new XAException("The XADataSource has no such Xid:  " + xid);
        }

        resource.commitThis(onePhase);
    }
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:26,代碼來源:JDBCXAResource.java

示例13: testEnd

import javax.transaction.xa.XAException; //導入依賴的package包/類
@Test
public void testEnd() throws SQLException, XAException
{
	CloudSpannerXAConnection subject = createSubject();
	Xid xid = createXid();
	subject.start(xid, XAResource.TMNOFLAGS);
	subject.end(xid, XAResource.TMSUCCESS);
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:9,代碼來源:CloudSpannerXAConnectionTest.java

示例14: isSameRM

import javax.transaction.xa.XAException; //導入依賴的package包/類
/**
 * Stub. See implementation comment in the method for why this is not
 * implemented yet.
 *
 * @return false.
 * @param xares XAResource
 * @throws XAException
 */
public boolean isSameRM(XAResource xares) throws XAException {

    if (!(xares instanceof JDBCXAResource)) {
        return false;
    }

    return xaDataSource == ((JDBCXAResource) xares).getXADataSource();
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:17,代碼來源:JDBCXAResource.java

示例15: testCommitTwoPhase

import javax.transaction.xa.XAException; //導入依賴的package包/類
@Test
public void testCommitTwoPhase() throws SQLException, XAException
{
	CloudSpannerXAConnection subject = createSubject();
	Xid xid = createXid();
	subject.start(xid, XAResource.TMNOFLAGS);
	subject.end(xid, XAResource.TMSUCCESS);
	subject.prepare(xid);
	subject.commit(xid, false);
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:11,代碼來源:CloudSpannerXAConnectionTest.java


注:本文中的javax.transaction.xa.XAException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。