Example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB updateItem

List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDB updateItem

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB updateItem.

Prototype

UpdateItemResult updateItem(UpdateItemRequest updateItemRequest);

Source Link

Document

Edits an existing item's attributes, or adds a new item to the table if it does not already exist.

Usage

From source file:com.netflix.config.sources.DynamoDbIntegrationTestHelper.java

License:Apache License

static void updateValues(AmazonDynamoDB dbClient, String tableName) {

    Map<String, AttributeValue> key1 = new HashMap<String, AttributeValue>(1);
    key1.put("test1", new AttributeValue().withS("HASH"));

    Map<String, AttributeValueUpdate> item1 = new HashMap<String, AttributeValueUpdate>(1);
    item1.put(DynamoDbConfigurationSource.defaultValueAttribute, new AttributeValueUpdate()
            .withAction(AttributeAction.PUT).withValue(new AttributeValue().withS("vala")));

    dbClient.updateItem(
            new UpdateItemRequest().withTableName(tableName).withKey(key1).withAttributeUpdates(item1));

    Map<String, AttributeValue> key2 = new HashMap<String, AttributeValue>(1);
    key2.put("test2", new AttributeValue().withS("HASH"));

    HashMap<String, AttributeValueUpdate> item2 = new HashMap<String, AttributeValueUpdate>(1);
    item2.put(DynamoDbConfigurationSource.defaultValueAttribute, new AttributeValueUpdate()
            .withAction(AttributeAction.PUT).withValue(new AttributeValue().withS("valb")));

    dbClient.updateItem(//from w ww . j av a  2s.  c o  m
            new UpdateItemRequest().withTableName(tableName).withKey(key2).withAttributeUpdates(item2));

    Map<String, AttributeValue> key3 = new HashMap<String, AttributeValue>(1);
    key3.put("test3", new AttributeValue().withS("HASH"));

    HashMap<String, AttributeValueUpdate> item3 = new HashMap<String, AttributeValueUpdate>(1);
    item3.put(DynamoDbConfigurationSource.defaultValueAttribute, new AttributeValueUpdate()
            .withAction(AttributeAction.PUT).withValue(new AttributeValue().withS("valc")));

    dbClient.updateItem(
            new UpdateItemRequest().withTableName(tableName).withKey(key3).withAttributeUpdates(item3));
}

From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java

License:Open Source License

public static void updateItem(AmazonDynamoDB dynamoDBClient, String tableName, String id, String val) {
    java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("Id", new AttributeValue().withN(id));

    Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
    AttributeValueUpdate update = new AttributeValueUpdate().withAction(AttributeAction.PUT)
            .withValue(new AttributeValue().withS(val));
    attributeUpdates.put("attribute-2", update);

    UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(key)
            .withAttributeUpdates(attributeUpdates);
    dynamoDBClient.updateItem(updateItemRequest);
}