Search in sources :

Example 21 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap 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)19 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)19 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)12 Item (com.amazonaws.services.dynamodbv2.document.Item)11 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)6 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)6 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)6 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)6 NameMap (com.amazonaws.services.dynamodbv2.document.utils.NameMap)5 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 Index (com.amazonaws.services.dynamodbv2.document.Index)2 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)2 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 HashMap (java.util.HashMap)2 DeleteItemOutcome (com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome)1 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)1