public sealed class SpannerTransaction : SpannerTransactionBase, IDbTransaction, IDisposable, IAsyncDisposable
Reference documentation and code samples for the Google.Cloud.Spanner.Data class SpannerTransaction.
Represents a SQL transaction to be made in a Spanner database. A transaction in Cloud Spanner is a set of reads and writes that execute atomically at a single logical point in time across columns, rows, and tables in a database.
Inheritance
object > MarshalByRefObject > DbTransaction > SpannerTransactionBase > SpannerTransactionNamespace
Google.Cloud.Spanner.DataAssembly
Google.Cloud.Spanner.Data.dll
Properties
CommitPriority
public Priority CommitPriority { get; set; }
The RPC priority to use for the commit RPC of this transaction. This can only be set for read/write transactions. This priority is not used for commands that are executed on this transaction. Use Priority to set the priority of commands. The default priority is Unspecified.
Property Value | |
---|---|
Type | Description |
Priority |
CommitTimeout
public int CommitTimeout { get; set; }
Gets or sets the wait time before terminating the attempt to Commit() or Rollback() and generating an error. Defaults to the timeout from the connection string. A value of '0' normally indicates that no timeout should be used (it waits an infinite amount of time). However, if you specify AllowImmediateTimeouts=true in the connection string, '0' will cause a timeout that expires immediately. This is normally used only for testing purposes.
Property Value | |
---|---|
Type | Description |
int |
DbConnection
protected override DbConnection DbConnection { get; }
Specifies the DbConnection object associated with the transaction.
Property Value | |
---|---|
Type | Description |
DbConnection |
The DbConnection object associated with the transaction. |
DisposeBehavior
public DisposeBehavior DisposeBehavior { get; set; }
Specifies how resources are treated when Dispose(bool) is called. Defaults to Default. For a pooled transaction, Default will cause transactional resources to be sent back into a shared pool for re-use. For a detached transaction the default behaviour is to do nothing with transactional resources. If set to CloseResources all transactional resource will be closed. A detached transaction must have one process choose CloseResources to avoid leaks of transactional resources.
Property Value | |
---|---|
Type | Description |
DisposeBehavior |
IsDetached
public bool IsDetached { get; }
Whether this transaction is detached or not. A detached transaction's resources are not pooled, so the transaction may be shared across processes for instance, for partitioned reads.
Property Value | |
---|---|
Type | Description |
bool |
IsolationLevel
public override IsolationLevel IsolationLevel { get; }
Specifies the IsolationLevel for this transaction.
Property Value | |
---|---|
Type | Description |
IsolationLevel |
The IsolationLevel for this transaction. |
LogCommitStats
public bool LogCommitStats { get; set; }
Specifies whether this transaction should request commit statistics from the backend and log these. This property is by default equal to the value set on the SpannerConnection of this transaction, but can be overridden for a specific transaction.
Property Value | |
---|---|
Type | Description |
bool |
MaxCommitDelay
public TimeSpan? MaxCommitDelay { get; set; }
The maximum amount of time the commit may be delayed server side for batching with other commits. The bigger the delay, the better the throughput (QPS), but at the expense of commit latency. If set to Zero, commit batching is disabled. May be null, in which case commits will continue to be batched as they had been before this configuration option was made available to Spanner API consumers. May be set to any value between Zero and 500ms.
Property Value | |
---|---|
Type | Description |
TimeSpan |
Mode
public TransactionMode Mode { get; }
Indicates the TransactionMode for the transaction.
Property Value | |
---|---|
Type | Description |
TransactionMode |
Cloud Spanner supports two transaction modes:
- Locking read-write transactions are the only transaction type that support writing data into Cloud Spanner. These transactions rely on pessimistic locking and, if necessary, two-phase commit. Locking read-write transactions may abort, requiring the application to retry.
- Read-only transactions provide guaranteed consistency across several reads, but do not allow writes. Read-only transactions can be configured to read at timestamps in the past. Read-only transactions do not need to be committed and do not take locks.
ReadTimestamp
public Timestamp ReadTimestamp { get; }
The read timestamp of the read-only transaction if
ReturnReadTimestamp is true, else null
.
Property Value | |
---|---|
Type | Description |
Timestamp |
Tag
public string Tag { get; set; }
The transaction tag to use for this transaction. This can only be set for read/write transactions, and must be set before any statements are executed on the transaction.
Property Value | |
---|---|
Type | Description |
string |
TimestampBound
public TimestampBound TimestampBound { get; }
Tells Cloud Spanner how to choose a timestamp at which to read the data for read-only transactions.
Property Value | |
---|---|
Type | Description |
TimestampBound |
The types of timestamp bounds are:
- Strong (the default): read the latest data.
- Bounded staleness: read a version of the data that's no staler than a bound.
- Exact staleness: read the version of the data at an exact timestamp.
TransactionId
public TransactionId TransactionId { get; }
Identifying information about this transaction.
Property Value | |
---|---|
Type | Description |
TransactionId |
Methods
Commit()
public override void Commit()
Commits the database transaction.
Commit(out DateTime)
public void Commit(out DateTime timestamp)
Commits the database transaction synchronously, returning the database timestamp for the commit via timestamp
.
Parameter | |
---|---|
Name | Description |
timestamp |
DateTime Returns the UTC timestamp when the data was written to the database. |
CommitAsync(CancellationToken)
public Task<DateTime> CommitAsync(CancellationToken cancellationToken = default)
Commits the database transaction asynchronously, returning the commit timestamp.
Parameter | |
---|---|
Name | Description |
cancellationToken |
CancellationToken A cancellation token used for this task. |
Returns | |
---|---|
Type | Description |
TaskDateTime |
Returns the UTC timestamp when the data was written to the database. |
CreateBatchDmlCommand()
public SpannerBatchCommand CreateBatchDmlCommand()
Creates a new SpannerBatchCommand to execute batched DML statements within this transaction. You can add commands to the batch by using Add(SpannerCommand), Add(SpannerCommandTextBuilder, SpannerParameterCollection) and Add(string, SpannerParameterCollection).
Returns | |
---|---|
Type | Description |
SpannerBatchCommand |
Dispose(bool)
protected override void Dispose(bool disposing)
Releases the unmanaged resources used by the DbTransaction and optionally releases the managed resources.
Parameter | |
---|---|
Name | Description |
disposing |
bool If true, this method releases all resources held by any managed objects that this DbTransaction references. |
Rollback()
public override void Rollback()
Rolls back a transaction from a pending state.
RollbackAsync(CancellationToken)
public override Task RollbackAsync(CancellationToken cancellationToken = default)
Rolls back a transaction asynchronously.
Parameter | |
---|---|
Name | Description |
cancellationToken |
CancellationToken A cancellation token used for this task. |
Returns | |
---|---|
Type | Description |
Task |