Table of Contents

Class SelectForUpdateLockHandler

Namespace
Quartz.Impl.AdoJobStore
Assembly
Quartz.dll

Database based lock handler that takes the lock by issuing SELECT ... FOR UPDATE against the lock row.

public class SelectForUpdateLockHandler : DbLockHandler, ILockHandler
Inheritance
SelectForUpdateLockHandler
Implements
Derived
Inherited Members

Constructors

SelectForUpdateLockHandler(IDbProvider)

Initializes a new instance of the SelectForUpdateLockHandler class.

[ActivatorUtilitiesConstructor]
public SelectForUpdateLockHandler(IDbProvider dbProvider)

Parameters

dbProvider IDbProvider

Remarks

This is the constructor the container uses. The other one takes strings, which no container can supply, and marking this one says so rather than leaving the choice ambiguous.

SelectForUpdateLockHandler(string, string, string?, IDbProvider)

Initializes a new instance of the SelectForUpdateLockHandler class.

public SelectForUpdateLockHandler(string tablePrefix, string schedulerName, string? selectWithLockSql, IDbProvider dbProvider)

Parameters

tablePrefix string

The table prefix.

schedulerName string

the scheduler name

selectWithLockSql string

The select with lock SQL.

dbProvider IDbProvider

The database this handler takes its locks in.

SelectForUpdateLockHandler(string, string?, string?, string, IDbProvider)

Initializes a new instance of the SelectForUpdateLockHandler class for a subclass that needs its own insert statement.

protected SelectForUpdateLockHandler(string tablePrefix, string? schedulerName, string? selectWithLockSql, string insertLockSql, IDbProvider dbProvider)

Parameters

tablePrefix string

The table prefix.

schedulerName string

the scheduler name

selectWithLockSql string

The select with lock SQL.

insertLockSql string

The statement that inserts the lock row when it does not exist yet.

dbProvider IDbProvider

The db provider.

Remarks

The insert arrives here rather than being assigned afterwards, because the base class folds the table prefix into both statements once, at construction.

Fields

InsertLock

The statement that inserts the lock row when it does not exist yet.

protected const string InsertLock = "INSERT INTO {0}LOCKS(SCHED_NAME, LOCK_NAME) VALUES (@schedulerName, @lockName)"

Field Value

string

SelectForLock

The statement that takes the lock by selecting its row for update.

protected const string SelectForLock = "SELECT * FROM {0}LOCKS WHERE SCHED_NAME = @schedulerName AND LOCK_NAME = @lockName FOR UPDATE"

Field Value

string

Properties

MaxRetry

Maximum retry attempts, defaults to 3.

public int MaxRetry { get; init; }

Property Value

int

Remarks

Init-only: how many times a lock attempt is retried is fixed for the life of the handler, and a setter invited changing it while a contended lock was mid-retry. The flat quartz.jobStore.lockHandler.maxRetry and …retryPeriod keys still reach it — the property bridge writes the handler by reflection, and an init accessor is a setter as far as reflection is concerned.

RetryPeriod

Sleep between attempts, defaults to 1 second.

[TimeSpanParseRule(TimeSpanParseRule.Milliseconds)]
public TimeSpan RetryPeriod { get; init; }

Property Value

TimeSpan

Remarks

Init-only: how many times a lock attempt is retried is fixed for the life of the handler, and a setter invited changing it while a contended lock was mid-retry. The flat quartz.jobStore.lockHandler.maxRetry and …retryPeriod keys still reach it — the property bridge writes the handler by reflection, and an init accessor is a setter as far as reflection is concerned.

Methods

ExecuteSql(Guid, ConnectionAndTransactionHolder, string, string, string, CancellationToken)

Execute the SQL select for update that will lock the proper database row.

protected override ValueTask ExecuteSql(Guid requestorId, ConnectionAndTransactionHolder conn, string lockName, string expandedSql, string expandedInsertSql, CancellationToken cancellationToken = default)

Parameters

requestorId Guid
conn ConnectionAndTransactionHolder
lockName string
expandedSql string
expandedInsertSql string
cancellationToken CancellationToken

Returns

ValueTask