public sealed class PooledSession : IDisposable
Reference documentation and code samples for the Google Cloud Spanner v1 API class PooledSession.
A session from a SessionPool, with an associated transaction if requested. Instances must be released back to the pool via ReleaseToPool(Boolean).
Implements
IDisposableNamespace
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.
This class keeps track of successful RPCs to update its internal refresh timer. This can't be applied for streaming SQL calls, as ReliableStreamReader performs the actual RPCs in that case.
Properties
ReadTimestamp
public Timestamp ReadTimestamp { get; }
The read timestamp of the transaction. (Always null
if
ReturnReadTimestamp = false or if TransactionMode != ReadOnly.)
Property Value | |
---|---|
Type | Description |
Timestamp |
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. May be null.
Property Value | |
---|---|
Type | Description |
ByteString |
Methods
CommitAsync(CommitRequest, CallSettings)
public async Task<CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings)
Executes a Commit RPC asynchronously.
Parameters | |
---|---|
Name | Description |
request | CommitRequest The commit request. Must not be null. The request will be modified with session and transaction details from this object. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<CommitResponse> | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |
Dispose()
public void Dispose()
Releases this session back to the session pool. This method should only be called once per instance; subsequent calls are ignored. No other methods can be called after this.
This method is equivalent to calling ReleaseToPool(Boolean) with an argument of false
.
ExecuteBatchDmlAsync(ExecuteBatchDmlRequest, CallSettings)
public Task<ExecuteBatchDmlResponse> ExecuteBatchDmlAsync(ExecuteBatchDmlRequest request, CallSettings callSettings)
Executes an ExecuteBatchDml RPC asynchronously.
Parameters | |
---|---|
Name | Description |
request | ExecuteBatchDmlRequest The 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 | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<ExecuteBatchDmlResponse> | 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 | ExecuteSqlRequest The 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 | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<ResultSet> | 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 | ExecuteSqlRequest The 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 | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
ReliableStreamReader | A ReliableStreamReader for the streaming SQL request. |
PartitionQueryAsync(PartitionQueryRequest, CallSettings)
public Task<PartitionResponse> PartitionQueryAsync(PartitionQueryRequest request, CallSettings callSettings)
Executes a PartitionQuery RPC asynchronously.
Parameters | |
---|---|
Name | Description |
request | PartitionQueryRequest The partitioning request. Must not be null. The request will be modified with session details from this object. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<PartitionResponse> | 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 | PartitionReadRequest The partitioning request. Must not be null. The request will be modified with session details from this object. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<PartitionResponse> | 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 | ReadRequest The read 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 | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
ReliableStreamReader | A ReliableStreamReader for the streaming SQL request. |
ReleaseToPool(Boolean)
public void ReleaseToPool(bool forceDelete)
Returns this session to the session pool from which it was acquired, unless it has become invalid. This method should only be called once per instance; subsequent calls are ignored. No other methods can be called after this.
Parameter | |
---|---|
Name | Description |
forceDelete | Boolean true to force the session to be deleted; false to allow the session to be reused. |
RollbackAsync(RollbackRequest, CallSettings)
public async Task RollbackAsync(RollbackRequest request, CallSettings callSettings)
Executes a Rollback RPC asynchronously.
Parameters | |
---|---|
Name | Description |
request | RollbackRequest The rollback request. Must not be null. The request will be modified with session and transaction details from this object. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task | A task representing the asynchronous operation. |
WithFreshTransactionOrNewAsync(TransactionOptions, CancellationToken)
public Task<PooledSession> WithFreshTransactionOrNewAsync(TransactionOptions transactionOptions, CancellationToken cancellationToken)
Always returns a new instance of PooledSession. The new instance can:
- represent the same session as this one, but will have a fresh transaction of the same type as this PooledSession did.
- represent an entirely different session with a fresh transaction of the same type as this PooledSession did. This method will always try to get a fresh transaction for this session. If the session has expired or it fails to get a fresh transaction, then it will acquire a session in the normal way. This PooledSession instance will be disposed of to ensure that all operations with the underlying session are done through the new instance.
Parameters | |
---|---|
Name | Description |
transactionOptions | TransactionOptions |
cancellationToken | CancellationToken |
Returns | |
---|---|
Type | Description |
Task<PooledSession> | A new instance of PooledSession. |
Use this method when executing operations that are best done using the same session. For instance, when retrying aborted commits it is better if the transaction work and commit are retried with the same session, because after each abort the sessions' lock priority increments.
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | If this Google.Cloud.Spanner.V1.PooledSession.TransactionMode is None. |