use of com.arjuna.ats.jta.exceptions.InvalidTerminationStateException in project narayana by jbosstm.
the class SubordinateTxUnitTest method testTransactionImple.
@Test
public void testTransactionImple() throws Exception {
TransactionImple tx = new TransactionImple(0);
TransactionImple dummy = new TransactionImple(0);
assertFalse(tx.equals(dummy));
try {
tx.commit();
fail();
} catch (final IllegalStateException ex) {
}
try {
tx.rollback();
fail();
} catch (InvalidTerminationStateException ex) {
}
assertEquals(tx.doPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
tx.doCommit();
dummy.doRollback();
tx = new TransactionImple(10);
tx.doOnePhaseCommit();
tx.doForget();
tx.doBeforeCompletion();
assertTrue(tx.toString() != null);
assertTrue(tx.activated());
}
use of com.arjuna.ats.jta.exceptions.InvalidTerminationStateException in project narayana by jbosstm.
the class TransactionImpleUnitTest method test.
@Test
public void test() throws Exception {
OTSImpleManager.current().begin();
TransactionImple tx = new TransactionImple(new SubordinateAtomicTransaction(new ServerControlWrapper(OTSImpleManager.current().get_control())));
assertFalse(tx.equals(null));
assertTrue(tx.equals(tx));
assertFalse(tx.equals(new TransactionImple(new AtomicTransaction())));
assertFalse(tx.equals(new Object()));
assertTrue(tx.toString() != null);
try {
tx.commit();
fail();
} catch (final InvalidTerminationStateException ex) {
}
try {
tx.rollback();
fail();
} catch (final InvalidTerminationStateException ex) {
}
tx.doBeforeCompletion();
tx.doPrepare();
try {
tx.doCommit();
fail();
} catch (final Throwable ex) {
}
try {
tx.doRollback();
fail();
} catch (final Throwable ex) {
}
try {
tx.doOnePhaseCommit();
fail();
} catch (final Throwable ex) {
}
tx.doForget();
OTSImpleManager.current().rollback();
DummyTransactionImple dummy = new DummyTransactionImple(new AtomicTransaction());
try {
dummy.commitAndDisassociate();
} catch (final InactiveTransactionException ex) {
}
try {
dummy.rollbackAndDisassociate();
} catch (final InactiveTransactionException ex) {
}
}
use of com.arjuna.ats.jta.exceptions.InvalidTerminationStateException in project narayana by jbosstm.
the class TransactionImple method doOnePhaseCommit.
public void doOnePhaseCommit() throws IllegalStateException, javax.transaction.HeuristicMixedException, javax.transaction.SystemException, RollbackException {
try {
SubordinateAtomicAction subAct = (SubordinateAtomicAction) super._theTransaction;
if (!endSuspendedRMs())
_theTransaction.preventCommit();
int status = subAct.doOnePhaseCommit();
switch(status) {
case ActionStatus.COMMITTED:
case ActionStatus.COMMITTING:
case ActionStatus.H_COMMIT:
TransactionImple.removeTransaction(this);
break;
case ActionStatus.ABORTED:
case ActionStatus.ABORTING:
case ActionStatus.H_ROLLBACK:
TransactionImple.removeTransaction(this);
// in which case IllegalState may be a better option?
throw new RollbackException();
case ActionStatus.INVALID:
throw new InvalidTerminationStateException();
case ActionStatus.H_HAZARD:
case ActionStatus.H_MIXED:
default:
throw new javax.transaction.HeuristicMixedException();
}
} catch (ClassCastException ex) {
ex.printStackTrace();
UnexpectedConditionException unexpectedConditionException = new UnexpectedConditionException(ex.toString());
unexpectedConditionException.initCause(ex);
throw unexpectedConditionException;
}
}
use of com.arjuna.ats.jta.exceptions.InvalidTerminationStateException in project narayana by jbosstm.
the class TransactionImple method rollback.
public void rollback() throws java.lang.IllegalStateException, java.lang.SecurityException, javax.transaction.SystemException {
if (jtaxLogger.logger.isTraceEnabled()) {
jtaxLogger.logger.trace("TransactionImple.rollback");
}
boolean endSuspendedFailed = false;
if (_theTransaction != null) {
try {
if ((getStatus() != Status.STATUS_ACTIVE) && (getStatus() != Status.STATUS_MARKED_ROLLBACK))
throw new NoTransaction();
/*
* Call end on any suspended resources. If this fails, then there's
* not a lot else we can do because the transaction is about to roll
* back anyway!
*/
endSuspendedFailed = !endSuspendedRMs();
if (endSuspendedFailed) {
jtaxLogger.i18NLogger.warn_jtax_transaction_jts_endsuspendfailed1();
}
_theTransaction.abort();
} catch (WrongTransaction e1) {
InactiveTransactionException inactiveTransactionException = new InactiveTransactionException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_wrongstatetx());
inactiveTransactionException.initCause(e1);
throw inactiveTransactionException;
} catch (org.omg.CORBA.NO_PERMISSION e2) {
throw new SecurityException(e2);
} catch (INVALID_TRANSACTION e3) {
InactiveTransactionException inactiveTransactionException = new InactiveTransactionException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_invalidtx2());
inactiveTransactionException.initCause(e3);
throw inactiveTransactionException;
} catch (NoTransaction e4) {
throw new IllegalStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_notx(), e4);
} catch (org.omg.CORBA.SystemException e5) {
javax.transaction.SystemException systemException = new javax.transaction.SystemException(e5.toString());
systemException.initCause(e5);
throw systemException;
} finally {
TransactionImple.removeTransaction(this);
}
if (endSuspendedFailed)
throw new InvalidTerminationStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_endsuspendfailed2());
} else
throw new IllegalStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_inactivetx());
}
Aggregations