Search in sources :

Example 1 with TransactionalConnection

use of org.mule.runtime.extension.api.connectivity.TransactionalConnection in project mule by mulesoft.

the class DefaultSourceCallbackContext method bindConnection.

/**
 * {@inheritDoc}
 */
@Override
public TransactionHandle bindConnection(Object connection) throws ConnectionException, TransactionException {
    checkArgument(connection != null, "Cannot bind a null connection");
    if (this.connection != null) {
        throw new IllegalArgumentException("Connection can only be set once per " + SourceCallbackContext.class.getSimpleName());
    }
    this.connection = connection;
    if (sourceCallback.getTransactionConfig().isTransacted() && connection instanceof TransactionalConnection) {
        ConnectionHandler<Object> connectionHandler = sourceCallback.getSourceConnectionManager().getConnectionHandler(connection).orElseThrow(() -> new TransactionException(createWrongConnectionMessage(connection)));
        sourceCallback.getTransactionSourceBinder().bindToTransaction(sourceCallback.getTransactionConfig(), sourceCallback.getConfigurationInstance(), connectionHandler);
        transactionHandle = DEFAULT_TRANSACTION_HANDLE;
    }
    return transactionHandle;
}
Also used : TransactionException(org.mule.runtime.api.tx.TransactionException) TransactionalConnection(org.mule.runtime.extension.api.connectivity.TransactionalConnection)

Aggregations

TransactionException (org.mule.runtime.api.tx.TransactionException)1 TransactionalConnection (org.mule.runtime.extension.api.connectivity.TransactionalConnection)1