SnapshotBatchWriter

Writes a list of SimulationSnapshot objects produced by InMemorySnapshotCollector into a KSLDatabase in a single sequential pass.

The snapshots arrive with placeholder FK values (exp_id = -1, run_id = -1) set by SimulationLifeCycleBridge. This writer inserts the experiment and simulation-run records first, reads back the auto-increment IDs generated by the database, then fixes all downstream FK fields before inserting the remaining records.

Expected snapshot order (produced by a clean run):

  1. Exactly one SimulationSnapshot.ExperimentStarted

  2. One SimulationSnapshot.ReplicationCompleted per replication

  3. Exactly one SimulationSnapshot.ExperimentCompleted or SimulationSnapshot.ExperimentFailed

Snapshots are mutated in-place during FK remapping; the caller should not reuse the list.

Constructors

Link copied to clipboard
constructor(db: KSLDatabase)

Functions

Link copied to clipboard
fun write(snapshots: List<SimulationSnapshot>)

Writes snapshots to db.