Swan Lake Beta2 is here.
import ballerina/io;

public function main() returns error? {
    // Compile-time guarantees that transactions are bracketed with
    // begin and commit or rollback. Transaction statement begins
    // a new transaction and executes a block.
    transaction {
        doStage1();
        doStage2();

        // Commit of a transaction must be done explicitly using commit.
        // Commit must be lexically within a transaction statement and may
        // return an error;
        check commit;

    }
}

function doStage1() {
    io:println("Stage1 completed");
}

function doStage2() {
    io:println("Stage2 completed");
}

Transaction Statement

Ballerina provides support for interacting with a transaction manager. Compile-time guarantees that transactions are bracketed with begin and commit or rollback. The region in the middle, is typed as being a transactional context. Ballerina does not have a transactional memory and includes transaction manager. Current transaction is a part of the execution context of a strand.

import ballerina/io;
public function main() returns error? {
    transaction {
        doStage1();
        doStage2();

Compile-time guarantees that transactions are bracketed with begin and commit or rollback. Transaction statement begins a new transaction and executes a block.

        check commit;

Commit of a transaction must be done explicitly using commit. Commit must be lexically within a transaction statement and may return an error;

    }
}
function doStage1() {
    io:println("Stage1 completed");
}
function doStage2() {
    io:println("Stage2 completed");
}
bal run transaction_statement.bal
Stage1 completed
Stage2 completed
import ballerina/io;

public function main() returns error? {
    // Compile-time guarantees that transactions are bracketed with
    // begin and commit or rollback. Transaction statement begins
    // a new transaction and executes a block.
    transaction {
        doStage1();
        doStage2();

        // Commit of a transaction must be done explicitly using commit.
        // Commit must be lexically within a transaction statement and may
        // return an error;
        check commit;

    }
}

function doStage1() {
    io:println("Stage1 completed");
}

function doStage2() {
    io:println("Stage2 completed");
}

Transaction Statement

Ballerina provides support for interacting with a transaction manager. Compile-time guarantees that transactions are bracketed with begin and commit or rollback. The region in the middle, is typed as being a transactional context. Ballerina does not have a transactional memory and includes transaction manager. Current transaction is a part of the execution context of a strand.

import ballerina/io;
public function main() returns error? {
    transaction {
        doStage1();
        doStage2();

Compile-time guarantees that transactions are bracketed with begin and commit or rollback. Transaction statement begins a new transaction and executes a block.

        check commit;

Commit of a transaction must be done explicitly using commit. Commit must be lexically within a transaction statement and may return an error;

    }
}
function doStage1() {
    io:println("Stage1 completed");
}
function doStage2() {
    io:println("Stage2 completed");
}
bal run transaction_statement.bal
Stage1 completed
Stage2 completed

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand