Search in sources :

Example 6 with NameMap

use of com.amazonaws.services.dynamodbv2.document.utils.NameMap in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIItemCRUDExample method updateAddNewAttribute.

private static void updateAddNewAttribute() {
    Table table = dynamoDB.getTable(tableName);
    try {
        UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("Id", 121).withUpdateExpression("set #na = :val1").withNameMap(new NameMap().with("#na", "NewAttribute")).withValueMap(new ValueMap().withString(":val1", "Some value")).withReturnValues(ReturnValue.ALL_NEW);
        UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
        // Check the response.
        System.out.println("Printing item after adding new attribute...");
        System.out.println(outcome.getItem().toJSONPretty());
    } catch (Exception e) {
        System.err.println("Failed to add new attribute in " + tableName);
        System.err.println(e.getMessage());
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) UpdateItemOutcome(com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome) NameMap(com.amazonaws.services.dynamodbv2.document.utils.NameMap) IOException(java.io.IOException)

Aggregations

Table (com.amazonaws.services.dynamodbv2.document.Table)6 NameMap (com.amazonaws.services.dynamodbv2.document.utils.NameMap)5 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)5 IOException (java.io.IOException)4 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)2 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)2 Item (com.amazonaws.services.dynamodbv2.document.Item)2 DeleteItemOutcome (com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome)1 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)1 ScanOutcome (com.amazonaws.services.dynamodbv2.document.ScanOutcome)1 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)1 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)1 ScanSpec (com.amazonaws.services.dynamodbv2.document.spec.ScanSpec)1 HashMap (java.util.HashMap)1