CosmosContainer クラス

  • java.lang.Object
    • com.azure.cosmos.CosmosContainer

public class CosmosContainer

既存のコンテナーの読み取り、削除、および置き換えのための同期メソッドを提供する 子リソース (項目、スクリプト、競合) と対話するためのメソッドを提供します

メソッドの概要

修飾子と型 メソッドと説明
CosmosItemResponse<T> createItem(T item)

新しい項目を同期的に作成し、それぞれの Cosmos 項目の応答を返します。

CosmosItemResponse<T> createItem(T item, CosmosItemRequestOptions options)

新しい項目を同期的に作成し、追加のオプションを指定しながら、それぞれの Cosmos 項目の応答を返します。

CosmosItemResponse<T> createItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)

新しい項目を同期的に作成し、追加のオプションを指定しながら、それぞれの Cosmos 項目の応答を返します。

CosmosItemResponse<Object> deleteItem(T item, CosmosItemRequestOptions options)

現在のコンテナー内の項目を削除します。

CosmosItemResponse<T> patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, CosmosPatchItemRequestOptions options, Class<T> itemType)

アイテム全体を置き換えることなく、アイテムの特定のプロパティまたはフィールドを変更する部分更新を実行します。

CosmosItemResponse<T> patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, Class<T> itemType)

アイテム全体を置き換えることなく、アイテムの特定のプロパティまたはフィールドを変更する部分更新を実行します。

CosmosPagedIterable<T> queryChangeFeed(CosmosChangeFeedRequestOptions options, Class<T> classType)

を使用して、現在のコンテナーの変更フィード内の項目を照会します CosmosChangeFeedRequestOptions

CosmosPagedIterable<T> queryItems(SqlQuerySpec querySpec, CosmosQueryRequestOptions options, Class<T> classType)

結果を として CosmosPagedIterable<T>返す現在のコンテナー内のクエリ 項目。

CosmosPagedIterable<T> queryItems(String query, CosmosQueryRequestOptions options, Class<T> classType)

結果を として CosmosPagedIterable<T>返す現在のコンテナー内のクエリ 項目。

CosmosPagedIterable<T> readAllItems(PartitionKey partitionKey, CosmosQueryRequestOptions options, Class<T> classType)

結果を として CosmosPagedIterable<T>返す論理パーティションのすべての項目を読み取ります。

CosmosPagedIterable<T> readAllItems(PartitionKey partitionKey, Class<T> classType)

結果を として CosmosPagedIterable<T>返す論理パーティションのすべての項目を読み取ります。

CosmosItemResponse<T> readItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options, Class<T> itemType)

追加のオプションを指定しながら、現在のコンテナー内の項目を読み取ります。

CosmosItemResponse<T> readItem(String itemId, PartitionKey partitionKey, Class<T> itemType)

現在のコンテナー内の項目を読み取ります。

FeedResponse<T> readMany(List<CosmosItemIdentity> itemIdentityList, Class<T> classType)

多数のドキュメントを読み取ります。

FeedResponse<T> readMany(List<CosmosItemIdentity> itemIdentityList, String sessionToken, Class<T> classType)

多数のドキュメントを読み取ります。

CosmosItemResponse<T> replaceItem(T item, String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)

コンテナー内の既存の項目を新しい項目に置き換えます。

CosmosItemResponse<T> upsertItem(T item)

現在のコンテナー内の Cosmos 項目をアップサートします。

CosmosItemResponse<T> upsertItem(T item, CosmosItemRequestOptions options)

追加のオプションを指定しながら、アイテム Cosmos 同期項目をアップサートします。

CosmosItemResponse<T> upsertItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)

追加のオプションを指定しながら、アイテム Cosmos 同期項目をアップサートします。

Iterable<CosmosBulkOperationResponse<TContext>> executeBulkOperations(Iterable<CosmosItemOperation> operations)

一括で操作の一覧を実行します。

Iterable<CosmosBulkOperationResponse<TContext>> executeBulkOperations(Iterable<CosmosItemOperation> operations, CosmosBulkExecutionOptions bulkOptions)

一括で操作の一覧を実行します。

CosmosContainerResponse delete()

現在の Cosmos コンテナーを削除します。

CosmosContainerResponse delete(CosmosContainerRequestOptions options)

If-Match などの追加オプションを指定しながら、現在の Cosmos コンテナーを削除します。

CosmosItemResponse<Object> deleteAllItemsByPartitionKey(PartitionKey partitionKey, CosmosItemRequestOptions options)

指定したパーティションキー値を持つコンテナー内のすべての項目を削除します。

CosmosItemResponse<Object> deleteItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)

現在のコンテナー内の項目を削除します。

void enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig, GlobalThroughputControlConfig globalControlConfig)

グローバル制御モードでスループット制御グループを有効にします。

void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig)

ローカル制御モードでスループット制御グループを有効にします。

CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch)

トランザクション バッチを実行します。

CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch, CosmosBatchRequestOptions requestOptions)

トランザクション バッチを実行します。

List<FeedRange> getFeedRanges()

フィード操作の並列化に使用できる の FeedRange 一覧を取得します。

String getId()

現在のコンテナー ID を取得します。

CosmosScripts getScripts()

現在のコンテナーをコンテキストとして使用して Cosmos スクリプトを取得します。

void openConnectionsAndInitCaches()

非推奨

現在の読み取りリージョンのキャッシュと接続をウォームアップして、コンテナーを初期化します。

void openConnectionsAndInitCaches(int numProactiveConnectionRegions)

非推奨

指定した no へのキャッシュと接続をウォームアップして、コンテナーを初期化します。

CosmosContainerResponse read()

現在のコンテナーを読み取ります。

CosmosContainerResponse read(CosmosContainerRequestOptions options)

If-Match などの追加のオプションを指定しながら、現在のコンテナーを読み取ります。

ThroughputResponse readThroughput()

現在のコンテナーのスループットを取得します。

CosmosContainerResponse replace(CosmosContainerProperties containerProperties)

現在のコンテナー のプロパティを置き換えます。

CosmosContainerResponse replace(CosmosContainerProperties containerProperties, CosmosContainerRequestOptions options)

If-Match などの追加オプションを指定しながら、現在のコンテナーのプロパティを置き換えます。

ThroughputResponse replaceThroughput(ThroughputProperties throughputProperties)

現在のコンテナーのスループットを設定します。

メソッドの継承元: java.lang.Object

メソッドの詳細

createItem

public CosmosItemResponse createItem(T item)

新しい項目を同期的に作成し、それぞれの Cosmos 項目の応答を返します。

Parameters:

item - アイテム

Returns:

Cosmos 項目の応答

createItem

public CosmosItemResponse createItem(T item, CosmosItemRequestOptions options)

新しい項目を同期的に作成し、追加のオプションを指定しながら、それぞれの Cosmos 項目の応答を返します。

パーティション キーの値は、アイテムのコンテンツから自動的に抽出されます。

Parameters:

item - 項目。
options - オプション。

Returns:

cosmos 項目の応答。

createItem

public CosmosItemResponse createItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)

新しい項目を同期的に作成し、追加のオプションを指定しながら、それぞれの Cosmos 項目の応答を返します。

Parameters:

item - 項目。
partitionKey - パーティション キー。
options - オプション。

Returns:

Cosmos 項目の応答。

deleteItem

public CosmosItemResponse deleteItem(T item, CosmosItemRequestOptions options)

現在のコンテナー内の項目を削除します。

Parameters:

item - 削除するアイテム。
options - オプション。

Returns:

Cosmos 項目の応答。

patchItem

public CosmosItemResponse patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, CosmosPatchItemRequestOptions options, Class itemType)

アイテム全体を置き換えることなく、アイテムの特定のプロパティまたはフィールドを変更する部分更新を実行します。

CosmosPatchOperations cosmosPatchOperations = CosmosPatchOperations.create();

 cosmosPatchOperations
     .add("/departure", "SEA")
     .increment("/trips", 1);

 CosmosItemResponse<Passenger> response = cosmosContainer.patchItem(
     passenger.getId(),
     new PartitionKey(passenger.getId()),
     cosmosPatchOperations,
     Passenger.class);

Parameters:

itemId - 項目 ID。
partitionKey - パーティション キー。
cosmosPatchOperations - 参照される Cosmos アイテムに順番に適用される操作の一覧を持つコンテナーを表します。
options - 要求オプション。
itemType - 項目の種類。

Returns:

パッチが適用された項目または例外を含む Cosmos 項目リソース応答。

patchItem

public CosmosItemResponse patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, Class itemType)

アイテム全体を置き換えることなく、アイテムの特定のプロパティまたはフィールドを変更する部分更新を実行します。

CosmosPatchOperations cosmosPatchOperations = CosmosPatchOperations.create();

 cosmosPatchOperations
     .add("/departure", "SEA")
     .increment("/trips", 1);

 CosmosItemResponse<Passenger> response = cosmosContainer.patchItem(
     passenger.getId(),
     new PartitionKey(passenger.getId()),
     cosmosPatchOperations,
     Passenger.class);

Parameters:

itemId - 項目 ID。
partitionKey - パーティション キー。
cosmosPatchOperations - 参照される Cosmos アイテムに順番に適用される操作の一覧を持つコンテナーを表します。
itemType - 項目の種類。

Returns:

パッチが適用された項目または例外を含む Cosmos 項目リソース応答。

queryChangeFeed

public CosmosPagedIterable queryChangeFeed(CosmosChangeFeedRequestOptions options, Class classType)

を使用して、現在のコンテナーの変更フィード内の項目を照会します CosmosChangeFeedRequestOptions

CosmosChangeFeedRequestOptions options = CosmosChangeFeedRequestOptions
     .createForProcessingFromNow(FeedRange.forFullRange())
     .allVersionsAndDeletes();

 Iterable<FeedResponse<Passenger>> feedResponses = cosmosContainer.queryChangeFeed(options, Passenger.class)
     .iterableByPage();
 for (FeedResponse<Passenger> feedResponse : feedResponses) {
     List<Passenger> results = feedResponse.getResults();
     System.out.println(results);
 }

次のページは、前に返されたインスタンスの継続トークンから作成された の CosmosChangeFeedRequestOptions 新しいインスタンスを使用して queryChangeFeed をもう一度呼び出すことによって取得 FeedResponse<T> できます。

Parameters:

options - 変更フィード要求オプション。
classType - クラス型。

Returns:

1 つのフィード応答ページを含む 。CosmosPagedFlux<T>

queryItems

public CosmosPagedIterable queryItems(SqlQuerySpec querySpec, CosmosQueryRequestOptions options, Class classType)

結果を として CosmosPagedIterable<T>返す現在のコンテナー内のクエリ 項目。

CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
 String query = "SELECT * FROM Passenger p WHERE (p.departure = @departure)";
 List<SqlParameter> parameters = Collections.singletonList(new SqlParameter("@departure", "SEA"));
 SqlQuerySpec sqlQuerySpec = new SqlQuerySpec(query, parameters);

 Iterable<FeedResponse<Passenger>> queryResponses = cosmosContainer.queryItems(sqlQuerySpec, options, Passenger.class)
     .iterableByPage();

 for (FeedResponse<Passenger> feedResponse : queryResponses) {
     List<Passenger> results = feedResponse.getResults();
     System.out.println(results);
 }

Parameters:

querySpec - クエリ スペック。
options - オプション。
classType - クラス型。

Returns:

の値を指定します CosmosPagedIterable<T>

queryItems

public CosmosPagedIterable queryItems(String query, CosmosQueryRequestOptions options, Class classType)

結果を として CosmosPagedIterable<T>返す現在のコンテナー内のクエリ 項目。

CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
 String query = "SELECT * FROM Passenger WHERE Passenger.departure IN ('SEA', 'IND')";
 Iterable<FeedResponse<Passenger>> queryResponses = cosmosContainer.queryItems(query, options, Passenger.class)
     .iterableByPage();

 for (FeedResponse<Passenger> feedResponse : queryResponses) {
     List<Passenger> results = feedResponse.getResults();
     System.out.println(results);
 }

Parameters:

query - クエリ。
options - オプション。
classType - クラス型。

Returns:

の値を指定します CosmosPagedIterable<T>

readAllItems

public CosmosPagedIterable readAllItems(PartitionKey partitionKey, CosmosQueryRequestOptions options, Class classType)

結果を として CosmosPagedIterable<T>返す論理パーティションのすべての項目を読み取ります。

CosmosPagedIterable<Passenger> passengers = cosmosContainer
     .readAllItems(new PartitionKey(partitionKey), Passenger.class);

 passengers.forEach(passenger -> {
     System.out.println(passenger);
 });

Parameters:

partitionKey - 読み取る必要があるドキュメントのパーティション キー値
options - フィード オプション。
classType - クラス型。

Returns:

の値を指定します CosmosPagedIterable<T>

readAllItems

public CosmosPagedIterable readAllItems(PartitionKey partitionKey, Class classType)

結果を として CosmosPagedIterable<T>返す論理パーティションのすべての項目を読み取ります。

CosmosPagedIterable<Passenger> passengers = cosmosContainer
     .readAllItems(new PartitionKey(partitionKey), Passenger.class);

 passengers.forEach(passenger -> {
     System.out.println(passenger);
 });

Parameters:

partitionKey - 読み取る必要があるドキュメントのパーティション キー値
classType - クラス型。

Returns:

の値を指定します CosmosPagedIterable<T>

readItem

public CosmosItemResponse readItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options, Class itemType)

追加のオプションを指定しながら、現在のコンテナー内の項目を読み取ります。 この操作は、一意識別子 (ID) とパーティション キーに基づいてコンテナーから 1 つの項目を取得するために使用されます。 readItem 操作は、アイテムの ID とパーティション キー値で構成される一意識別子を使用して、特定のアイテムに直接アクセスします。 この操作は、複雑なクエリを必要とせずに、ID とパーティション キーによって既知の項目を取得する場合に効率的です。

Parameters:

itemId - 項目 ID。
partitionKey - パーティション キー。
options - オプション (省略可能)。
itemType - 項目のクラス型。

Returns:

Cosmos 項目の応答。

readItem

public CosmosItemResponse readItem(String itemId, PartitionKey partitionKey, Class itemType)

現在のコンテナー内の項目を読み取ります。 この操作は、一意識別子 (ID) とパーティション キーに基づいてコンテナーから 1 つの項目を取得するために使用されます。 readItem 操作は、アイテムの ID とパーティション キー値で構成される一意識別子を使用して、特定のアイテムに直接アクセスします。 この操作は、複雑なクエリを必要とせずに、ID とパーティション キーによって既知の項目を取得する場合に効率的です。

// Read an item
 try {
     CosmosItemResponse<Passenger> response = cosmosContainer.readItem(
         passenger.getId(),
         new PartitionKey(passenger.getId()),
         Passenger.class
     );
     Passenger passengerItem = response.getItem();
 } catch (NotFoundException e) {
     // catch exception if item not found
     System.out.printf("Passenger with item id %s not found\n",
         passenger.getId());
 } catch (Exception e) {
     System.out.println(e.getMessage());
 }

 // ...

Parameters:

itemId - 項目 ID。
partitionKey - パーティション キー。
itemType - 項目のクラス型。

Returns:

Cosmos 項目の応答。

readMany

public FeedResponse readMany(List itemIdentityList, Class classType)

多数のドキュメントを読み取ります。 特定の ID とパーティション キーを持つ多くのドキュメントを 1 つの要求で読み取る場合に便利です。 リストのドキュメントがない場合、例外はスローされません。

List<CosmosItemIdentity> itemIdentityList = new ArrayList<>();
 itemIdentityList.add(new CosmosItemIdentity(new PartitionKey(passenger1Id), passenger1Id));
 itemIdentityList.add(new CosmosItemIdentity(new PartitionKey(passenger2Id), passenger2Id));

 FeedResponse<Passenger> passengerFeedResponse = cosmosContainer.readMany(itemIdentityList, Passenger.class);
 for (Passenger passenger : passengerFeedResponse.getResults()) {
     System.out.println(passenger);
 }

Parameters:

itemIdentityList - 読み取る必要がある項目の CosmosItem ID とパーティション キーのタプル
classType - クラス型

Returns:

Cosmos アイテムのフィード応答を持つ Mono

readMany

public FeedResponse readMany(List itemIdentityList, String sessionToken, Class classType)

多数のドキュメントを読み取ります。 特定の ID とパーティション キーを持つ多くのドキュメントを 1 つの要求で読み取る場合に便利です。 リストのドキュメントがない場合、例外はスローされません。

List<CosmosItemIdentity> itemIdentityList = new ArrayList<>();
 itemIdentityList.add(new CosmosItemIdentity(new PartitionKey(passenger1Id), passenger1Id));
 itemIdentityList.add(new CosmosItemIdentity(new PartitionKey(passenger2Id), passenger2Id));

 FeedResponse<Passenger> passengerFeedResponse = cosmosContainer.readMany(itemIdentityList, Passenger.class);
 for (Passenger passenger : passengerFeedResponse.getResults()) {
     System.out.println(passenger);
 }

Parameters:

itemIdentityList - 読み取る必要がある項目の CosmosItem ID とパーティション キーのタプル
sessionToken - オプションのセッション トークン - 特定のセッション トークンなしで読み取りを行うことができる場合は null
classType - クラス型

Returns:

Cosmos アイテムのフィード応答を持つ Mono

replaceItem

public CosmosItemResponse replaceItem(T item, String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)

コンテナー内の既存の項目を新しい項目に置き換えます。 項目の完全な置換が実行され、そのすべてのプロパティが新しい項目のプロパティに置き換えられます。

CosmosItemResponse<Passenger> response = cosmosContainer.replaceItem(
     newPassenger,
     oldPassenger.getId(),
     new PartitionKey(oldPassenger.getId()),
     new CosmosItemRequestOptions());

Parameters:

item - 項目。
itemId - 項目 ID。
partitionKey - パーティション キー。
options - オプション。

Returns:

Cosmos 項目の応答。

upsertItem

public CosmosItemResponse upsertItem(T item)

現在のコンテナー内の Cosmos 項目をアップサートします。

Parameters:

item - 項目。

Returns:

Cosmos 項目の応答。

upsertItem

public CosmosItemResponse upsertItem(T item, CosmosItemRequestOptions options)

追加のオプションを指定しながら、アイテム Cosmos 同期項目をアップサートします。

Parameters:

item - 項目。
options - オプション。

Returns:

Cosmos 項目の応答。

upsertItem

public CosmosItemResponse upsertItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)

追加のオプションを指定しながら、アイテム Cosmos 同期項目をアップサートします。

Parameters:

item - 項目。
partitionKey - partitionKey。
options - オプション。

Returns:

Cosmos 項目の応答。

executeBulkOperations

public Iterable<>> executeBulkOperations(Iterable operations)

一括で操作の一覧を実行します。

Parameters:

operations - このコンテナーによって実行される操作の一覧。

Returns:

Iterable には CosmosBulkOperationResponse<TContext> 操作が含まれており、応答または例外です。 ここで実行できる操作を作成するには、 を使用 CosmosBulkOperationsします。 例: アップサート操作の使用 com.azure.cosmos.models.CosmosBulkOperations#getUpsertItemOperation(Object, PartitionKey) を使用して対応する操作を取得でき、 を使用 getOperation() した getResponse()応答です。 操作が正常に実行された場合、 によって isSuccessStatusCode() 返される値は true になります。 実際の状態を取得するには、 を使用します getStatusCode()。 操作に例外があるかどうかをチェックするには、 を使用getException()して例外を取得します。

executeBulkOperations

public Iterable<>> executeBulkOperations(Iterable operations, CosmosBulkExecutionOptions bulkOptions)

一括で操作の一覧を実行します。

Parameters:

operations - このコンテナーによって実行される操作の一覧。
bulkOptions - コンカレンシー、バッチ処理サイズ、間隔、コンテキストなどの実行に関するオプションを指定する、この一括要求に適用されるオプション。

Returns:

Iterable には CosmosBulkOperationResponse<TContext> 操作が含まれており、応答または例外です。 ここで実行できる操作を作成するには、 を使用 CosmosBulkOperationsします。 例: アップサート操作の使用 com.azure.cosmos.models.CosmosBulkOperations#getUpsertItemOperation(Object, PartitionKey) を使用して対応する操作を取得でき、 を使用 getOperation() した getResponse()応答です。 操作が正常に実行された場合、 によって isSuccessStatusCode() 返される値は true になります。 実際の状態を取得するには、 を使用します getStatusCode()。 操作に例外があるかどうかをチェックするには、 を使用getException()して例外を取得します。

delete

public CosmosContainerResponse delete()

現在の Cosmos コンテナーを削除します。

Returns:

cosmos コンテナーの応答。

delete

public CosmosContainerResponse delete(CosmosContainerRequestOptions options)

If-Match などの追加オプションを指定しながら、現在の Cosmos コンテナーを削除します。

Parameters:

options - オプション。

Returns:

cosmos コンテナーの応答。

deleteAllItemsByPartitionKey

public CosmosItemResponse deleteAllItemsByPartitionKey(PartitionKey partitionKey, CosmosItemRequestOptions options)

指定した partitionKey 値を持つコンテナー内のすべての項目を削除します。 指定した値を使用してコンテナー内のすべての項目を削除する非同期 Cosmos DB バックグラウンド操作を開始します。 非同期 Cosmos DB バックグラウンド操作は、ユーザー RU の割合を使用して実行されます。

Parameters:

partitionKey - パーティション キー。
options - オプション。

Returns:

Cosmos 項目の応答

deleteItem

public CosmosItemResponse deleteItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)

現在のコンテナー内の項目を削除します。

try {
     CosmosItemRequestOptions options = new CosmosItemRequestOptions();
     CosmosItemResponse<Object> deleteItemResponse = cosmosContainer.deleteItem(
         passenger.getId(),
         new PartitionKey(passenger.getId()),
         options
     );
     System.out.println(deleteItemResponse);
 } catch (NotFoundException e) {
     // catch exception if item not found
     System.out.printf("Passenger with item id %s not found\n",
         passenger.getId());
 } catch (Exception e) {
     System.out.println(e.getMessage());
 }

Parameters:

itemId - 項目 ID。
partitionKey - パーティション キー。
options - オプション。

Returns:

Cosmos 項目の応答。

enableGlobalThroughputControlGroup

public void enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig, GlobalThroughputControlConfig globalControlConfig)

グローバル制御モードでスループット制御グループを有効にします。 定義されたスループット制限は、異なるクライアント間で共有されます。

ThroughputControlGroupConfig groupConfig =
     new ThroughputControlGroupConfigBuilder()
         .groupName("localControlGroup")
         .targetThroughputThreshold(0.1)
         .build();

 GlobalThroughputControlConfig globalControlConfig =
     this.client.createGlobalThroughputControlConfigBuilder(database.getId(), container.getId())
         .setControlItemRenewInterval(Duration.ofSeconds(5))
         .setControlItemExpireInterval(Duration.ofSeconds(10))
         .build();

 container.enableGlobalThroughputControlGroup(groupConfig, globalControlConfig);

Parameters:

groupConfig - スループット制御グループの構成については、「」を参照してください GlobalThroughputControlGroup
globalControlConfig - グローバル スループット制御の構成については、「」を参照してください GlobalThroughputControlConfig

enableLocalThroughputControlGroup

public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig)

ローカル制御モードでスループット制御グループを有効にします。

ThroughputControlGroupConfig groupConfig =
     new ThroughputControlGroupConfigBuilder()
         .groupName("localControlGroup")
         .targetThroughputThreshold(0.1)
         .build();

 container.enableLocalThroughputControlGroup(groupConfig);

Parameters:

executeCosmosBatch

public CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch)

トランザクション バッチを実行します。

Parameters:

cosmosBatch - このコンテナーによって実行される操作とパーティション キーの一覧を持つバッチ。

Returns:

トランザクション バッチの実行の詳細を含む TransactionalBatchResponse。

トランザクション バッチが正常に実行された場合、返される応答で によって CosmosBatchResponse#getStatusCode 返される値は 200} に設定されます。

実行中にトランザクション バッチ内の操作が失敗した場合、バッチからの変更はコミットされません。失敗した操作の状態は、例外によってまたは例外によって CosmosBatchResponse#getStatusCode 使用可能になります。 競合、見つからないなどのユーザー エラーが発生した場合に失敗した操作に関する情報を取得するには、応答を列挙できます。 これにより、トランザクション バッチ内の CosmosBatchOperationResult 各操作に対応するインスタンスが、トランザクション バッチに追加された順序で返されます。 トランザクション バッチ内の操作に対応する結果の場合は、 を使用 CosmosBatchOperationResult#getStatusCode して操作の状態にアクセスします。 操作が実行されなかった場合、またはトランザクション バッチ内の別の操作が失敗したために中止された場合、このフィールドの値は 424 になります。バッチが中止された操作の場合、このフィールドの値はエラーの原因を示します。

要求タイムアウト、ゴーン、セッション利用不可、ネットワーク障害などの問題がある場合、またはサービスが何らかの方法で 5xx を返した場合、CosmosBatchResponse を返す代わりに例外がスローされます。

トランザクション バッチが成功したことを確認するには、返された応答で を使用 CosmosBatchResponse#isSuccessStatusCode します。

executeCosmosBatch

public CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch, CosmosBatchRequestOptions requestOptions)

トランザクション バッチを実行します。

Parameters:

cosmosBatch - このコンテナーによって実行される操作とパーティション キーの一覧を持つバッチ。
requestOptions - バッチ要求に特に適用されるオプション。

Returns:

トランザクション バッチの実行の詳細を含む CosmosBatchResponse。

トランザクション バッチが正常に実行された場合、返される応答で によって CosmosBatchResponse#getStatusCode 返される値は 200} に設定されます。

実行中にトランザクション バッチ内の操作が失敗した場合、バッチからの変更はコミットされません。失敗した操作の状態は、例外によってまたは例外によって CosmosBatchResponse#getStatusCode 使用可能になります。 競合、見つからないなどのユーザー エラーが発生した場合に失敗した操作に関する情報を取得するには、応答を列挙できます。 これにより、トランザクション バッチ内の CosmosBatchOperationResult 各操作に対応するインスタンスが、トランザクション バッチに追加された順序で返されます。 トランザクション バッチ内の操作に対応する結果の場合は、 を使用 CosmosBatchOperationResult#getStatusCode して操作の状態にアクセスします。 操作が実行されなかった場合、またはトランザクション バッチ内の別の操作が失敗したために中止された場合、このフィールドの値は 424 になります。バッチが中止された操作の場合、このフィールドの値はエラーの原因を示します。

要求タイムアウト、ゴーン、セッション利用不可、ネットワーク障害などの問題がある場合、またはサービスが何らかの方法で 5xx を返した場合、CosmosBatchResponse を返す代わりに例外がスローされます。

トランザクション バッチが成功したことを確認するには、返された応答で を使用 CosmosBatchResponse#isSuccessStatusCode します。

getFeedRanges

public List getFeedRanges()

フィード操作の並列化に使用できる の FeedRange 一覧を取得します。

List<FeedRange> feedRanges = cosmosContainer.getFeedRanges();
 for (FeedRange feedRange : feedRanges) {
     System.out.println("Feed range: " + feedRange);
 }

Returns:

変更不可能な の一覧 FeedRange

getId

public String getId()

現在のコンテナー ID を取得します。

Returns:

コンテナー ID。

getScripts

public CosmosScripts getScripts()

現在のコンテナーをコンテキストとして使用して Cosmos スクリプトを取得します。

Returns:

Cosmos 同期スクリプト。

openConnectionsAndInitCaches

@Deprecated
public void openConnectionsAndInitCaches()

非推奨

現在の読み取りリージョンのキャッシュと接続をウォームアップして、コンテナーを初期化します。

注: この API は、ワークロードの前にアプリケーションの初期化中に 1 回だけ呼び出すのが理想的です。 一時的なエラーが発生した場合、呼び出し元はエラーを使用し、通常のワークロードを続行する必要があります。

openConnectionsAndInitCaches

@Deprecated
public void openConnectionsAndInitCaches(int numProactiveConnectionRegions)

非推奨

事前接続リージョンの指定された no へのキャッシュと接続をウォームアップして、コンテナーを初期化します。 プロアクティブ接続リージョンの詳細については、次を参照してください。 getProactiveConnectionRegionsCount()

注: この API は、ワークロードの前にアプリケーションの初期化中に 1 回だけ呼び出すのが理想的です。 一時的なエラーが発生した場合、呼び出し元はエラーを使用し、通常のワークロードを続行する必要があります。

Parameters:

numProactiveConnectionRegions - リージョンの優先リストからプロアクティブに接続するリージョンがない

read

public CosmosContainerResponse read()

現在のコンテナーを読み取ります。

Returns:

読み取りコンテナーを使用した Cosmos コンテナー応答。

read

public CosmosContainerResponse read(CosmosContainerRequestOptions options)

If-Match などの追加のオプションを指定しながら、現在のコンテナーを読み取ります。

Parameters:

options - オプション。

Returns:

Cosmos コンテナーの応答。

readThroughput

public ThroughputResponse readThroughput()

現在のコンテナーのスループットを取得します。

try {
     ThroughputResponse throughputResponse = cosmosContainer.readThroughput();
     System.out.println(throughputResponse);
 } catch (CosmosException ce) {
     ce.printStackTrace();
 } catch (Exception e) {
     e.printStackTrace();
 }

Returns:

スループット応答。

replace

public CosmosContainerResponse replace(CosmosContainerProperties containerProperties)

現在のコンテナー のプロパティを置き換えます。

Parameters:

containerProperties - コンテナーのプロパティ。

Returns:

cosmos コンテナーの応答。

replace

public CosmosContainerResponse replace(CosmosContainerProperties containerProperties, CosmosContainerRequestOptions options)

If-Match などの追加オプションを指定しながら、現在のコンテナーのプロパティを置き換えます。

Parameters:

containerProperties - コンテナーのプロパティ。
options - オプション。

Returns:

cosmos コンテナーの応答。

replaceThroughput

public ThroughputResponse replaceThroughput(ThroughputProperties throughputProperties)

現在のコンテナーのスループットを設定します。

ThroughputProperties throughputProperties =
     ThroughputProperties.createAutoscaledThroughput(1000);
 try {
     ThroughputResponse throughputResponse =
         cosmosContainer.replaceThroughput(throughputProperties);
     System.out.println(throughputResponse);
 } catch (CosmosException ce) {
     ce.printStackTrace();
 } catch (Exception e) {
     e.printStackTrace();
 }

Parameters:

throughputProperties - スループット プロパティ (省略可能)。

Returns:

スループット応答。

適用対象