Refine search
@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. } } }
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:
txn = transactionManager.getTransaction(); if ( txn == null ) { throw new HibernateException( "Unable to locate current JTA transaction" ); if ( !JtaStatusHelper.isActive( txn.getStatus() ) ) {
if (!this.ignoreJTA && this.cache.getJTATransactionManager() != null) { Transaction jtaTransaction = this.cache.getJTATransactionManager().getTransaction(); if (jtaTransaction == null || jtaTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) { return null;
.getTransaction(); if (tx != null) { int testTxState = tx.getStatus(); if (testTxState != Status.STATUS_NO_TRANSACTION && testTxState != Status.STATUS_ROLLEDBACK
@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()); }
@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()); }
@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()); }
@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; } }); } });
@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()); }
final Transaction firstTx = tm.getTransaction(); assertNotNull(firstTx); assertEquals(firstTx.getStatus(), Status.STATUS_ACTIVE); return innerExecutionTemplate.execute(new ExecutionCallback<Void>() {
@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; } }
@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; } }
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; }
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; }
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); } }
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); } }
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); } }
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); } }
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); } } }