Search in sources :

Example 31 with NotSupportedException

use of javax.transaction.NotSupportedException in project partyline by Commonjava.

the class InfinispanTransactionalGLM method executeInTransaction.

/**
 * If transaction not supported, we throw PartylineException to inform the caller to not try again. For other
 * transactional exceptions, we return null to let caller retry later.
 * @param txManager
 * @param operation
 * @param <T>
 * @return
 * @throws PartylineException if transaction not supported
 */
private <T> T executeInTransaction(TransactionManager txManager, TransactionalOperation<T> operation) throws PartylineException {
    try {
        txManager.begin();
    } catch (NotSupportedException e) {
        throw new PartylineException("Transaction not supported", e);
    } catch (SystemException e) {
        logger.error("Failed to begin transaction.", e);
        return null;
    }
    try {
        T ret = operation.execute();
        txManager.commit();
        return ret;
    } catch (SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        logger.warn("Failed to commit transaction.", e);
        return null;
    } catch (Exception e) {
        try {
            logger.error("Failed to execute. Rolling back.", e);
            txManager.rollback();
        } catch (SystemException e1) {
            logger.error("Exception during rollback", e1);
        }
    }
    return null;
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) PartylineException(org.commonjava.util.partyline.PartylineException) NotSupportedException(javax.transaction.NotSupportedException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) PartylineException(org.commonjava.util.partyline.PartylineException) UnknownHostException(java.net.UnknownHostException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 32 with NotSupportedException

use of javax.transaction.NotSupportedException 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 33 with NotSupportedException

use of javax.transaction.NotSupportedException in project wildfly by wildfly.

the class MockTransactionManager method begin.

@Override
public void begin() throws NotSupportedException, SystemException {
    Transaction tx = currentTx.get();
    if (tx != null)
        throw new NotSupportedException("Nested tx are not supported");
    tx = mock(Transaction.class);
    currentTx.set(tx);
}
Also used : Transaction(javax.transaction.Transaction) NotSupportedException(javax.transaction.NotSupportedException)

Example 34 with NotSupportedException

use of javax.transaction.NotSupportedException in project carbon-business-process by wso2.

the class TransactionManagerProvider method doNonTransactionalWork.

public void doNonTransactionalWork(Runnable runnable) throws NotSupportedException {
    TransactionManager tm;
    Transaction transaction;
    try {
        tm = getTransactionManager();
        transaction = tm.suspend();
    } catch (Exception e) {
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        throw nse;
    }
    runnable.run();
    try {
        tm.resume(transaction);
    } catch (Exception e) {
        try {
            transaction.setRollbackOnly();
        } catch (SystemException se2) {
            throw new GeneralException(se2);
        }
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        throw nse;
    }
}
Also used : GeneralException(org.apache.openjpa.util.GeneralException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) NotSupportedException(javax.transaction.NotSupportedException) GeneralException(org.apache.openjpa.util.GeneralException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 35 with NotSupportedException

use of javax.transaction.NotSupportedException in project carbon-business-process by wso2.

the class TransactionManagerProvider method doNonTransactionalWork.

public void doNonTransactionalWork(java.lang.Runnable runnable) throws NotSupportedException {
    TransactionManager tm;
    Transaction transaction;
    try {
        tm = getTransactionManager();
        transaction = tm.suspend();
    } catch (Exception e) {
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        throw nse;
    }
    runnable.run();
    try {
        tm.resume(transaction);
    } catch (Exception e) {
        try {
            transaction.setRollbackOnly();
        } catch (SystemException se2) {
            throw new GeneralException(se2);
        }
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        throw nse;
    }
}
Also used : GeneralException(org.apache.openjpa.util.GeneralException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) NotSupportedException(javax.transaction.NotSupportedException) GeneralException(org.apache.openjpa.util.GeneralException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Aggregations

NotSupportedException (javax.transaction.NotSupportedException)53 SystemException (javax.transaction.SystemException)42 RollbackException (javax.transaction.RollbackException)22 HeuristicMixedException (javax.transaction.HeuristicMixedException)20 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)20 Transaction (javax.transaction.Transaction)17 UserTransaction (javax.transaction.UserTransaction)11 TransactionManager (javax.transaction.TransactionManager)10 SQLException (java.sql.SQLException)8 NamingException (javax.naming.NamingException)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 InvalidTransactionException (javax.transaction.InvalidTransactionException)5 Connection (java.sql.Connection)4 GeneralException (org.apache.openjpa.util.GeneralException)4 File (java.io.File)3 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2