← Back to Stormify Documentation

TransactionContextJ

Scope of an active database transaction. Provides CRUD operations, raw SQL queries, stored procedure calls, and nested transactions; every operation runs on the same connection and participates in the same transaction.

Obtained from StormifyJ.transaction.

Constructors

Link copied to clipboard
constructor(ctx: TransactionContext)

Functions

Link copied to clipboard
fun <T : Any> create(item: T): T

Inserts item into its mapped table and returns the (possibly key-populated) entity.

fun <T : Any> create(items: Collection<T>): List<T>

Batch INSERT of items in a single round trip.

Link copied to clipboard
fun delete(deletedItem: Any)

DELETE's the row corresponding to deletedItem using its primary key.

fun <T : Any> delete(items: Collection<T>)

Batch DELETE of items.

Link copied to clipboard
fun executeUpdate(query: String, vararg params: Any?): Int

Executes an INSERT / UPDATE / DELETE and returns the affected row count.

Link copied to clipboard
fun <T : Any> findAll(baseClass: Class<T>, whereClause: String = "", vararg arguments: Any?): List<T>

Convenience over read for SELECT * FROM <table> <whereClause>.

Link copied to clipboard
fun <T : Any> findById(baseClass: Class<T>, id: Any): T?

Looks up a single row of baseClass by its primary key id. Returns null if not found.

Link copied to clipboard
fun <M : Any, T : Any> getDetails(parent: M, detailsClass: Class<T>, propertyName: String? = null): List<T>

Returns the detail rows of type detailsClass that reference parent. Use propertyName to disambiguate when the detail class has multiple foreign keys pointing at the same parent type.

fun <M : Any, T : Any> getDetails(parent: M, detailsClass: Class<T>, referenceField: ReferencePath): List<T>

Type-safe variant of getDetails that accepts an annotation-processor-generated reference path (e.g. Paths.AuditEntry_.createdBy()) instead of a string.

Link copied to clipboard
fun <T : Any> populate(entity: T): T

Populates entity from the database by its primary key. Used internally by AutoTable.

Link copied to clipboard
fun procedure(name: String, vararg args: Any?)

Invokes the stored procedure name with args. Output and bidirectional parameters should be passed as Sp.Out / Sp.InOut instances; all other values are auto-wrapped as IN.

Link copied to clipboard
fun <T : Any> read(baseClass: Class<T>, query: String, vararg params: Any?): List<T>

Executes a SELECT and returns the rows as a list of baseClass instances.

Link copied to clipboard
fun <T : Any> readCursor(baseClass: Class<T>, query: String, consumer: Consumer<T>, vararg params: Any?): Int

Executes a SELECT and streams each row to consumer — avoids materializing the full result.

Link copied to clipboard
fun <T : Any> readOne(baseClass: Class<T>, query: String, vararg params: Any?): T?

Executes a SELECT and returns the first row as a baseClass instance, or null if empty.

Link copied to clipboard
fun transaction(block: Runnable)

Starts a nested transaction via a savepoint. If block throws, only its work is rolled back.

Starts a nested transaction via a savepoint and returns block's result. If block throws, only its work is rolled back.

Link copied to clipboard
fun <T : Any> update(updatedItem: T): T

UPDATE's the row corresponding to updatedItem using its primary key.

fun <T : Any> update(items: Collection<T>): List<T>

Batch UPDATE of items.