TransactionPlan

Mutable container for building a sequence of database operations to be executed atomically.

Collects TransactionStep instances and their corresponding StepHandles, enabling deferred execution within a single transaction via DataAccess.executeTransactionPlan.

Useful when transaction steps need to be constructed dynamically based on runtime data (e.g., enrolling a variable number of legionnaires into a newly created legion).

Usage Example

val plan = TransactionPlan()

// Step 1: Create the legion, get its generated ID back
val legionHandle = plan.add(
dataAccess.insertInto("legions").values(legionData).asStep().toField<Int>()
)

// Step 2: Enroll each legionnaire, referencing the legion ID from Step 1
legionnaires.forEach { legionnaire ->
plan.add(
dataAccess.insertInto("legionnaire_assignments")
.values(mapOf("legion_id" to legionHandle.field(), "legionnaire_id" to legionnaire.id))
.asStep().execute()
)
}

dataAccess.executeTransactionPlan(plan)

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun <T> add(step: TransactionStep<T>): StepHandle<T>

Adds a step to the plan and returns a handle for referencing its result in subsequent steps.

Link copied to clipboard
fun addPlan(otherPlan: TransactionPlan)

Adds all steps from another transaction plan to the current plan.