DbTx

zio.blocks.sql.DbTx
See theDbTx companion object
trait DbTx extends DbCon

Transactional connection with savepoint support for nested transactions.

Savepoint semantics: nested transactions are emulated via SQL savepoints named zib_tx_1 .. zib_tx_N where N is the nesting depth. On success the savepoint is released via RELEASE SAVEPOINT, on failure the transaction rolls back to the savepoint via ROLLBACK TO SAVEPOINT and rethrows the exception. Only the outermost Transactor.transact does a real COMMIT/ROLLBACK; inner blocks are savepoint-scoped and share the same underlying JDBC connection.

Depth tracking: each DbTx instance tracks its current nesting depth (0 = outermost). The counter is incremented only after the savepoint is created successfully and decremented in a finally block, guaranteeing correct depth even if savepoint creation throws and reset even when inner blocks throw.

Attributes

Companion
object
Source
DbTx.scala
Graph
Supertypes
trait DbCon
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def currentDepth: Int

Attributes

Source
DbTx.scala
def release(name: String): Unit

Release the savepoint with the given name.

Release the savepoint with the given name.

Implemented via RELEASE SAVEPOINT. No savepoint leak on the success path: every successful nested transact releases its savepoint before returning.

Attributes

Source
DbTx.scala
def rollbackTo(name: String): Unit

Roll back to the savepoint with the given name.

Roll back to the savepoint with the given name.

Implemented via ROLLBACK TO SAVEPOINT. The savepoint remains valid after rollback on most drivers; on failure only depth is decremented and the savepoint is not released (it will be cleaned up when outer transaction commits/rolls back).

Attributes

Source
DbTx.scala
def savepoint(name: String): Unit

Create a savepoint with the given name.

Create a savepoint with the given name.

Implemented via SAVEPOINT SQL for portability (SQLite, PostgreSQL). The underlying connection must be inside an active transaction (autoCommit = false).

Attributes

Source
DbTx.scala
def transact[A](f: DbTx ?=> A): A
Extension method from zio.blocks.sql

Execute f inside a savepoint nested transaction.

Execute f inside a savepoint nested transaction.

Creates savepoint zib_tx_ where depth is outer.currentDepth + 1, runs f with the same underlying connection (given DbTx is outer with incremented depth), releases on success and rolls back to the savepoint on failure. Depth is always decremented in finally. On failure only depth is decremented and the savepoint is not released (it will be cleaned up when outer transaction commits/rolls back).

Attributes

Source
DbTx.scala

Inherited and Abstract methods

Attributes

Inherited from:
DbCon
Source
DbCon.scala

Attributes

Inherited from:
DbCon
Source
DbCon.scala

Attributes

Inherited from:
DbCon
Source
DbCon.scala