Module : transactions

Version : 0.5.0

Module overview

This module provides Ballerina transaction manager implementation.

The code snippet given below uses the functions in the module to get the transaction information.

NOTE: This module is deprecated from 2.0.0-preview1 onwards. Please use lang.transaction module instead.


// When the `transaction` statement starts, a distributed transaction context is created.
transaction {
    // Print the current transaction ID
    log:printInfo("Started transaction: " +
                     transactions:getCurrentTransactionId());

    // When a participant is called, the transaction context is propagated, and that participant
    // gets infected and joins the distributed transaction.
    boolean successful = callBusinessService();
    if (successful) {
        log:printInfo("Business operation executed successfully");
    } else {
        log:printError("Business operation failed");
        abort;
    }

    // As soon as the `transaction` block ends, the `2-phase commit
    // coordination` protocol will run. All participants are prepared
    // and depending on the joint outcome, either a `notify commit` or
    // `notify abort` will be sent to the participants.
} committed {
    log:printInfo("Initiated transaction committed");
} aborted {
    log:printInfo("Initiated transaction aborted");
}

Records

Info
TransactionContext
TransactionParticipantConfig

Contains the configurations for local transaction participant function.

Functions

ballerina/transactions:0.5.0.<init>0
ballerina/transactions:0.5.0.<init>1
ballerina/transactions:0.5.0.<init>2
ballerina/transactions:0.5.0.<init>3
ballerina/transactions:0.5.0.<init>4
beginTransaction Deprecated When a transaction block in Ballerina code begins, it will call this function to begin a transaction.
cleanupTransactionContext Deprecated Cleanup the transaction context.
endTransaction Deprecated When a transaction block in Ballerina code ends, it will call this function to end a transaction.
getAndClearFailure Deprecated Get and Cleanup the failure.
getCurrentTransactionId Deprecated Get the current transaction id.
rollbackTransaction Deprecated Rollback the transaction.
setTransactionContext Deprecated Set the transactionContext.

Constants

OUTCOME_COMMITTED
TWO_PHASE_COMMIT

Annotations

Participant

The annotation which is used to configure local transaction participant function.

Errors

TransactionError

Represents a TransactionError with the message and the cause.