Chapter 3. Updating Records

Table of Contents

Creating new Records
Using RecordInitializers to Automatically Set Default Values
Modifying Records
Saving Records
Deleting Records

Creating new Records

To create a new Record, first obtain a Table from the Store via the Store.getTable(String tableName) method. Then call the Table's create() method. The Record is neither persisted nor available to queries until its save() method is called.

Note

Changes to a Record will not be visible to other parts of the program until the Record's save() method is called.

To create a new Record by copying all of the fields from another Record, use Table's createCopy(Record) method.

Using RecordInitializers to Automatically Set Default Values

Trivial Persist provides a RecordInitializer interface with the single method void init(Record record). If a Table has had a RecordInitializer set via Table.setRecordInitializer(RecordInitializer initializer), the RecordInitializer's init() method will be called on every new Record before Table.create() returns. This provides a mechanism to include arbitrarily complex initialization logic, although most of the time your RecordInitializers will simply consist of a series of calls to the methods described below.