Search in sources :

Example 16 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.

the class CciLocalTransactionManager method doBegin.

@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
    Connection con = null;
    try {
        con = getConnectionFactory().getConnection();
        if (logger.isDebugEnabled()) {
            logger.debug("Acquired Connection [" + con + "] for local CCI transaction");
        }
        txObject.setConnectionHolder(new ConnectionHolder(con));
        txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
        con.getLocalTransaction().begin();
        int timeout = determineTimeout(definition);
        if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
            txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
        }
        TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
    } catch (NotSupportedException ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
    } catch (LocalTransactionException ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex);
    } catch (Throwable ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) Connection(javax.resource.cci.Connection) TransactionSystemException(org.springframework.transaction.TransactionSystemException) NotSupportedException(javax.resource.NotSupportedException)

Example 17 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException 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 18 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException 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 19 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.

the class WebLogicJtaTransactionManager method loadWebLogicTransactionClasses.

private void loadWebLogicTransactionClasses() throws TransactionSystemException {
    try {
        Class<?> userTransactionClass = getClass().getClassLoader().loadClass(USER_TRANSACTION_CLASS_NAME);
        this.weblogicUserTransactionAvailable = userTransactionClass.isInstance(getUserTransaction());
        if (this.weblogicUserTransactionAvailable) {
            this.beginWithNameMethod = userTransactionClass.getMethod("begin", String.class);
            this.beginWithNameAndTimeoutMethod = userTransactionClass.getMethod("begin", String.class, int.class);
            logger.info("Support for WebLogic transaction names available");
        } else {
            logger.info("Support for WebLogic transaction names not available");
        }
        // Obtain WebLogic ClientTransactionManager interface.
        Class<?> transactionManagerClass = getClass().getClassLoader().loadClass(CLIENT_TRANSACTION_MANAGER_CLASS_NAME);
        logger.debug("WebLogic ClientTransactionManager found");
        this.weblogicTransactionManagerAvailable = transactionManagerClass.isInstance(getTransactionManager());
        if (this.weblogicTransactionManagerAvailable) {
            Class<?> transactionClass = getClass().getClassLoader().loadClass(TRANSACTION_CLASS_NAME);
            this.forceResumeMethod = transactionManagerClass.getMethod("forceResume", Transaction.class);
            this.setPropertyMethod = transactionClass.getMethod("setProperty", String.class, Serializable.class);
            logger.debug("Support for WebLogic forceResume available");
        } else {
            logger.warn("Support for WebLogic forceResume not available");
        }
    } catch (Exception ex) {
        throw new TransactionSystemException("Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available", ex);
    }
}
Also used : Serializable(java.io.Serializable) Transaction(javax.transaction.Transaction) UserTransaction(javax.transaction.UserTransaction) TransactionSystemException(org.springframework.transaction.TransactionSystemException) NotSupportedException(javax.transaction.NotSupportedException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.

the class WebLogicJtaTransactionManager method retrieveTransactionManager.

@Override
protected TransactionManager retrieveTransactionManager() throws TransactionSystemException {
    loadWebLogicTransactionHelper();
    try {
        logger.debug("Retrieving JTA TransactionManager from WebLogic TransactionHelper");
        Method getTransactionManagerMethod = this.transactionHelper.getClass().getMethod("getTransactionManager");
        return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper);
    } catch (InvocationTargetException ex) {
        throw new TransactionSystemException("WebLogic's TransactionHelper.getTransactionManager() method failed", ex.getTargetException());
    } catch (Exception ex) {
        throw new TransactionSystemException("Could not invoke WebLogic's TransactionHelper.getTransactionManager() method", ex);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) Method(java.lang.reflect.Method) 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)

Aggregations

TransactionSystemException (org.springframework.transaction.TransactionSystemException)27 SystemException (javax.transaction.SystemException)7 Test (org.junit.Test)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 InvalidTransactionException (javax.transaction.InvalidTransactionException)6 NotSupportedException (javax.transaction.NotSupportedException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SQLException (java.sql.SQLException)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)3 RollbackException (javax.persistence.RollbackException)3 Connection (javax.resource.cci.Connection)3 LocalTransactionException (javax.resource.spi.LocalTransactionException)3 RollbackException (javax.transaction.RollbackException)3 UserTransaction (javax.transaction.UserTransaction)3 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)3 UOWException (com.ibm.wsspi.uow.UOWException)2 Connection (java.sql.Connection)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2