PostgresSnapshotStore
The SnapshotStore of one bounded context on PostgreSQL (documentation/designs/03-log-and-snapshot.md §3).
Each aggregate type has a table of its own (PostgresSnapshotTables), created on its first save or load, which claims its format version first (PostgresFormat). One table holds one row per aggregate. The state and the access attributes are jsonb, so the snapshot can be queried in place as the default read model. A save is one autocommitted statement that carries its own version and state revision guard (see PostgresSnapshotTables.save); a save refused for a higher state revision then marks the row stale. The claimed state revision of each table is a row of PostgresSnapshotTables.TABLES, claimed with one statement.
JDBC calls run on dispatcher, virtual threads by default (JDK 21). A failure of the database is a defect and is thrown: a snapshot is a cache, so the caller may drop it and rebuild later.
Constructors
Properties
Functions
Nothing to create up front: each aggregate type's table is created on its first use (createTable), since the store does not know the context's aggregate types. Kept for the host, which calls it at startup.
Creates the table of aggregateName when missing, once per store; refuses snapshots recorded in another format version (PostgresFormat).
Saves snapshots: in the rounds SnapshotSaveOutcome.rounds gives, each round's snapshots of one aggregate type with one statement (PostgresSnapshotTables.saveRows, at most PostgresSnapshotTables.MAX_ROWS a statement), then, only when some were refused, one statement marking those of a higher state revision stale. So a batch of one aggregate type that all lands is one round trip, as one save is.