Documenta le differenze delle API tra la versione 1 e la versione 2 di AWS SDK per Java - AWS SDK for Java 2.x

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Documenta le differenze delle API tra la versione 1 e la versione 2 di AWS SDK per Java

L'API Document supporta l'utilizzo di documenti in stile JSON come elementi singoli in una tabella DynamoDB. L'API Document V1 ha un'API corrispondente nella V2, ma invece di utilizzare un client separato per l'API dei documenti come nella V1, la V2 incorpora le funzionalità dell'API dei documenti nel client avanzato DynamoDB.

In V1, la Itemclasse rappresenta un record non strutturato da una tabella DynamoDB. In V2, un record non strutturato è rappresentato da un'istanza della classe. EnhancedDocument Nota che le chiavi primarie sono definite nello schema della tabella per V2 e sull'elemento stesso in V1.

La tabella seguente confronta le differenze tra il Documento APIs in V1 e V2.

Caso d'uso V1 V2
Crea un client per documenti
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.
Fai riferimento a una tabella
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
Converti una struttura JSON per usarla con l'API Document
// 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());
Inserisci JSON
documentTable.putItem(item)
documentTable.putItem(document);
Leggi JSON
GetItemOutcome outcome = //Get item. String jsonPerson = outcome.getItem().toJSON();
String jsonPerson = documentTable.getItem(Key.builder() .partitionValue(50).build()) .fromJson();

Riferimento all'API e guide per il documento APIs