本文整理了Java中javax.transaction.Transaction.getStatus()
方法的一些代码示例,展示了Transaction.getStatus()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.getStatus()
方法的具体详情如下:
包路径:javax.transaction.Transaction
类名称:Transaction
方法名:getStatus
[英]Get the status of the transaction.
[中]获取事务的状态。
代码示例来源:origin: hibernate/hibernate-orm
@Override
public void doBeforeTransactionCompletion(SessionImplementor session) {
try {
// Wait for the transaction to be rolled back by the Reaper thread.
final Transaction transaction = TestingJtaPlatformImpl.transactionManager().getTransaction();
while ( transaction.getStatus() != Status.STATUS_ROLLEDBACK )
Thread.sleep( 10 );
}
catch ( Exception e ) {
// we aren't concerned with this.
}
}
}
代码示例来源:origin: wildfly/wildfly
if(transactionManager != null) {
try {
final Transaction transactionOnReset = transactionManager.getTransaction();
if(transactionOnReset != null && !transactionOnReset.equals(transactionOnSetup)) {
switch (transactionOnReset.getStatus()) {
case Status.STATUS_ACTIVE:
case Status.STATUS_COMMITTING:
代码示例来源:origin: hibernate/hibernate-orm
txn = transactionManager.getTransaction();
if ( txn == null ) {
throw new HibernateException( "Unable to locate current JTA transaction" );
if ( !JtaStatusHelper.isActive( txn.getStatus() ) ) {
代码示例来源:origin: apache/geode
if (!this.ignoreJTA && this.cache.getJTATransactionManager() != null) {
Transaction jtaTransaction = this.cache.getJTATransactionManager().getTransaction();
if (jtaTransaction == null
|| jtaTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
return null;
代码示例来源:origin: kiegroup/jbpm
.getTransaction();
if (tx != null) {
int testTxState = tx.getStatus();
if (testTxState != Status.STATUS_NO_TRANSACTION
&& testTxState != Status.STATUS_ROLLEDBACK
代码示例来源:origin: mulesoft/mule
@Test
public void testTxManagerCommitDissassociatesThread() throws Exception {
// don't wait for ages, has to be set before TX is begun
tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
tm.begin();
Transaction tx = tm.getTransaction();
assertNotNull("Transaction should have started.", tx);
assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus());
tm.commit();
assertNull("Committing via TX Manager should have disassociated TX from the current thread.", tm.getTransaction());
}
代码示例来源:origin: mulesoft/mule
@Test
public void testTxManagerRollbackDissassociatesThread() throws Exception {
// don't wait for ages, has to be set before TX is begun
tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
tm.begin();
Transaction tx = tm.getTransaction();
assertNotNull("Transaction should have started.", tx);
assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus());
tm.rollback();
assertNull("Committing via TX Manager should have disassociated TX from the current thread.", tm.getTransaction());
}
代码示例来源:origin: mulesoft/mule
@Test
public void testTxHandleCommitKeepsThreadAssociation() throws Exception {
// don't wait for ages, has to be set before TX is begun
tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
tm.begin();
Transaction tx = tm.getTransaction();
assertNotNull("Transaction should have started.", tx);
assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus());
tx.commit();
tx = tm.getTransaction();
assertNotNull("Committing via TX handle should NOT disassociated TX from the current thread.", tx);
assertEquals("TX status should have been COMMITTED.", Status.STATUS_COMMITTED, tx.getStatus());
// Remove the TX-thread association. The only public API to achieve it is suspend(),
// technically we never resume the same transaction (TX forget).
Transaction suspended = tm.suspend();
assertTrue("Wrong TX suspended?.", suspended.equals(tx));
assertNull("TX should've been disassociated from the thread.", tm.getTransaction());
// should be no-op and never fail
tm.resume(null);
// ensure we don't have any TX-Thread association lurking around a main thread
assertNull(tm.getTransaction());
}
代码示例来源:origin: mulesoft/mule
@Override
public Void process() throws Exception {
// the callee executes within its own TX template, but uses the same global XA transaction,
// bound to the current thread of execution via a ThreadLocal
ExecutionTemplate<Void> nestedExecutionTemplate =
TransactionalExecutionTemplate.createTransactionalExecutionTemplate(muleContext, nestedConfig);
final Transaction firstTx = tm.getTransaction();
assertNotNull(firstTx);
assertEquals(firstTx.getStatus(), Status.STATUS_ACTIVE);
return nestedExecutionTemplate.execute(new ExecutionCallback<Void>() {
@Override
public Void process() throws Exception {
Transaction secondTx = tm.getTransaction();
assertNull(secondTx);
assertEquals(firstTx.getStatus(), Status.STATUS_ACTIVE);
try {
tm.resume(firstTx);
assertEquals(firstTx, tm.getTransaction());
assertEquals(firstTx.getStatus(), Status.STATUS_ACTIVE);
Transaction a = tm.suspend();
assertTrue(a.equals(firstTx));
} catch (Exception e) {
fail("Error: " + e);
}
// do not care about the return really
return null;
}
});
}
});
代码示例来源:origin: mulesoft/mule
@Test
public void isRollbackOnly() throws Exception {
javax.transaction.Transaction tx = mock(javax.transaction.Transaction.class);
when(tx.getStatus()).thenReturn(Transaction.STATUS_ACTIVE).thenReturn(Transaction.STATUS_COMMITTED)
.thenReturn(Transaction.STATUS_MARKED_ROLLBACK).thenReturn(Transaction.STATUS_ROLLEDBACK)
.thenReturn(Transaction.STATUS_ROLLING_BACK);
when(mockTransactionManager.getTransaction()).thenReturn(tx);
XaTransaction xaTransaction = new XaTransaction(mockMuleContext);
xaTransaction.begin();
assertFalse(xaTransaction.isRollbackOnly());
assertFalse(xaTransaction.isRollbackOnly());
assertTrue(xaTransaction.isRollbackOnly());
assertTrue(xaTransaction.isRollbackOnly());
assertTrue(xaTransaction.isRollbackOnly());
}
代码示例来源:origin: mulesoft/mule
final Transaction firstTx = tm.getTransaction();
assertNotNull(firstTx);
assertEquals(firstTx.getStatus(), Status.STATUS_ACTIVE);
return innerExecutionTemplate.execute(new ExecutionCallback<Void>() {
代码示例来源:origin: org.apache.tomee/openejb-core
@Override
public boolean isActive() {
try {
final int status = transactionManager.getTransaction().getStatus();
return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK
|| status == Status.STATUS_PREPARED || status == Status.STATUS_PREPARING
|| status == Status.STATUS_COMMITTING || status == Status.STATUS_ROLLING_BACK
|| status == Status.STATUS_UNKNOWN;
} catch (final Throwable e) {
return false;
}
}
代码示例来源:origin: apache/meecrowave
@Override
public boolean isActive() {
try {
final int status = transactionManager.getTransaction().getStatus();
return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK
|| status == Status.STATUS_PREPARED || status == Status.STATUS_PREPARING
|| status == Status.STATUS_COMMITTING || status == Status.STATUS_ROLLING_BACK
|| status == Status.STATUS_UNKNOWN;
} catch (final Throwable e) {
return false;
}
}
代码示例来源:origin: org.apache.geronimo.ext.openejb/openejb-core
public static Transaction getTransactionIfActive(TransactionManager transactionManager) {
Transaction transaction = null;
int status = Status.STATUS_NO_TRANSACTION;
try {
transaction = transactionManager.getTransaction();
if (transaction != null) status = transaction.getStatus();
} catch (SystemException ignored) {
}
if (transaction != null && status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) {
return transaction;
}
return null;
}
代码示例来源:origin: org.apache.geronimo.components/geronimo-connector
public static Transaction getTransactionIfActive(TransactionManager transactionManager) {
Transaction transaction = null;
int status = Status.STATUS_NO_TRANSACTION;
try {
transaction = transactionManager.getTransaction();
if (transaction != null) status = transaction.getStatus();
} catch (SystemException ignored) {
}
if (transaction != null && status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) {
return transaction;
}
return null;
}
代码示例来源:origin: com.butor/butor-dao
private boolean isXa() {
if(transactionManager == null)
return false;
try {
Transaction tx = transactionManager.getTransaction();
if(tx == null)
return false;
boolean inTransaction = tx.getStatus() != Status.STATUS_NO_TRANSACTION;
Preconditions.checkArgument(!(xaDataSource == null && inTransaction),"In a XA Transaction but no XA Datasource available!");
return inTransaction;
} catch(Throwable e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.apache.tomee/openejb-core
private Transaction getActiveTransaction() {
try {
final Transaction transaction = transactionManager.getTransaction();
if (transaction == null) {
throw new IllegalStateException("No transaction active");
}
final int status = transaction.getStatus();
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("No transaction active");
}
return transaction;
} catch (final SystemException e) {
throw new IllegalStateException("No transaction active", e);
}
}
代码示例来源:origin: org.apache.geronimo.ext.openejb/openejb-core
private Transaction getActiveTransaction() {
try {
Transaction transaction = transactionManager.getTransaction();
if (transaction == null) {
throw new IllegalStateException("No transaction active");
}
int status = transaction.getStatus();
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("No transaction active");
}
return transaction;
} catch (SystemException e) {
throw new IllegalStateException("No transaction active", e);
}
}
代码示例来源:origin: org.apache.openejb/openejb-core
private Transaction getActiveTransaction() {
try {
final Transaction transaction = transactionManager.getTransaction();
if (transaction == null) {
throw new IllegalStateException("No transaction active");
}
final int status = transaction.getStatus();
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("No transaction active");
}
return transaction;
} catch (final SystemException e) {
throw new IllegalStateException("No transaction active", e);
}
}
代码示例来源:origin: kumuluz/kumuluzee
public static Boolean isActive(TransactionManager transactionManager) {
try {
Transaction tx = transactionManager.getTransaction();
return tx != null && JtaTransactionHolder.TRANSACTION_ACTIVE_STATUS.contains(tx.getStatus());
} catch (SystemException e) {
throw new CannotRetrieveTxException(e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!