# new ContextLock()
Default transaction boundary implementation stored on the Context by @transactional.
Gated by the maxConcurrentTransactions flag (see AdapterFlags): -1 (default) means no limit and
begin/commit/rollback behave as a no-op; 0 disables transactions outright (every call throws);
any positive number gates concurrent transactions through SimpleConcurrencyLock.for(adapter, limit),
the one counting semaphore shared by every transaction on that adapter, queuing callers until a slot
frees up.
Adapters with native transaction support (e.g. a SQL adapter wrapping BEGIN/COMMIT/ROLLBACK) override
Adapter.transactionLock() to return a subclass with real begin/commit/rollback behavior - if that
subclass does not call super.begin()/super.commit()/super.rollback(), maxConcurrentTransactions
has no effect for it, since concurrency is then governed by the underlying database instead.
transactionLock() always returns a fresh ContextLock per top-level transaction - it's the
per-transaction handle (nesting depth, and for native adapters the actual exclusive connection/cursor),
so it cannot be a singleton itself; only the concurrency gate it delegates to is shared.
Nesting (reusing the same instance across nested @transactional calls, and deciding when to actually
call begin/commit/rollback) is owned by the @transactional proxy via depth, not by this class.
Per-adapter transaction lock
Members
Methods
# async begin(context) → {Promise.<void>}
context already exists by the time this is called (the @transactional proxy always
builds it before calling begin), so this routes it through Adapter.logCtx() with allowCreate
left at its default false - there is nothing to create here, only the existing context (and its
logger) to reuse. Passing allowCreate: true would be wrong: it skips the "reuse the context I was
given" branch entirely and tries to build a new one through Adapter.context(), whose third
positional parameter is reserved for a model constructor - the context would be misread as "model".
Called once, by the outermost @transactional call
Parameters:
| Name | Type | Description |
|---|---|---|
context |
Context.<any>
|
The context the transaction is starting under |
Promise.<void>
# async commit(context) → {Promise.<void>}
Called once, when the outermost @transactional call exits successfully
Called once, when the outermost @transactional call exits successfully
Parameters:
| Name | Type | Description |
|---|---|---|
context |
Context.<any>
|
The context the transaction ran under |
Promise.<void>
# async rollback(err, context) → {Promise.<void>}
Called once, by whichever call hits the error first.
Called once, by whichever call hits the error first. Ends the transaction outright
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error
|
The error that triggered the rollback |
context |
Context.<any>
|
The context the transaction ran under |
Promise.<void>