のバージョン 1 とバージョン 2 の API の違いを文書化する AWS SDK for Java - AWS SDK for Java 2.x

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

のバージョン 1 とバージョン 2 の API の違いを文書化する AWS SDK for Java

ドキュメント API は、DynamoDB テーブルでの単一の項目としての JSON 形式のドキュメントの使用をサポートしています。V1 ドキュメント API には V2 に対応する API がありますが、V1, V2 には DynamoDB 拡張クライアントにドキュメント API 機能が組み込まれています。

V1 では、 Item クラスは DynamoDB テーブルからの非構造化レコードを表します。V2 では、非構造化レコードは EnhancedDocumentクラスのインスタンスによって表されます。プライマリキーは V2 のテーブルスキーマと V1 の項目自体で定義されていることに注意してください。

次の表は、V1 と V2 のドキュメント APIsしたものです。

ユースケース V1 V2
Create a document client
AmazonDynamoDB client = ... //Create a client. DynamoDB documentClient = new DynamoDB(client);
// The V2 Document API uses the same DynamoDbEnhancedClient // that is used for mapping POJOs. DynamoDbClient standardClient = ... //Create a standard client. DynamoDbEnhancedClient enhancedClient = ... // Create an enhanced client.
Reference a table
Table documentTable = docClient.documentClient("Person");
DynamoDbTable<EnhancedDocument> documentTable = enhancedClient.table("Person", TableSchema.documentSchemaBuilder() .addIndexPartitionKey(TableMetadata.primaryIndexName(),"id", AttributeValueType.S) .attributeConverterProviders(AttributeConverterProvider.defaultProvider()) .build());
Work with semi-structured data
Put item
Item item = new Item() .withPrimaryKey("id", 50) .withString("firstName", "Shirley"); PutItemOutcome outcome = documentTable.putItem(item);
EnhancedDocument personDocument = EnhancedDocument.builder() .putNumber("id", 50) .putString("firstName", "Shirley") .build(); documentTable.putItem(personDocument);
Get item
GetItemOutcome outcome = documentTable.getItemOutcome( "id", 50); Item personDocFromDb = outcome.getItem(); String firstName = personDocFromDb.getString("firstName");
EnhancedDocument personDocFromDb = documentTable .getItem(Key.builder() .partitionValue(50) .build()); String firstName = personDocFromDb.getString("firstName");
Work with JSON items
Convert a JSON structure to use it with the Document API
// The 'jsonPerson' identifier is a JSON string. Item item = new Item().fromJSON(jsonPerson);
// The 'jsonPerson' identifier is a JSON string. EnhancedDocument document = EnhancedDocument.builder() .json(jsonPerson).build());
Put JSON
documentTable.putItem(item)
documentTable.putItem(document);
Read JSON
GetItemOutcome outcome = //Get item. String jsonPerson = outcome.getItem().toJSON();
String jsonPerson = documentTable.getItem(Key.builder() .partitionValue(50).build()) .fromJson();

ドキュメント API の APIsリファレンスとガイド

V1 V2
API リファレンス API リファレンス API リファレンス
ドキュメントガイド Amazon DynamoDB デベロッパーガイド 拡張ドキュメント API (このガイド)