本文整理汇总了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");
}
示例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);
}
示例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");
}
}
示例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;
}
示例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 );
}
}
示例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);
}
}
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}