TransactionPlan

Operations to run as one transaction, assembled before any of it runs - for a sequence decided in one place and run in another. Where the sequence is written out where it runs, a transaction { } block is simpler.

Steps run in the order they were added, and a step uses what an earlier one produced through the StepHandle returned:

val plan = TransactionPlan()

val edictId = plan.add(
db.insertInto("edicts").values(edict).returning("id")
.asStep().fetchFieldStrict<Int>(edict)
)

for (item in levy) {
plan.add(
db.insertInto("edict_items").values(listOf("edict_id", "province_id", "amount"))
.asStep().executeUpdate(
"edict_id" to edictId.value(),
"province_id" to item.provinceId,
"amount" to item.amount
)
)
}

val results = db.executeTransactionPlan(plan)

Running a plan does not change it, so retrying a serialization failure is a loop around executeTransactionPlan, each run resolving its handles against its own results.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
internal class PlannedStep(val handle: StepHandle<*>, val query: RunnableQuery<*>, val params: Map<String, Any?>, val run: (Map<String, Any?>) -> Any?)

A step and the handle it was filed under.

Properties

Link copied to clipboard
val size: Int

How many steps the plan holds.

Functions

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

Appends step, built with RunnableQuery.asStep, and returns the handle later steps refer to it by.

Link copied to clipboard

Appends every step of other, in its order. other's handles keep working against the merged plan and its result, and other itself is left unchanged.

Link copied to clipboard

What this plan will do, as text: every step's index, its SQL, and where each parameter comes from.

Link copied to clipboard

Whether the plan holds no steps at all.

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String