public sealed class ManagedTransaction : IAsyncDisposableReference documentation and code samples for the Google Cloud Spanner v1 API class ManagedTransaction.
A managed transaction that will acquire a Spanner transaction as needed and apply it to requests executed with it.
Implements
IAsyncDisposableNamespace
Google.Cloud.Spanner.V1Assembly
Google.Cloud.Spanner.V1.dll
Remarks
Each method in this class modifies requests passed as arguments to RPC methods, to populate the session and transaction properties.
Properties
ReadTimestamp
public Timestamp ReadTimestamp { get; }The read timestamp of the transaction. May be null.
| Property Value | |
|---|---|
| Type | Description |
Timestamp |
|
Will be set iif a transaction has been started and TransactionOptions represents read-only options with ReturnReadTimestamp set to true or if this session was created using FromTransaction(SpannerClient, Session, ByteString, TransactionOptions, Timestamp) and a non-null was provided for the Timestamp parameter.
SessionName
public SessionName SessionName { get; }The name of the session. This is never null.
| Property Value | |
|---|---|
| Type | Description |
SessionName |
|
TransactionId
public ByteString TransactionId { get; }The ID of the transaction. Will be null if a Spanner transaction hasn't been created yet. Spanner transaction is usually created when the first command that requires a transaction is executed via this ManagedTransaction.
| Property Value | |
|---|---|
| Type | Description |
ByteString |
|
Methods
CommitAsync(CommitRequest, CallSettings)
public Task<CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings)Executes a Commit RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
CommitRequestThe commit request. Must not be null. The request will be modified with session and transaction details from this object. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskCommitResponse |
A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
DisposeAsync()
public ValueTask DisposeAsync()Rollbacks the Spanner transaction if it was read/write, it hasn't been committed or rollbacked and the managed transaction is not shared.
| Returns | |
|---|---|
| Type | Description |
ValueTask |
|
ExecuteBatchDmlAsync(ExecuteBatchDmlRequest, CallSettings)
public Task<ExecuteBatchDmlResponse> ExecuteBatchDmlAsync(ExecuteBatchDmlRequest request, CallSettings callSettings)Executes an ExecuteBatchDml RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
ExecuteBatchDmlRequestThe query request. Must not be null. The request will be modified with session and transaction details from this object. If this object's TransactionId is null, the request's transaction is not modified. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskExecuteBatchDmlResponse |
A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
ExecuteSqlAsync(ExecuteSqlRequest, CallSettings)
public Task<ResultSet> ExecuteSqlAsync(ExecuteSqlRequest request, CallSettings callSettings)Executes an ExecuteSql RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
ExecuteSqlRequestThe query request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskResultSet |
A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
ExecuteSqlStreamReader(ExecuteSqlRequest, CallSettings)
public ReliableStreamReader ExecuteSqlStreamReader(ExecuteSqlRequest request, CallSettings callSettings)Creates a ReliableStreamReader for the given request.
| Parameters | |
|---|---|
| Name | Description |
request |
ExecuteSqlRequestThe query request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
ReliableStreamReader |
A ReliableStreamReader for the streaming SQL request. |
FreshAfterAbort()
public ManagedTransaction FreshAfterAbort()Creates a new managed transaction from this one. This is useful for preserving lock ordering in the event of the current transaction being aborted.
| Returns | |
|---|---|
| Type | Description |
ManagedTransaction |
|
FromTransaction(SpannerClient, Session, ByteString, TransactionOptions, Timestamp)
public static ManagedTransaction FromTransaction(SpannerClient client, Session session, ByteString transactionId, TransactionOptions transactionOptions, Timestamp readTimestamp)Creates a ManagedTransaction associated to the pair session,
transactionId.
| Parameters | |
|---|---|
| Name | Description |
client |
SpannerClient |
session |
Session |
transactionId |
ByteString |
transactionOptions |
TransactionOptions |
readTimestamp |
Timestamp |
| Returns | |
|---|---|
| Type | Description |
ManagedTransaction |
|
Note that no Spanner transaction will be started. The transaction identified by transactionId
should have been started or obtained earlier by the caller.
PartitionQueryAsync(PartitionQueryRequest, CallSettings)
public Task<PartitionResponse> PartitionQueryAsync(PartitionQueryRequest request, CallSettings callSettings)Executes a PartitionQuery RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
PartitionQueryRequestThe partitioning request. Must not be null. The request will be modified with session details from this object. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskPartitionResponse |
A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
PartitionReadAsync(PartitionReadRequest, CallSettings)
public Task<PartitionResponse> PartitionReadAsync(PartitionReadRequest request, CallSettings callSettings)Executes a PartitionRead RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
PartitionReadRequestThe partitioning request. Must not be null. The request will be modified with session details from this object. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskPartitionResponse |
A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
ReadStreamReader(ReadRequest, CallSettings)
public ReliableStreamReader ReadStreamReader(ReadRequest request, CallSettings callSettings)Creates a ReliableStreamReader for the given request.
| Parameters | |
|---|---|
| Name | Description |
request |
ReadRequestThe read request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
ReliableStreamReader |
A ReliableStreamReader for the streaming SQL request. |
RollbackAsync(RollbackRequest, CallSettings)
public Task RollbackAsync(RollbackRequest request, CallSettings callSettings)Executes a Rollback RPC asynchronously.
| Parameters | |
|---|---|
| Name | Description |
request |
RollbackRequestThe rollback request. Must not be null. The request will be modified with session and transaction details from this object. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
Task |
A task representing the asynchronous operation. |