Brightspot CMS Developer Guide

Transactions


A database transaction is a sequence of operations performed as a single logical unit of work. Transactions allow you to roll back all operations should any single operation fail. For example, if you save multiple Dari objects within a transaction, a save exception for one object will prevent all objects in the transactions from being committed to the database. Transactions are thread bound.

As shown in the following snippet, transactions require an instance of the Database object on which you want to run a transaction. Generally, you want to use the default database.

Every call to beginWrites must be followed by a call to endWrites. The commitWrites API commits all pending writes. The data is either committed to the database, or it is discarded if there are any validation errors thrown in the save operation.

Database db = Database.Static.getDefault();
db.beginWrites();
try {
    /* Save Dari objects using save(). */
    object.save();
    if (!rollback) {
        db.commitWrites();
    }
}
finally {
    db.endWrites();
}

Previous Topic
Forwarding database
Next Topic
Async database
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News