pub trait TransactionSession:
Any
+ Send
+ Sync
+ 'static {
// Required methods
fn datasource(&self) -> &str;
fn state(&self) -> TransactionState;
fn begin(&self) -> BeginFuture<'_>;
fn set_rollback_only(&self);
fn is_rollback_only(&self) -> bool;
fn commit(&self) -> FinalizeFuture<'_>;
fn rollback(&self) -> FinalizeFuture<'_>;
}Expand description
One block-owned transaction on one datasource.
A session owns (or guards) its pooled connection for the whole block, so
every joined sql step on the block datasource shares one transaction
(requirement “Join semantics for sql steps on the block datasource”). The
session is 'static so the implementing crate can downcast the trait object
to its concrete type for statement execution without camel-api gaining a
SQL value model.
The Any supertrait makes that downcast a trait-object upcast: an
Arc<dyn TransactionSession> coerces to Arc<dyn Any + Send + Sync> and
Arc::downcast recovers the concrete session
type. Any is auto-implemented, so implementors carry no extra burden.
Required Methods§
Sourcefn datasource(&self) -> &str
fn datasource(&self) -> &str
Datasource this session runs on.
Sourcefn state(&self) -> TransactionState
fn state(&self) -> TransactionState
Current lifecycle state.
Slice 2 relies on the explicit machine (Fresh → Active → Finalizing → Done | Detached) rather than inferring state from a borrow.
Sourcefn begin(&self) -> BeginFuture<'_>
fn begin(&self) -> BeginFuture<'_>
Send the lazy BEGIN.
Called at the first joined sql step, not when the session opens.
Precondition Clean; Ok(()) if already Open (idempotent);
Err(SessionAborted) otherwise. A begin that arrives while the
session’s execution slot is held is rejected with the typed Busy
error. The owner SHALL call begin only
from the Clean state or to observe an already-open session, and
admission hygiene must have been acknowledged before the first
BEGIN (requirement “Lazy begin and block-owned commit/rollback”).
Sourcefn set_rollback_only(&self)
fn set_rollback_only(&self)
Mark the session rollback-only.
Slice 2 calls this before returning a joined database error to the pipeline (requirement “Handled joined DB errors are rollback-only”), so a handled error can never commit a server-aborted transaction.
Sourcefn is_rollback_only(&self) -> bool
fn is_rollback_only(&self) -> bool
Whether the session has been marked rollback-only.
Sourcefn commit(&self) -> FinalizeFuture<'_>
fn commit(&self) -> FinalizeFuture<'_>
Commit the block’s transaction.
Returns the observed TransactionOutcome; slice 2 relies on the
outcome (not just Ok) to distinguish an acknowledged commit from a
detached connection (requirement “Cancellation cutoff”, “Uncertain
finalization detaches the connection”).
Precondition Active. Otherwise no SQL is sent and the call returns
Err(SessionAborted). The owner SHALL call commit only when
state() == Active.
Sourcefn rollback(&self) -> FinalizeFuture<'_>
fn rollback(&self) -> FinalizeFuture<'_>
End the block without committing. Total over every lifecycle state; the implementation selects the action from its private phase:
- nothing begun (
Fresh, BEGIN never sent): no SQL, connection returned clean,Ok(RolledBack)(nothing was begun, so nothing is durable); - BEGIN sent but unacknowledged (
Fresh): no SQL, detach,Err(RollbackUncertain); Active: ROLLBACK within the finalize grace; acknowledged →Ok(RolledBack), else detach +Err(RollbackUncertain);Detached, or a defensiveFinalizing/Doneentry: no SQL,Err(RollbackUncertain)(error!log for the defensive entry).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".