Example usage for com.amazonaws.services.dynamodbv2.xspec ExpressionSpecBuilder S

List of usage examples for com.amazonaws.services.dynamodbv2.xspec ExpressionSpecBuilder S

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.xspec ExpressionSpecBuilder S.

Prototype

public static S S(String path) 

Source Link

Document

Creates a path operand that refers to a <a href= "http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html" >string attribute</a> for the purpose of building expressions.

Usage

From source file:com.github.fge.jsonpatch.PathValueOperation.java

License:LGPL

@Override
public void applyToBuilder(ExpressionSpecBuilder builder) {
    String attributePath = pathGenerator.apply(path);
    JsonNodeType type = value.getNodeType();
    switch (type) {
    case NUMBER:/* w ww  . j a v a2 s .c o m*/
        builder.addUpdate(ExpressionSpecBuilder.N(attributePath).set(value.numberValue()));
        break;

    case STRING:
        builder.addUpdate(ExpressionSpecBuilder.S(attributePath).set(value.textValue()));
        break;

    case BOOLEAN:
        builder.addUpdate(ExpressionSpecBuilder.BOOL(attributePath).set(value.booleanValue()));
        break;

    case NULL:
        builder.addUpdate(ExpressionSpecBuilder.NULL(attributePath).set());
        break;

    case ARRAY:
        if (value.iterator().hasNext() == false) {
            builder.addUpdate(ExpressionSpecBuilder.L(attributePath).set(Collections.emptyList()));
        } else {
            JsonNode repNode = value.iterator().next();
            if (repNode.isNumber()) {
                builder.addUpdate(ExpressionSpecBuilder.NS(attributePath).set(convertNumberList(value)));
            } else if (repNode.isTextual()) {
                builder.addUpdate(ExpressionSpecBuilder.SS(attributePath).set(convertStringList(value)));
            } else {
                throw new UnsupportedOperationException("Not implemented yet: " + repNode.getNodeType());
            }
        }
        break;

    case OBJECT:
        Map<String, ?> m = toMap(value);
        builder.addUpdate(ExpressionSpecBuilder.M(attributePath).set(m));
        break;

    default:
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Not implemented yet: " + type);
    }
}

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

License:Open Source License

@Override
public <S extends E> S update(S domain, VersionCondition condition) {
    Preconditions.checkNotNull(domain, "domain must not be null");
    final Item domainItem = convertDomainToItem(domain);
    Preconditions.checkArgument(domainItem.hasAttribute(hashKeyName),
            "hash key must be set in domain object when updating: " + hashKeyName);

    ExpressionSpecBuilder builder = new ExpressionSpecBuilder();
    builder.withCondition(ExpressionSpecBuilder.S(hashKeyName).exists());
    if (condition != null) {
        Preconditions.checkState(versionProperty != null);
        builder.withCondition(ExpressionSpecBuilder.N(versionProperty).eq(condition.getVersion()));
    }/*from   ww  w .j a  v a 2  s . c  o  m*/
    PutItemExpressionSpec xSpec = builder.buildForPut();
    PutItemSpec spec = new PutItemSpec().withItem(domainItem).withExpressionSpec(xSpec);
    try {
        table.putItem(spec);
    } catch (AmazonClientException e) {
        throw processUpdateItemException(getId(domain), e);
    }
    // PutItem does not accept ReturnValue.ALL_NEW
    return domain;
}