Search in sources :

Example 6 with LocalTransactionInfo

use of org.ballerinalang.util.transactions.LocalTransactionInfo in project ballerina by ballerina-lang.

the class CPU method endTransaction.

private static void endTransaction(WorkerExecutionContext ctx, int transactionBlockId, int status) {
    LocalTransactionInfo localTransactionInfo = ctx.getLocalTransactionInfo();
    boolean isGlobalTransactionEnabled = ctx.getGlobalTransactionEnabled();
    boolean notifyCoordinator;
    try {
        // In success case no need to do anything as with the transaction end phase it will be committed.
        if (status == TransactionStatus.FAILED.value()) {
            notifyCoordinator = localTransactionInfo.onTransactionFailed(ctx, transactionBlockId);
            if (notifyCoordinator) {
                if (isGlobalTransactionEnabled) {
                    TransactionUtils.notifyTransactionAbort(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
                } else {
                    TransactionResourceManager.getInstance().notifyAbort(localTransactionInfo.getGlobalTransactionId(), transactionBlockId, false);
                }
            }
        } else if (status == TransactionStatus.ABORTED.value()) {
            if (isGlobalTransactionEnabled) {
                TransactionUtils.notifyTransactionAbort(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
            } else {
                TransactionResourceManager.getInstance().notifyAbort(localTransactionInfo.getGlobalTransactionId(), transactionBlockId, false);
            }
        } else if (status == TransactionStatus.SUCCESS.value()) {
            // it will commit at the end message
            if (!isGlobalTransactionEnabled) {
                TransactionResourceManager.getInstance().prepare(localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
                TransactionResourceManager.getInstance().notifyCommit(localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
            }
        } else if (status == TransactionStatus.END.value()) {
            // status = 1 Transaction end
            boolean isOuterTx = localTransactionInfo.onTransactionEnd(transactionBlockId);
            if (isGlobalTransactionEnabled) {
                TransactionUtils.notifyTransactionEnd(ctx, localTransactionInfo.getGlobalTransactionId(), transactionBlockId);
            }
            if (isOuterTx) {
                BLangVMUtils.removeTransactionInfo(ctx);
            }
        }
    } catch (Throwable e) {
        ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
        handleError(ctx);
    }
}
Also used : LocalTransactionInfo(org.ballerinalang.util.transactions.LocalTransactionInfo)

Example 7 with LocalTransactionInfo

use of org.ballerinalang.util.transactions.LocalTransactionInfo in project ballerina by ballerina-lang.

the class CPU method retryTransaction.

private static void retryTransaction(WorkerExecutionContext ctx, int transactionBlockId, int startOfAbortIP, int startOfNoThrowEndIP) {
    LocalTransactionInfo localTransactionInfo = ctx.getLocalTransactionInfo();
    if (!localTransactionInfo.isRetryPossible(ctx, transactionBlockId)) {
        if (ctx.getError() == null) {
            ctx.ip = startOfNoThrowEndIP;
        } else {
            if (BLangVMErrors.TRANSACTION_ERROR.equals(ctx.getError().getStringField(0))) {
                ctx.ip = startOfNoThrowEndIP;
            } else {
                ctx.ip = startOfAbortIP;
            }
        }
    }
    localTransactionInfo.incrementCurrentRetryCount(transactionBlockId);
}
Also used : LocalTransactionInfo(org.ballerinalang.util.transactions.LocalTransactionInfo)

Aggregations

LocalTransactionInfo (org.ballerinalang.util.transactions.LocalTransactionInfo)7 BString (org.ballerinalang.model.values.BString)2 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 XAConnection (javax.sql.XAConnection)1 XAResource (javax.transaction.xa.XAResource)1 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 BFunctionPointer (org.ballerinalang.model.values.BFunctionPointer)1 BStruct (org.ballerinalang.model.values.BStruct)1 BValue (org.ballerinalang.model.values.BValue)1 SQLTransactionContext (org.ballerinalang.nativeimpl.actions.data.sql.SQLTransactionContext)1 ResourceInfo (org.ballerinalang.util.codegen.ResourceInfo)1 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)1 BallerinaTransactionContext (org.ballerinalang.util.transactions.BallerinaTransactionContext)1