Example usage for com.amazonaws.services.dynamodbv2.document.utils ValueMap withMap

List of usage examples for com.amazonaws.services.dynamodbv2.document.utils ValueMap withMap

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document.utils ValueMap withMap.

Prototype

public ValueMap withMap(String key, Map<String, ?> val) 

Source Link

Document

Sets the value of the specified key in the current ValueMap to the given value.

Usage

From source file:com.exorath.service.lobbymsg.impl.DynamoDBService.java

License:Apache License

public static UpdateItemSpec getUpdateItemSpec(String gameId, Message message) {
    String updateExpression;//  w  w w  .  j  a  va  2  s.c  om
    ValueMap valueMap = new ValueMap();
    if (message.getMsg() == null)
        updateExpression = "REMOVE " + MSGS_FIELD + "." + gameId;
    else {
        updateExpression = "SET " + MSGS_FIELD + "." + gameId + "=:msgMap";
        ValueMap msgMap = new ValueMap().withString(MSG_FIELD, message.getMsg());
        if (message.getFormat() != null)
            msgMap.withString(FORMAT_FIELD, message.getFormat());
        valueMap.withMap(":msgMap", msgMap);
    }

    if (valueMap.isEmpty())
        valueMap = null;
    System.out.println(updateExpression);
    return new UpdateItemSpec().withPrimaryKey(getPrimaryKey()).withUpdateExpression(updateExpression)
            .withValueMap(valueMap);
}