OctaviusClient

Hands out queries and sessions, and runs transactions over them. That is all it is.

A query taken from here - rawQuery, select, insertInto, update, deleteFrom - is a RunnableQuery, which carries the terminal family and finds its own session when one of them is called. Nothing has to be opened around it, which is what keeps a single query to a single expression.

Where the work is not a query - copy, largeObjects, notifications, or several statements that have to share one session - execute hands over the driver's own OctaviusSessionOperations and gets out of the way. Neither path wraps or renames anything the driver named.

val db = OctaviusClient.fromDataSource(hikariDataSource)

val senators = db.rawQuery("SELECT id, cognomen FROM senators WHERE province_id = @p")
.fetchObjects<Senator>("p" to 7)

What it buys over calling dataSource.getOctaviusSession() by hand is the thing a data layer of any size ends up needing: a repository function can open a scope without knowing whether it is already inside a transaction, and be right either way. A session opened here joins the transaction running on this thread if there is one, so the same function works standalone and as a step in a larger unit of work, without a session in its signature.

Failures arrive as exceptions, which is what the driver raises and what a try/catch expects. Where a failure should be a value instead, the result style has a door for each width: asResult for one query, transactionResult for a transaction, and dbResult for anything else.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The dynamic_dto types this client knows: where they are registered, and where a value is wrapped for writing.

Functions

Link copied to clipboard
abstract override fun close()

Releases what this client holds. A data source it was given rather than built is not closed.

Link copied to clipboard
abstract fun deleteFrom(table: String): DeleteQuery

Starts building a DELETE from the given table. A WHERE is required before it will render.

Link copied to clipboard
abstract fun <T> execute(block: OctaviusSessionOperations.() -> T): T

Runs block on a session, and gives that session back when it returns.

Link copied to clipboard
open fun executeTransactionPlan(plan: TransactionPlan, propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: TransactionIsolationLevel? = null, readOnly: Boolean = false, statementTimeout: Duration? = null, transactionTimeout: Duration? = null): TransactionPlanResult

Runs every step of plan in one transaction, in the order they were added, and returns what each produced.

Link copied to clipboard
abstract fun insertInto(table: String): InsertQuery

Starts building an INSERT into the given table.

Link copied to clipboard
abstract fun rawQuery(sql: String): RawQuery

Prepares SQL written by hand, with @name parameters.

Link copied to clipboard
abstract fun select(vararg columns: String): SelectQuery

Starts building a SELECT over the given columns.

Link copied to clipboard
abstract fun <T> transaction(propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: TransactionIsolationLevel? = null, readOnly: Boolean = false, statementTimeout: Duration? = null, transactionTimeout: Duration? = null, block: OctaviusClient.() -> T): T

Runs block inside a transaction, committing when it returns and rolling back when it throws.

Link copied to clipboard
open fun <T> transactionResult(propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: TransactionIsolationLevel? = null, readOnly: Boolean = false, statementTimeout: Duration? = null, transactionTimeout: Duration? = null, block: OctaviusClient.() -> DataResult<T>): DataResult<T>

Runs block in a transaction that understands a returned failure, and hands back what it produced.

Link copied to clipboard
abstract fun update(table: String): UpdateQuery

Starts building an UPDATE of the given table. A WHERE is required before it will render.