当前位置: 首页>>代码示例>>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;未经允许,请勿转载。