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

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

Introduction

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

Prototype

public ValueMap withString(String key, 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;//from  w  w w  . ja va2 s .  co  m
    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);
}

From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java

License:Eclipse Distribution License

public Observable<Boolean> compareAndPut(String repositoryName, Ref oldRef, Ref newRef) {
    boolean isSymbolic = newRef.isSymbolic();
    boolean isPeeled = newRef.isPeeled();
    String target = newRef.isSymbolic() ? newRef.getTarget().getName() : newRef.getObjectId().name();

    logger.debug("Saving ref {} -> {} in repository {}", newRef.getName(), target, repositoryName);

    UpdateItemSpec updateSpec = new UpdateItemSpec()
            .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName),
                    new KeyAttribute(NAME_ATTRIBUTE, newRef.getName())));

    StringBuilder updateExpression = new StringBuilder(COMPARE_AND_PUT_EXPRESSION);
    ValueMap valueMap = new ValueMap().withString(":target", target).withBoolean(":isSymbolic", isSymbolic)
            .withBoolean(":isPeeled", isPeeled);

    if (isPeeled && newRef.getPeeledObjectId() != null) {
        updateExpression.append(", ");
        updateExpression.append(PEELED_TARGET_ATTRIBUTE);
        updateExpression.append(" = :peeledTarget");
        valueMap = valueMap.withString(":peeledTarget", newRef.getPeeledObjectId().name());
    }/* w  w  w.  ja va 2  s.c om*/

    if (oldRef != null && oldRef.getStorage() != Ref.Storage.NEW) {
        String expected = oldRef.isSymbolic() ? oldRef.getTarget().getName() : oldRef.getObjectId().name();
        updateSpec = updateSpec.withConditionExpression("#target = :expected")
                .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE));
        valueMap = valueMap.withString(":expected", expected);
    }

    updateSpec = updateSpec.withUpdateExpression(updateExpression.toString()).withValueMap(valueMap);

    return configuration.getDynamoClient()
            .updateItem(configuration.getRefsTableName(), updateSpec, tableCreator).map(v -> true)
            .doOnNext(v -> logger.debug("Saved ref {} in repository {}", newRef.getName(), repositoryName))
            .onErrorReturn(t -> false);
}