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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations