sqlalchemy_dlock.lock.oracle module¶
Oracle database lock implementation using DBMS_LOCK
- class sqlalchemy_dlock.lock.oracle.OracleAsyncSadLock(connection_or_session, key, **kwargs)[source]¶
Bases:
OracleSadLockMixin,BaseAsyncSadLock[int,AsyncConnection|AsyncSession|async_scoped_session]Async IO version of OracleSadLock
- Parameters:
key (
Any) – Oracle lock identifier - Whenint: used directly as lock ID (must be 0-1073741823) - Whenstr/bytes: hashed to integer via blake2b - Other types are converted using default or custom converterconvert – Custom function to convert key to int
lock_mode – Lock mode to use - “X” (default): Exclusive mode - full exclusive access - “S”: Shared mode - multiple readers - “SS”: Sub-Shared - for aggregate objects - “SX”: Sub-Exclusive (Row Exclusive) - “SSX”: Shared Sub-Exclusive (Share Row Exclusive) - “NL”: Null mode - no actual locking
release_on_commit – Whether to release lock on commit/rollback - False (default): Lock held until explicit release or session ends - True: Lock released when transaction ends
connection_or_session (AsyncConnection | AsyncSession | async_scoped_session)
Lock Mode Compatibility Matrix: (Held Mode vs Get Mode: S=Success, F=Fail) HeldGet | NL | SS | SX | S | SSX | X ———|----|—-|----|—-|-----|— NL | S | S | S | S | S | S SS | S | S | S | S | S | F SX | S | S | S | F | F | F S | S | S | F | S | F | F SSX | S | S | F | F | F | F X | S | F | F | F | F | F
- class sqlalchemy_dlock.lock.oracle.OracleSadLock(connection_or_session, key, **kwargs)[source]¶
Bases:
OracleSadLockMixin,BaseSadLock[int,Connection|Session|scoped_session]Distributed lock implemented by Oracle DBMS_LOCK
Tip
Oracle user locks are identified with the prefix “UL” and can be viewed in Enterprise Manager lock monitor or appropriate V$ views.
Locks are automatically released when a session terminates.
String keys are converted to integer IDs using blake2b hash, similar to PostgreSQL’s advisory lock implementation.
- Parameters:
connection_or_session (
Connection|Session|scoped_session) – seeBaseSadLock.connection_or_sessionkey (
Any) –BaseSadLock.keylock_mode –
OracleSadLockMixin.lock_moderelease_on_commit –
OracleSadLockMixin.release_on_commitconvert –
OracleSadLockMixin**kwargs – other named parameters pass to
BaseSadLockandOracleSadLockMixin
- class sqlalchemy_dlock.lock.oracle.OracleSadLockMixin(*, key, convert=None, lock_mode='X', release_on_commit=False, **kwargs)[source]¶
Bases:
AbstractLockMixin[KTV,int]Mixin class for Oracle DBMS_LOCK
- Parameters:
key (
TypeVar(KTV, bound=Any)) – Oracle lock identifier - Whenint: used directly as lock ID (must be 0-1073741823) - Whenstr/bytes: hashed to integer via blake2b - Other types are converted using default or custom converterconvert (
Callable[[TypeVar(KTV, bound=Any)],int] |None) – Custom function to convert key to intlock_mode (
Literal['NL','SS','SX','S','SSX','X']) – Lock mode to use - “X” (default): Exclusive mode - full exclusive access - “S”: Shared mode - multiple readers - “SS”: Sub-Shared - for aggregate objects - “SX”: Sub-Exclusive (Row Exclusive) - “SSX”: Shared Sub-Exclusive (Share Row Exclusive) - “NL”: Null mode - no actual lockingrelease_on_commit (
bool) – Whether to release lock on commit/rollback - False (default): Lock held until explicit release or session ends - True: Lock released when transaction ends
Lock Mode Compatibility Matrix: (Held Mode vs Get Mode: S=Success, F=Fail) HeldGet | NL | SS | SX | S | SSX | X ———|----|—-|----|—-|-----|— NL | S | S | S | S | S | S SS | S | S | S | S | S | F SX | S | S | S | F | F | F S | S | S | F | S | F | F SSX | S | S | F | F | F | F X | S | F | F | F | F | F
- NL_MODE = 1¶
- SSX_MODE = 5¶
- SS_MODE = 2¶
- SX_MODE = 3¶
- S_MODE = 4¶
- X_MODE = 6¶
- classmethod convert(k)[source]¶
Default key converter for Oracle DBMS_LOCK
Similar to PostgreSQL: strings/bytes are hashed using blake2b.