AWS SDK for Java의 버전 1과 버전 2 간의 문서 API 차이점 - AWS SDK for Java 2.x

AWS SDK for Java의 버전 1과 버전 2 간의 문서 API 차이점

문서 API는 DynamoDB 테이블에서 JSON 형식 문서를 단일 항목으로 사용할 수 있도록 지원합니다. V1 문서 API는 V2에 해당 API가 있지만, V1처럼 문서 API에 별도의 클라이언트를 사용하는 대신, V2에서는 DynamoDB 향상된 클라이언트에 문서 API 기능을 통합했습니다.

V1에서 Item 클래스는 DynamoDB 테이블의 비정형 레코드를 나타냅니다. V2에서 비정형 레코드는 EnhancedDocument 클래스의 인스턴스로 표시됩니다. 프라이머리 키는 V2의 테이블 스키마와 V1의 항목 자체에 정의되어 있습니다.

아래 테이블에서는 V1과 V2의 문서 API를 비교합니다.

사용 사례 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에 대한 API 참조 및 안내서

V1 V2
API 참조 API 참조 API 참조
문서 안내서 Amazon DynamoDB 개발자 안내서 향상된 문서 API(이 안내서)