Search in sources :

Example 1 with ExternalTransactionAwareTransactionFactory

use of org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory in project mule by mulesoft.

the class ExternalTransactionInterceptor method execute.

@Override
public T execute(ExecutionCallback<T> callback, ExecutionContext executionContext) throws Exception {
    Transaction joinedExternal = null;
    Transaction tx = TransactionCoordination.getInstance().getTransaction();
    try {
        if (tx == null && muleContext != null && transactionConfig != null && transactionConfig.isInteractWithExternal()) {
            TransactionFactory tmFactory = transactionConfig.getFactory();
            if (tmFactory instanceof ExternalTransactionAwareTransactionFactory) {
                ExternalTransactionAwareTransactionFactory externalTransactionFactory = (ExternalTransactionAwareTransactionFactory) tmFactory;
                joinedExternal = externalTransactionFactory.joinExternalTransaction(muleContext);
            }
        }
        return next.execute(callback, executionContext);
    } finally {
        if (joinedExternal != null) {
            TransactionCoordination.getInstance().unbindTransaction(joinedExternal);
        }
    }
}
Also used : Transaction(org.mule.runtime.core.api.transaction.Transaction) TransactionFactory(org.mule.runtime.core.api.transaction.TransactionFactory) ExternalTransactionAwareTransactionFactory(org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory) ExternalTransactionAwareTransactionFactory(org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory)

Aggregations

ExternalTransactionAwareTransactionFactory (org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory)1 Transaction (org.mule.runtime.core.api.transaction.Transaction)1 TransactionFactory (org.mule.runtime.core.api.transaction.TransactionFactory)1