TransactionalBatch class
Class representing a transactional batch. This implementation provides atomic and non-atomic transactions. Atomic transactions will always fail on error, and support a maximum of 100 operations per batch. For non-atomic transactions, the behavior in case of error can be controlled via the continueOnError flag. Non-atomic transactions send operations in chunks of 100, effectively working around the Cosmos DB limitation of 100 operations per batch.
- Inheritance
- Implemented types
Constructors
- TransactionalBatch.new(CosmosDbContainer container, {PartitionKey? partitionKey, bool continueOnError = true})
-
Creates a non-atomic Batch instance operating on
container
andpartitionKey
. The partition key is optional, provided each operation in this batch instance can provide a partition key. Operations working on a document should be able to extract the document's partition key using thecontainer
's PartitionKeySpec. By default,continueOnError
istrue
and all operations will be executed and report their status. IfcontinueOnError
isfalse
, the batch process will stop upon the first failing operation. In this case, that operation will report a specific error status while all subsequent operations will fail with a HttpStatusCode.failedDependency error status. - TransactionalBatch.atomic(CosmosDbContainer container, {PartitionKey? partitionKey})
-
Creates an atomic Batch instance operating on
container
andpartitionKey
. The partition key is optional, provided each operation in this batch instance can provide a partition key. Operations working on a document should be able to extract the document's partition key using thecontainer
's PartitionKeySpec. For atomic batches, the continueOnError flag is alwaysfalse
.
Properties
- container → CosmosDbContainer
-
The container this batch instance is attached to.
finalinherited
- continueOnError → bool
-
If
true
, processing will continue after an error. Otherwise, processing is stopped and subsequent operations fail with a 424 HttpStatusCode.failedDependency status code.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
The document's id.
finalinherited
- isAtomic → bool
-
If
true
, modifications are persisted to the container atomically. If an error occurs during processing, no modifications are persisted and all other operations fail with a 424 HttpStatusCode.failedDependency status code.final - isCrossPartition → bool
-
If
true
, operations registered with this batch may target multiple partition keys. Operations will be grouped by partition keys when execute is called. Implies continueOnError =true
and isAtomic =false
.final - length → int
-
The number of operations in this batch instance.
no setteroverride
-
operations
→ Iterable<
BatchOperation> -
The list of operations registered with this batch instance.
no setteroverride
- partitionKey → PartitionKey?
-
The default partition key for operations in this batch.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
BatchOperation op) → void -
Adds the specified BatchOperation to this batch instance.
override
-
create<
T extends BaseDocument> (T item, {PartitionKey? partitionKey}) → void -
Adds a BatchOperationCreate to this batch instance.
inherited
-
delete(
String id, {PartitionKey? partitionKey}) → void -
Adds a BatchOperationDelete to this batch instance.
inherited
-
execute(
{CosmosDbAccessControl? accessControl}) → Future< BatchResponse> -
Executes the BatchOperations registered in this batch instance.
override
-
getHeaders(
Iterable< PartitionKeyRange> pkRanges) → Map<String, String> - Returns the HTTP headers for this batch request (retrieves the partition key range ID and maps properties isAtomic and continueOnError).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch<
T extends BaseDocument> (String id, {PartitionKey? partitionKey}) → BatchOperationPatch< BaseDocument> -
Adds a BatchOperationPatch to this batch instance.
inherited
-
read<
T extends BaseDocument> (String id, {PartitionKey? partitionKey}) → void -
Adds a BatchOperationRead to this batch instance.
inherited
-
recycle(
) → void -
Recycles this batch instance for reuse. This method clears the list of operations.
override
-
replace<
T extends BaseDocument> (T item, {PartitionKey? partitionKey}) → void -
Adds a BatchOperationReplace to this batch instance.
inherited
-
toJson(
) → List -
Serializes this instance to a JSON object.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
upsert<
T extends BaseDocument> (T item, {PartitionKey? partitionKey}) → void -
Adds a BatchOperationUpsert to this batch instance.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited