liveBook · Manning

Insert

As explained in Data-Oriented Programming in Java

An insert is a database write description representing the creation of a new record.

An insert is a database write description representing the creation of a new record. It pairs a table name with a TableRecord and remains separate from an update. section 10.1.1

An insert carries the database library’s storage-level semantics:

  • Collect inserts in a list when several new records must be written transactionally. section 10.1.1
  • Represent the payload as a TableRecord mapping column names to values. section 10.1.1
  • Expect a failure when an insert targets a record that already exists. section 10.4.6

Writing account records

List<Insert> inserts = List.of( new Insert("ACCOUNTS", accountRecord), new Insert("ACCOUNTS", anotherAccountRecord) ); database.transact(inserts, List.of()); The application can keep the insert construction at the boundary while expressing a higher-level operation such as upsert internally. section 10.1.1 section 10.4.6

Listing 10.3 Data types used for making changes
record Insert(String table, TableRecord record){}
record Update(String table, TableRecord record){}
 

Use the compact Java definition to see how Insert differs structurally from Update while sharing the same TableRecord payload. section 10.1.1

How Data-Oriented Programming in Java covers it

How deep it goes
Defines the record shape, payload representation, transaction role, and duplicate constraint, but defers database implementation details.
Examples
Uses Java record definitions, account batches, and a transact call to demonstrate constructing and submitting inserts.
What it assumes
Assumes familiarity with database records, tables, transactions, and Java record syntax.
What you can do after
Apply it via transact by pairing table names with TableRecords and batching new-record writes separately from updates.
How it connects
Connects inserts with database transactions, updates, TableRecord, upsert, and architectural boundaries.

Also explained in

Compare how 3 books explain insert →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.