public sealed class DatastoreTransactionImpl : DatastoreTransaction, IDisposable
Production implementation of DatastoreTransaction, using a DatastoreClient to implement the operations.
Implements
IDisposableNamespace
Google.Cloud.Datastore.V1Assembly
Google.Cloud.Datastore.V1.dll
Constructors
DatastoreTransactionImpl(DatastoreClient, String, String, ByteString)
public DatastoreTransactionImpl(DatastoreClient client, string projectId, string namespaceId, ByteString transactionId)
Constructs a DatastoreTransactionImpl from a client, project ID and transaction ID.
Parameters | |
---|---|
Name | Description |
client | DatastoreClient The client to use for Datastore operations. Must not be null. |
projectId | String The ID of the project of the Datastore operations. Must not be null. |
namespaceId | String The ID of the namespace which is combined with |
transactionId | ByteString The transaction obtained by an earlier BeginTransaction(String, CallSettings) or the asynchronous equivalent. Must not be null |
While this can be constructed manually, the expectation is that instances of this class are obtained via BeginTransaction(CallSettings) or BeginTransactionAsync(CallSettings).
Properties
TransactionId
public override ByteString TransactionId { get; }
The ID of the transaction, used implicitly in operations performed with this object.
Property Value | |
---|---|
Type | Description |
ByteString |
Methods
Commit(CallSettings)
public override CommitResponse Commit(CallSettings callSettings = null)
Commits all mutations in this transaction.
Parameter | |
---|---|
Name | Description |
callSettings | CallSettings |
Returns | |
---|---|
Type | Description |
CommitResponse | The response from the commit operation. This can be used to determine server-allocated keys. |
Any entities with incomplete keys that are assigned keys by this operation will be updated in memory with the server-allocated keys.
Datastore limits the number of entities that can be modified in a Commit operation, and therefore one transaction. When modifying a large number of entities, partition the changes into multiple transactions. See Datastore limits for more details on Datastore limits.
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The transaction has already been committed or rolled back. |
CommitAsync(CallSettings)
public override async Task<CommitResponse> CommitAsync(CallSettings callSettings = null)
Commits all mutations in this transaction asynchronously.
Parameter | |
---|---|
Name | Description |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
Task<CommitResponse> | The response from the commit operation. This can be used to determine server-allocated keys. |
Any entities with incomplete keys that are assigned keys by this operation will be updated in memory with the server-allocated keys.
Datastore limits the number of entities that can be modified in a Commit operation, and therefore one transaction. When modifying a large number of entities, partition the changes into multiple transactions. See Datastore limits for more details on Datastore limits.
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The transaction has already been committed or rolled back. |
Delete(IEnumerable<Entity>)
public override void Delete(IEnumerable<Entity> entities)
Adds delete operations for all the specified keys to this transaction.
Parameter | |
---|---|
Name | Description |
entities | IEnumerable<Entity> The entities to delete. Must not be null. |
Delete(IEnumerable<Key>)
public override void Delete(IEnumerable<Key> keys)
Adds deletion operations for all the specified keys to this transaction.
Parameter | |
---|---|
Name | Description |
keys | IEnumerable<Key> The keys to delete. Must not be null. |
Dispose()
public override void Dispose()
If the transaction has already been committed, this operation is a no-op. Otherwise, it rolls back the transaction.
Insert(IEnumerable<Entity>)
public override void Insert(IEnumerable<Entity> entities)
Adds insert operations for all the specified keys to this transaction.
Parameter | |
---|---|
Name | Description |
entities | IEnumerable<Entity> The entities to insert. Must not be null. |
Lookup(IEnumerable<Key>, CallSettings)
public override IReadOnlyList<Entity> Lookup(IEnumerable<Key> keys, CallSettings callSettings = null)
Looks up a collection of entities by key.
Parameters | |
---|---|
Name | Description |
keys | IEnumerable<Key> The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
IReadOnlyList<Entity> | A collection of entities with the same size as |
This call may perform multiple RPC operations in order to look up all keys.
LookupAsync(IEnumerable<Key>, CallSettings)
public override Task<IReadOnlyList<Entity>> LookupAsync(IEnumerable<Key> keys, CallSettings callSettings = null)
Looks up a collection of entities by key asynchronously.
Parameters | |
---|---|
Name | Description |
keys | IEnumerable<Key> The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
Task<IReadOnlyList<Entity>> | A collection of entities with the same size as |
This call may perform multiple RPC operations in order to look up all keys.
Rollback(CallSettings)
public override RollbackResponse Rollback(CallSettings callSettings = null)
Rolls back this transaction.
Parameter | |
---|---|
Name | Description |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
RollbackResponse |
This method is rarely useful explicitly; the Dispose() method rolls back the transaction if it
is still active, so a using
statement is normally preferable to this.
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The transaction has already been committed or rolled back. |
RollbackAsync(CallSettings)
public override async Task<RollbackResponse> RollbackAsync(CallSettings callSettings = null)
Rolls back this transaction asynchronously.
Parameter | |
---|---|
Name | Description |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
Task<RollbackResponse> |
This method is rarely useful explicitly; the Dispose() method rolls back the transaction if it
is still active, so a using
statement is normally preferable to this.
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The transaction has already been committed or rolled back. |
RunQueryLazily(GqlQuery, CallSettings)
public override LazyDatastoreQuery RunQueryLazily(GqlQuery gqlQuery, CallSettings callSettings = null)
Lazily executes the given GQL query in this transaction.
Parameters | |
---|---|
Name | Description |
gqlQuery | GqlQuery The query to execute. Must not be null. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
LazyDatastoreQuery | A LazyDatastoreQuery representing the result of the query. |
Using a transaction ensures that a commit operation will fail if any of the entities returned by this query have been modified while the transaction is active. Note that modifications performed as part of this operation are not reflected in the query results.
The results are requested lazily: no API calls will be made until the application starts iterating over the results. Iterating over the same LazyDatastoreQuery object multiple times will execute the query again, potentially returning different results.
RunQueryLazily(Query, CallSettings)
public override LazyDatastoreQuery RunQueryLazily(Query query, CallSettings callSettings = null)
Lazily executes the given structured query in this transaction.
Parameters | |
---|---|
Name | Description |
query | Query The query to execute. Must not be null. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
LazyDatastoreQuery | A LazyDatastoreQuery representing the the lazy query results. |
Using a transaction ensures that a commit operation will fail if any of the entities returned by this query have been modified while the transaction is active. Note that modifications performed as part of this operation are not reflected in the query results.
The results are requested lazily: no API calls will be made until the application starts iterating over the results. Iterating over the same LazyDatastoreQuery object multiple times will execute the query again, potentially returning different results.
RunQueryLazilyAsync(GqlQuery, CallSettings)
public override AsyncLazyDatastoreQuery RunQueryLazilyAsync(GqlQuery gqlQuery, CallSettings callSettings = null)
Lazily executes the given structured query in this transaction for asynchronous consumption.
Parameters | |
---|---|
Name | Description |
gqlQuery | GqlQuery The query to execute. Must not be null. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
AsyncLazyDatastoreQuery | An AsyncLazyDatastoreQuery representing the result of the query. |
Using a transaction ensures that a commit operation will fail if any of the entities returned by this query have been modified while the transaction is active. Note that modifications performed as part of this operation are not reflected in the query results.
The results are requested lazily: no API calls will be made until the application starts iterating over the results. Iterating over the same LazyDatastoreQuery object multiple times will execute the query again, potentially returning different results.
RunQueryLazilyAsync(Query, CallSettings)
public override AsyncLazyDatastoreQuery RunQueryLazilyAsync(Query query, CallSettings callSettings = null)
Lazily executes the given structured query in this transaction for asynchronous consumption.
Parameters | |
---|---|
Name | Description |
query | Query The query to execute. Must not be null. |
callSettings | CallSettings If not null, applies overrides to RPC calls. |
Returns | |
---|---|
Type | Description |
AsyncLazyDatastoreQuery | An AsyncLazyDatastoreQuery representing the result of the query. |
Using a transaction ensures that a commit operation will fail if any of the entities returned by this query have been modified while the transaction is active. Note that modifications performed as part of this operation are not reflected in the query results.
The results are requested lazily: no API calls will be made until the application starts iterating over the results. Iterating over the same LazyDatastoreQuery object multiple times will execute the query again, potentially returning different results.
Update(IEnumerable<Entity>)
public override void Update(IEnumerable<Entity> entities)
Adds update operations for all the specified keys to this transaction.
Parameter | |
---|---|
Name | Description |
entities | IEnumerable<Entity> The entities to update. Must not be null. |
Upsert(IEnumerable<Entity>)
public override void Upsert(IEnumerable<Entity> entities)
Adds upsert operations for all the specified keys to this transaction.
Parameter | |
---|---|
Name | Description |
entities | IEnumerable<Entity> The entities to upsert. Must not be null. |