Search in sources :

Example 1 with Key

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 "";
}
Also used : DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) DynamoDbSortKey(software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey) Key(software.amazon.awssdk.enhanced.dynamodb.Key) DynamoDbPartitionKey(software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey)

Example 2 with Key

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 "";
}
Also used : DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) DynamoDbSortKey(software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey) Key(software.amazon.awssdk.enhanced.dynamodb.Key) DynamoDbPartitionKey(software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey)

Example 3 with Key

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;
}
Also used : Key(software.amazon.awssdk.enhanced.dynamodb.Key)

Aggregations

Key (software.amazon.awssdk.enhanced.dynamodb.Key)3 DynamoDbPartitionKey (software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey)2 DynamoDbSortKey (software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey)2 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)2