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. If this is a new transaction (transactionId == () ), then this instance will become the initiator and will create a new transaction context. If the participant and initiator are in the same process, this transaction block will register with the local initiator via a local function call. If the participant and initiator are in different processes, this transaction block will register with the remote initiator via a network call.
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. Ending a transaction by a participant has no effect because it is the initiator who can decide whether to commit or abort a transaction. Depending on the state of the transaction, the initiator decides to commit or abort the 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.