Search in sources :

Example 6 with TransactionException

use of org.mule.runtime.api.tx.TransactionException in project mule by mulesoft.

the class ExternalXaTransaction method doBegin.

protected void doBegin() throws TransactionException {
    if (txManager == null) {
        throw new IllegalStateException(CoreMessages.objectNotRegistered("javax.transaction.TransactionManager", "Transaction Manager").getMessage());
    }
    try {
        synchronized (this) {
            transaction = txManager.getTransaction();
            transaction.registerSynchronization(new ExternalTransaction(muleContext));
        }
    } catch (Exception e) {
        throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
    }
}
Also used : TransactionException(org.mule.runtime.api.tx.TransactionException) TransactionException(org.mule.runtime.api.tx.TransactionException)

Example 7 with TransactionException

use of org.mule.runtime.api.tx.TransactionException in project mule by mulesoft.

the class XaTransaction method enlistResource.

// moved here from connection wrapper
public boolean enlistResource(XAResource resource) throws TransactionException {
    TransactionManager txManager = muleContext.getTransactionManager();
    try {
        Transaction jtaTransaction = txManager.getTransaction();
        if (jtaTransaction == null) {
            throw new TransactionException(I18nMessageFactory.createStaticMessage("XATransaction is null"));
        }
        resource.setTransactionTimeout(getTimeoutInSeconds());
        return jtaTransaction.enlistResource(resource);
    } catch (RollbackException | SystemException | XAException e) {
        throw new TransactionException(e);
    }
}
Also used : InvalidTransactionException(javax.transaction.InvalidTransactionException) TransactionException(org.mule.runtime.api.tx.TransactionException) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) TransactionRollbackException(org.mule.runtime.core.api.transaction.TransactionRollbackException)

Example 8 with TransactionException

use of org.mule.runtime.api.tx.TransactionException in project mule by mulesoft.

the class XaTransactionFactory method joinExternalTransaction.

/**
 * Create a Mule transaction that represents a transaction started outside of Mule
 */
public Transaction joinExternalTransaction(MuleContext muleContext) throws TransactionException {
    try {
        TransactionManager txManager = muleContext.getTransactionManager();
        if (txManager.getTransaction() == null) {
            return null;
        }
        XaTransaction xat = new ExternalXaTransaction(muleContext);
        xat.begin();
        return xat;
    } catch (Exception e) {
        throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
    }
}
Also used : ExternalXaTransaction(org.mule.runtime.core.internal.transaction.ExternalXaTransaction) XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) TransactionException(org.mule.runtime.api.tx.TransactionException) TransactionManager(javax.transaction.TransactionManager) ExternalXaTransaction(org.mule.runtime.core.internal.transaction.ExternalXaTransaction) TransactionException(org.mule.runtime.api.tx.TransactionException)

Example 9 with TransactionException

use of org.mule.runtime.api.tx.TransactionException in project mule by mulesoft.

the class XaTransactionFactory method beginTransaction.

public Transaction beginTransaction(MuleContext muleContext) throws TransactionException {
    try {
        XaTransaction xat = new XaTransaction(muleContext);
        xat.setTimeout(timeout);
        xat.begin();
        return xat;
    } catch (Exception e) {
        throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
    }
}
Also used : ExternalXaTransaction(org.mule.runtime.core.internal.transaction.ExternalXaTransaction) XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) TransactionException(org.mule.runtime.api.tx.TransactionException) TransactionException(org.mule.runtime.api.tx.TransactionException)

Example 10 with TransactionException

use of org.mule.runtime.api.tx.TransactionException in project mule by mulesoft.

the class TransactionBindingDelegate method getBoundResource.

/**
 * @param transactionConfig given transaction config
 * @param txKey the transaction key
 * @param connectionHandlerSupplier {@link Supplier} to get the {@link ConnectionHandler} of the current component
 * @return The {@link ConnectionHandler} that has be bound to the transaction.
 * @throws ConnectionException if a problem occurred retrieving the {@link ConnectionHandler}
 * @throws TransactionException if the connection could not be bound to the current transaction
 */
public <T extends TransactionalConnection> ConnectionHandler<T> getBoundResource(TransactionConfig transactionConfig, ExtensionTransactionKey txKey, ConnectionSupplier<ConnectionHandler<T>> connectionHandlerSupplier) throws ConnectionException, TransactionException {
    final Transaction currentTx = TransactionCoordination.getInstance().getTransaction();
    if (currentTx != null) {
        if (currentTx.hasResource(txKey)) {
            return new TransactionalConnectionHandler((ExtensionTransactionalResource) currentTx.getResource(txKey));
        }
        ConnectionHandler<T> connectionHandler = connectionHandlerSupplier.get();
        T connection = connectionHandler.getConnection();
        ExtensionTransactionalResource<T> txResource = createTransactionalResource(currentTx, connectionHandler, connection);
        boolean bound = false;
        try {
            if (currentTx.supports(txKey, txResource)) {
                currentTx.bindResource(txKey, txResource);
                bound = true;
                return new TransactionalConnectionHandler(txResource);
            } else if (transactionConfig.isTransacted()) {
                throw new TransactionException(createStaticMessage(format("%s '%s' of extension '%s' uses a transactional connection '%s', but the current transaction " + "doesn't support it and could not be bound", getComponentModelTypeName(componentModel), componentModel.getName(), extensionModel.getName(), connection.getClass().getName())));
            }
        } finally {
            if (!bound) {
                connectionHandler.release();
            }
        }
    }
    return connectionHandlerSupplier.get();
}
Also used : TransactionException(org.mule.runtime.api.tx.TransactionException) Transaction(org.mule.runtime.core.api.transaction.Transaction)

Aggregations

TransactionException (org.mule.runtime.api.tx.TransactionException)12 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)3 InvalidTransactionException (javax.transaction.InvalidTransactionException)3 RollbackException (javax.transaction.RollbackException)3 SystemException (javax.transaction.SystemException)3 XAException (javax.transaction.xa.XAException)3 Test (org.junit.Test)3 TransactionRollbackException (org.mule.runtime.core.api.transaction.TransactionRollbackException)3 TransactionManager (javax.transaction.TransactionManager)2 Transaction (org.mule.runtime.core.api.transaction.Transaction)2 TransactionStatusException (org.mule.runtime.core.api.transaction.TransactionStatusException)2 ExternalXaTransaction (org.mule.runtime.core.internal.transaction.ExternalXaTransaction)2 XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)2 IllegalTransactionStateException (org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)2 SmallTest (org.mule.tck.size.SmallTest)2 TestTransaction (org.mule.tck.testmodels.mule.TestTransaction)2 Thread.currentThread (java.lang.Thread.currentThread)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Transaction (javax.transaction.Transaction)1