use of software.amazon.awssdk.enhanced.dynamodb.Key in project aws-doc-sdk-examples by awsdocs.
the class EnhancedGetItem method getItem.
// snippet-start:[dynamodb.java2.mapping.getitem.main]
public static String getItem(DynamoDbEnhancedClient enhancedClient) {
try {
// Create a DynamoDbTable object
DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class));
// Create a KEY object
Key key = Key.builder().partitionValue("id146").build();
// Get the item by using the key
Customer result = mappedTable.getItem(r -> r.key(key));
return "The email value is " + result.getEmail();
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.enhanced.dynamodb.Key in project aws-doc-sdk-examples by awsdocs.
the class EnhancedModifyItem method modifyItem.
// snippet-start:[dynamodb.java2.mapping.moditem.main]
public static String modifyItem(DynamoDbEnhancedClient enhancedClient, String keyVal, String email) {
try {
// Create a DynamoDbTable object
DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class));
// Create a KEY object
Key key = Key.builder().partitionValue(keyVal).build();
// Get the item by using the key and update the email value.
Customer customerRec = mappedTable.getItem(r -> r.key(key));
customerRec.setEmail(email);
mappedTable.updateItem(customerRec);
return customerRec.getEmail();
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.enhanced.dynamodb.Key in project ff4j by ff4j.
the class DynamoDBClient method getItem.
public STORE getItem(String id) {
Util.assertHasLength(id);
Key key = Key.builder().partitionValue(id).build();
STORE item = table.getItem(r -> r.key(key));
if (item == null) {
throw notFoundException(id);
}
return item;
}
Aggregations