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


Java XAResource類代碼示例

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


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

示例1: testXARecover

import javax.transaction.xa.XAResource; //導入依賴的package包/類
private void testXARecover(CloudSpannerXAConnection xaConnection) throws SQLException, XAException
{
	log.info("Started XA recover transaction test");
	testXATransaction(xaConnection, CommitMode.None);
	Xid[] xids = xaConnection.recover(XAResource.TMSTARTRSCAN);
	Assert.assertEquals(1, xids.length);
	xaConnection.commit(xids[0], false);
	boolean found = false;
	try (ResultSet rs = xaConnection.getConnection().createStatement()
			.executeQuery("select * from test where id=1000000"))
	{
		if (rs.next())
			found = true;
	}
	Assert.assertTrue(found);
	log.info("Finished XA recover transaction test");
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:18,代碼來源:XATester.java

示例2: testBug46925

import javax.transaction.xa.XAResource; //導入依賴的package包/類
public void testBug46925() throws Exception {
    MysqlXADataSource xads1 = new MysqlXADataSource();
    MysqlXADataSource xads2 = new MysqlXADataSource();

    Xid txid = new MysqlXid(new byte[] { 0x1 }, new byte[] { 0xf }, 3306);

    xads1.setPinGlobalTxToPhysicalConnection(true);
    xads1.setUrl(dbUrl);

    xads2.setPinGlobalTxToPhysicalConnection(true);
    xads2.setUrl(dbUrl);

    XAConnection c1 = xads1.getXAConnection();
    assertTrue(c1 instanceof SuspendableXAConnection);
    // start a transaction on one connection
    c1.getXAResource().start(txid, XAResource.TMNOFLAGS);
    c1.getXAResource().end(txid, XAResource.TMSUCCESS);

    XAConnection c2 = xads2.getXAConnection();
    assertTrue(c2 instanceof SuspendableXAConnection);
    // prepare on another one. Since we are using a "pinned" connection we should have the same "currentXAConnection" for both SuspendableXAConnection
    c2.getXAResource().prepare(txid); // this will fail without the fix.
    c2.getXAResource().commit(txid, false);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:25,代碼來源:ConnectionRegressionTest.java

示例3: start

import javax.transaction.xa.XAResource; //導入依賴的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

示例4: rollbackXaTranInner

import javax.transaction.xa.XAResource; //導入依賴的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

示例5: associate

import javax.transaction.xa.XAResource; //導入依賴的package包/類
@Override
public void associate(Connection connection) throws SQLException {
    try {
        if ( transactionRunning() ) {
            boolean newEnlistment = transactionSynchronizationRegistry.getResource( key ) == null;
            transactionSynchronizationRegistry.registerInterposedSynchronization( new InterposedSynchronization( connection ) );

            if ( newEnlistment ) {
                transactionSynchronizationRegistry.putResource( key, connection );
                XAResource resource = connectable ? new ConnectableLocalXAResource( (TransactionAware) connection, jndiName ) : new LocalXAResource( (TransactionAware) connection, jndiName );
                transactionManager.getTransaction().enlistResource( resource );
            }
            else {
                ( (TransactionAware) connection ).transactionStart();
            }
        } else {
            ( (TransactionAware) connection ).transactionCheckCallback( this::transactionRunning );
        }
    } catch ( Exception e ) {
        throw new SQLException( "Exception in association of connection to existing transaction", e );
    }
}
 
開發者ID:agroal,項目名稱:agroal,代碼行數:23,代碼來源:NarayanaTransactionIntegration.java

示例6: connectionClosed

import javax.transaction.xa.XAResource; //導入依賴的package包/類
/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection close event.
 * 
 * @param event Connection event object
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      XAConnection conn = (XAConnection) event.getSource();
      XAResource xar = (XAResource) xaResourcesMap.get(conn);
      xaResourcesMap.remove(conn);
      Transaction txn = transManager.getTransaction();
      if (txn != null && xar != null)
        txn.delistResource(xar, XAResource.TMSUCCESS);
      provider.returnConnection(conn);
    } catch (Exception e) {
      String exception =
          "GemFireTransactionDataSource::connectionClosed: Exception occured due to " + e;
      if (logger.isDebugEnabled()) {
        logger.debug(exception, e);
      }
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:GemFireTransactionDataSource.java

示例7: registerTranxConnection

import javax.transaction.xa.XAResource; //導入依賴的package包/類
/**
 *  
 */
void registerTranxConnection(XAConnection xaConn) throws Exception {
  try {
    synchronized (this) {
      if (transManager == null) {
        transManager = JNDIInvoker.getTransactionManager();
      }
    }
    Transaction txn = transManager.getTransaction();
    if (txn != null) {
      XAResource xar = xaConn.getXAResource();
      txn.enlistResource(xar);
      // Add in the Map after successful registration of XAResource
      this.xaResourcesMap.put(xaConn, xar);
    }
  } catch (Exception ex) {
    Exception e = new Exception(
        LocalizedStrings.GemFireTransactionDataSource_GEMFIRETRANSACTIONDATASOURCEREGISTERTRANXCONNECTION_EXCEPTION_IN_REGISTERING_THE_XARESOURCE_WITH_THE_TRANSACTIONEXCEPTION_OCCURED_0
            .toLocalizedString(ex));
    e.initCause(ex);
    throw e;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:GemFireTransactionDataSource.java

示例8: getXAResource

import javax.transaction.xa.XAResource; //導入依賴的package包/類
@Override
public XAResource getXAResource() {
    final PooledSessionHolder session;
    try {
        session = safeGetSessionHolder();
    } catch (JMSException e) {
        throw JMSExceptionSupport.createRuntimeException(e);
    }

    if (session.getSession() instanceof XASession) {
        return ((XASession) session.getSession()).getXAResource();
    }

    return null;
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:16,代碼來源:JmsPoolSession.java

示例9: isSameRM

import javax.transaction.xa.XAResource; //導入依賴的package包/類
@Override
public boolean isSameRM(XAResource xares) throws XAException
{
	// This trivial implementation makes sure that the
	// application server doesn't try to use another connection
	// for prepare, commit and rollback commands.
	return xares == this;
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:9,代碼來源:CloudSpannerXAConnection.java

示例10: testStart

import javax.transaction.xa.XAResource; //導入依賴的package包/類
@Test
public void testStart() throws SQLException, XAException
{
	CloudSpannerXAConnection subject = createSubject();
	ICloudSpannerConnection connection = subject.getConnection();
	assertTrue(connection.getAutoCommit());
	Xid xid = createXid();
	subject.start(xid, XAResource.TMNOFLAGS);
	assertNotNull(connection);
	assertFalse(connection.getAutoCommit());
	thrown.expect(CloudSpannerSQLException.class);
	connection.commit();
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:14,代碼來源:CloudSpannerXAConnectionTest.java

示例11: testEnd

import javax.transaction.xa.XAResource; //導入依賴的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

示例12: testPrepare

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

示例13: testCommitOnePhase

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

示例14: testCommitTwoPhase

import javax.transaction.xa.XAResource; //導入依賴的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

示例15: testXATransaction

import javax.transaction.xa.XAResource; //導入依賴的package包/類
private void testXATransaction(CloudSpannerXAConnection xaConnection, CommitMode mode)
		throws SQLException, XAException
{
	log.info("Starting XA simple transaction test");
	Random rnd = new Random();
	Connection connection = xaConnection.getConnection();
	int id = rnd.nextInt();
	Xid xid = RecoveredXid.stringToXid(String.valueOf(id) + "_Z3RyaWQ=_YnF1YWw=");
	xaConnection.start(xid, XAResource.TMNOFLAGS);
	String sql = "insert into test (id, uuid, active, amount, description, created_date, last_updated) values (?, ?, ?, ?, ?, ?, ?)";
	PreparedStatement statement = connection.prepareStatement(sql);
	setParameterValues(statement, 1000000);
	statement.executeUpdate();
	xaConnection.end(xid, XAResource.TMSUCCESS);
	xaConnection.prepare(xid);
	if (mode != CommitMode.None)
	{
		xaConnection.commit(xid, mode == CommitMode.OnePhase);
	}

	if (mode != CommitMode.None)
	{
		boolean found = false;
		try (ResultSet rs = connection.createStatement().executeQuery("select * from test where id=1000000"))
		{
			if (rs.next())
				found = true;
		}
		Assert.assertTrue(found);
	}
	log.info("Finished XA simple transaction test");
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:33,代碼來源:XATester.java


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