Search in sources :

Example 71 with SystemException

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;
}
Also used : TransactionException(io.requery.TransactionException) SystemException(javax.transaction.SystemException) SQLException(java.sql.SQLException) NotSupportedException(javax.transaction.NotSupportedException)

Example 72 with SystemException

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());
    }
}
Also used : Transaction(javax.transaction.Transaction) UserTransaction(javax.transaction.UserTransaction) TransactionSystemException(org.springframework.transaction.TransactionSystemException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotSupportedException(javax.transaction.NotSupportedException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 73 with SystemException

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);
        }
    }
}
Also used : TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(javax.transaction.SystemException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) NamingException(javax.naming.NamingException) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.transaction.RollbackException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException) TransactionSuspensionNotSupportedException(org.springframework.transaction.TransactionSuspensionNotSupportedException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) InvalidIsolationLevelException(org.springframework.transaction.InvalidIsolationLevelException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) NestedTransactionNotSupportedException(org.springframework.transaction.NestedTransactionNotSupportedException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 74 with SystemException

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
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) SystemException(javax.transaction.SystemException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Test(org.junit.Test)

Example 75 with SystemException

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();
}
Also used : UserTransaction(javax.transaction.UserTransaction) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) SystemException(javax.transaction.SystemException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Test(org.junit.Test)

Aggregations

SystemException (javax.transaction.SystemException)102 Transaction (javax.transaction.Transaction)34 RollbackException (javax.transaction.RollbackException)29 NotSupportedException (javax.transaction.NotSupportedException)22 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)18 IOException (java.io.IOException)16 HeuristicMixedException (javax.transaction.HeuristicMixedException)16 UserTransaction (javax.transaction.UserTransaction)14 XAException (javax.transaction.xa.XAException)13 Test (org.junit.Test)12 TransactionManager (javax.transaction.TransactionManager)11 SQLException (java.sql.SQLException)10 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)10 InvalidTransactionException (javax.transaction.InvalidTransactionException)9 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)8 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)8 XAResource (javax.transaction.xa.XAResource)7 Synchronization (javax.transaction.Synchronization)6 File (java.io.File)5