Class AttemptContext
Provides methods that allow an application's transaction logic to read, mutate, insert, and delete documents.
Inheritance
Namespace: Couchbase.Integrated.Transactions
Assembly: Couchbase.NetClient.dll
Syntax
public class AttemptContext : object
Properties
| Improve this Doc View SourceAttemptId
Gets the ID of this individual attempt.
Declaration
public string AttemptId { get; }
Property Value
Type | Description |
---|---|
System.String |
Logger
Gets the logger instance used for this AttemptContext.
Declaration
public ILogger<AttemptContext> Logger { get; }
Property Value
Type | Description |
---|---|
ILogger<AttemptContext> |
TransactionId
Gets the ID of this overall transaction.
Declaration
public string TransactionId { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceCommitAsync(IRequestSpan)
Commits the transaction.
Declaration
public async Task CommitAsync(IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
IRequestSpan | parentSpan | (optional) RequestSpan to use as a parent for tracing. |
Returns
Type | Description |
---|---|
Task |
ConvertQueryError(Exception)
INTERNAL
Declaration
public Exception? ConvertQueryError(Exception err)
Parameters
Type | Name | Description |
---|---|---|
Exception | err | INTERNAL |
Returns
Type | Description |
---|---|
System.Nullable<Exception> | INTERNAL |
GetAsync(ICouchbaseCollection, String)
Gets a document.
Declaration
public async Task<TransactionGetResult> GetAsync(ICouchbaseCollection collection, string id)
Parameters
Type | Name | Description |
---|---|---|
ICouchbaseCollection | collection | The collection to look up the document in. |
System.String | id | The ID of the document. |
Returns
Type | Description |
---|---|
Task<TransactionGetResult> | A TransactionGetResult containing the document. |
Exceptions
Type | Condition |
---|---|
DocumentNotFoundException | If the document does not exist. |
GetOptionalAsync(ICouchbaseCollection, String, IRequestSpan)
Gets a document or null.
Declaration
public Task<TransactionGetResult> GetOptionalAsync(ICouchbaseCollection collection, string id, IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
ICouchbaseCollection | collection | The collection to look up the document in. |
System.String | id | The ID of the document. |
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task<TransactionGetResult> | A TransactionGetResult containing the document, or null if not found. |
InsertAsync(ICouchbaseCollection, String, Object, IRequestSpan)
Insert a document.
Declaration
public Task<TransactionGetResult> InsertAsync(ICouchbaseCollection collection, string id, object content, IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
ICouchbaseCollection | collection | The collection to insert the document into. |
System.String | id | The ID of the new document. |
System.Object | content | The content of the new document. |
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task<TransactionGetResult> | A TransactionGetResult representing the inserted document. |
QueryAsync<T>(String, TransactionQueryOptions, IScope, IRequestSpan)
Run a query in transaction mode.
Declaration
public Task<IQueryResult<T>> QueryAsync<T>(string statement, TransactionQueryOptions options, IScope scope = null, IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | statement | The statement to execute. |
TransactionQueryOptions | options | The query options to use for this query. |
IScope | scope | The scope |
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task<IQueryResult<T>> | A SingleQueryTransactionResult<T> with the query results, if any. |
Type Parameters
Name | Description |
---|---|
T | The type of the result. Use |
Remarks
IMPORTANT: Any KV operations after this query will be run via the query engine, which has performance implications.
RemoveAsync(TransactionGetResult, IRequestSpan)
Remove a document previously looked up in this transaction.
Declaration
public Task RemoveAsync(TransactionGetResult doc, IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
TransactionGetResult | doc | The TransactionGetResult of a document previously looked up in this transaction. |
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous work. |
ReplaceAsync(TransactionGetResult, Object, IRequestSpan)
Replace the content of a document previously fetched in this transaction with new content.
Declaration
public Task<TransactionGetResult> ReplaceAsync(TransactionGetResult doc, object content, IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
TransactionGetResult | doc | The TransactionGetResult of a document previously looked up in this transaction. |
System.Object | content | The updated content. |
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task<TransactionGetResult> | A TransactionGetResult reflecting the updated content. |
RollbackAsync(IRequestSpan)
Rollback the transaction, explicitly.
Declaration
public Task RollbackAsync(IRequestSpan parentSpan = null)
Parameters
Type | Name | Description |
---|---|---|
IRequestSpan | parentSpan | The optional parent tracing span. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous work. |
Remarks
Calling this method on AttemptContext is usually unnecessary, as unhandled exceptions will trigger a rollback automatically.