use of javax.transaction.SystemException in project requery by requery.
the class ManagedTransaction method begin.
@Override
public Transaction begin() {
if (active()) {
throw new IllegalStateException("transaction already active");
}
transactionListener.beforeBegin(null);
int status = getSynchronizationRegistry().getTransactionStatus();
if (status == Status.STATUS_NO_TRANSACTION) {
try {
getUserTransaction().begin();
initiatedTransaction = true;
} catch (NotSupportedException | SystemException e) {
throw new TransactionException(e);
}
}
getSynchronizationRegistry().registerInterposedSynchronization(this);
try {
connection = connectionProvider.getConnection();
} catch (SQLException e) {
throw new TransactionException(e);
}
uncloseableConnection = new UncloseableConnection(connection);
committed = false;
rolledBack = false;
entities.clear();
transactionListener.afterBegin(null);
return this;
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class WebLogicJtaTransactionManager method doJtaBegin.
@Override
protected void doJtaBegin(JtaTransactionObject txObject, TransactionDefinition definition) throws NotSupportedException, SystemException {
int timeout = determineTimeout(definition);
// Apply transaction name (if any) to WebLogic transaction.
if (this.weblogicUserTransactionAvailable && definition.getName() != null) {
try {
if (timeout > TransactionDefinition.TIMEOUT_DEFAULT) {
/*
weblogic.transaction.UserTransaction wut = (weblogic.transaction.UserTransaction) ut;
wut.begin(definition.getName(), timeout);
*/
this.beginWithNameAndTimeoutMethod.invoke(txObject.getUserTransaction(), definition.getName(), timeout);
} else {
/*
weblogic.transaction.UserTransaction wut = (weblogic.transaction.UserTransaction) ut;
wut.begin(definition.getName());
*/
this.beginWithNameMethod.invoke(txObject.getUserTransaction(), definition.getName());
}
} catch (InvocationTargetException ex) {
throw new TransactionSystemException("WebLogic's UserTransaction.begin() method failed", ex.getTargetException());
} catch (Exception ex) {
throw new TransactionSystemException("Could not invoke WebLogic's UserTransaction.begin() method", ex);
}
} else {
// No WebLogic UserTransaction available or no transaction name specified
// -> standard JTA begin call.
applyTimeout(txObject, timeout);
txObject.getUserTransaction().begin();
}
// Specify isolation level, if any, through corresponding WebLogic transaction property.
if (this.weblogicTransactionManagerAvailable) {
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
try {
Transaction tx = getTransactionManager().getTransaction();
Integer isolationLevel = definition.getIsolationLevel();
/*
weblogic.transaction.Transaction wtx = (weblogic.transaction.Transaction) tx;
wtx.setProperty(ISOLATION_LEVEL_KEY, isolationLevel);
*/
this.setPropertyMethod.invoke(tx, ISOLATION_LEVEL_KEY, isolationLevel);
} catch (InvocationTargetException ex) {
throw new TransactionSystemException("WebLogic's Transaction.setProperty(String, Serializable) method failed", ex.getTargetException());
} catch (Exception ex) {
throw new TransactionSystemException("Could not invoke WebLogic's Transaction.setProperty(String, Serializable) method", ex);
}
}
} else {
applyIsolationLevel(txObject, definition.getIsolationLevel());
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManager method registerAfterCompletionWithExistingTransaction.
@Override
protected void registerAfterCompletionWithExistingTransaction(Object transaction, List<TransactionSynchronization> synchronizations) {
JtaTransactionObject txObject = (JtaTransactionObject) transaction;
logger.debug("Registering after-completion synchronization with existing JTA transaction");
try {
doRegisterAfterCompletionWithJtaTransaction(txObject, synchronizations);
} catch (SystemException ex) {
throw new TransactionSystemException("JTA failure on registerSynchronization", ex);
} catch (Exception ex) {
// Note: JBoss throws plain RuntimeException with RollbackException as cause.
if (ex instanceof RollbackException || ex.getCause() instanceof RollbackException) {
logger.debug("Participating in existing JTA transaction that has been marked for rollback: " + "cannot register Spring after-completion callbacks with outer JTA transaction - " + "immediately performing Spring after-completion callbacks with outcome status 'rollback'. " + "Original exception: " + ex);
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
} else {
logger.debug("Participating in existing JTA transaction, but unexpected internal transaction " + "state encountered: cannot register Spring after-completion callbacks with outer JTA " + "transaction - processing Spring after-completion callbacks with outcome status 'unknown'" + "Original exception: " + ex);
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
}
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithSystemExceptionOnRollbackOnly.
@Test
public void jtaTransactionManagerWithSystemExceptionOnRollbackOnly() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new SystemException("system exception")).given(ut).setRollbackOnly();
try {
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
status.setRollbackOnly();
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN);
}
});
}
});
fail("Should have thrown TransactionSystemException");
} catch (TransactionSystemException ex) {
// expected
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithSystemExceptionOnRollback.
@Test
public void jtaTransactionManagerWithSystemExceptionOnRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
willThrow(new SystemException("system exception")).given(ut).rollback();
try {
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN);
}
});
status.setRollbackOnly();
}
});
fail("Should have thrown TransactionSystemException");
} catch (TransactionSystemException ex) {
// expected
}
verify(ut).begin();
}
Aggregations