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.
The elements that get you up and running in a matter of days, from pre-built content types, to modules, to landing pages.

Content types
Modules
Landing pages
Everything you need to manage and administer content within Brightspot CMS, including plug-and-play integrations.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting and administering code on the Brightspot platform, including integrations requiring developer support to use.

Field types
Content modeling
Rich-text elements
Images