public sealed class SpannerTransaction : DbTransaction, IDbTransaction, IDisposable, ISpannerTransaction
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.
Namespace
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 |
Int32 |
DbConnection
protected override DbConnection DbConnection { get; }
Property Value | |
---|---|
Type | Description |
DbConnection |
DisposeBehavior
public DisposeBehavior DisposeBehavior { get; set; }
Specifies how resources are treated when Dispose(Boolean) is called. The default behavior of ReleaseToPool will cause transactional resources to be sent back into a shared pool for re-use. Shared transactions may only set this value to either CloseResources to close resources or Detach to detach from the resources. A shared transaction must have one process choose CloseResources to avoid leaks of transactional resources.
Property Value | |
---|---|
Type | Description |
DisposeBehavior |
IsolationLevel
public override IsolationLevel IsolationLevel { get; }
Property Value | |
---|---|
Type | Description |
IsolationLevel |
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 |
Boolean |
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.
Shared
public bool Shared { get; }
Returns true if this transaction is being used by multiple Google.Cloud.Spanner.Data.SpannerTransaction.SpannerConnection objects. GetReaderPartitionsAsync(Nullable<Int64>, Nullable<Int64>, CancellationToken) will automatically mark the transaction as shared because it is expected that you will be distributing the read among several tasks or processes.
Property Value | |
---|---|
Type | Description |
Boolean |
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()
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(CancellationToken))
Commits the database transaction asynchronously.
Parameter | |
---|---|
Name | Description |
cancellationToken | CancellationToken A cancellation token used for this task. |
Returns | |
---|---|
Type | Description |
Task<DateTime> | 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(Boolean)
protected override void Dispose(bool disposing)
Parameter | |
---|---|
Name | Description |
disposing | Boolean |
Rollback()
public override void Rollback()
RollbackAsync(CancellationToken)
public Task RollbackAsync(CancellationToken cancellationToken = default(CancellationToken))
Rolls back a transaction asynchronously.
Parameter | |
---|---|
Name | Description |
cancellationToken | CancellationToken A cancellation token used for this task. |
Returns | |
---|---|
Type | Description |
Task |