Class ConnectionAndTransactionHolder
- Namespace
- Quartz.Impl.AdoJobStore
- Assembly
- Quartz.dll
Unit of work for AdoJobStore operations.
public sealed class ConnectionAndTransactionHolder : IDisposable, IAsyncDisposable
- Inheritance
-
ConnectionAndTransactionHolder
- Implements
- Inherited Members
Constructors
ConnectionAndTransactionHolder(DbConnection, DbTransaction?)
Initializes a new instance of the ConnectionAndTransactionHolder class that owns the connection and the transaction, and therefore commits, rolls back, closes and disposes them.
public ConnectionAndTransactionHolder(DbConnection connection, DbTransaction? transaction)
Parameters
connectionDbConnectionThe connection.
transactionDbTransactionThe transaction.
ConnectionAndTransactionHolder(DbConnection, DbTransaction?, bool)
Initializes a new instance of the ConnectionAndTransactionHolder class over a connection somebody else owns.
public ConnectionAndTransactionHolder(DbConnection connection, DbTransaction? transaction, bool ownsResources)
Parameters
connectionDbConnectionThe connection.
transactionDbTransactionThe transaction, if the caller began one.
ownsResourcesboolWhether this unit of work owns the connection and transaction. When false they belong to the caller, and this holder will neither commit, roll back, close nor dispose them.
Remarks
This is the shape a job store outside this assembly needs in order to run on a connection it did not open — the one an application enlisted, or one a container hands it. Owning nothing means committing nothing: whoever owns the transaction decides its outcome, and a rollback here would discard their work along with the scheduling.
A store that wants to honour enlisted transactions has more to do than build a holder over the enlisted connection: the enlistment has to be checked for the connection still being usable, and booked out for the duration of the operation so that two overlapping operations do not share it. The shipped ADO stores do both before they get here.
Properties
CanCreateBatch
Whether the underlying provider can execute several statements as one DbBatch, i.e. in a single round-trip. Defaults to false on DbConnection, so providers without batching support simply report no support and callers fall back to issuing the statements one at a time.
public bool CanCreateBatch { get; }
Property Value
Connection
The connection this unit of work runs on.
public DbConnection Connection { get; }
Property Value
OwnsResources
Whether this unit of work owns the connection and the transaction. When it does not, whoever handed them over is responsible for committing, rolling back and disposing them.
public bool OwnsResources { get; }
Property Value
Transaction
The transaction this unit of work runs in, or null when there is none.
public DbTransaction? Transaction { get; }
Property Value
Methods
Attach(DbCommand)
Puts this unit of work's connection and transaction on a command, so that it takes part in it.
public void Attach(DbCommand cmd)
Parameters
cmdDbCommandThe command to attach.
Close(CancellationToken)
Closes the connection, if this unit of work owns it.
public ValueTask Close(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
CreateBatch()
Creates a DbBatch enlisted in this unit of work. Only valid when CanCreateBatch is true.
public DbBatch CreateBatch()
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Disposes asynchronously, letting a provider close its connection without blocking a thread.
The form to prefer in an async method: await using var conn = ....
public ValueTask DisposeAsync()