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

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

Introduction

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

Prototype

public PutItemExpressionSpec buildForPut() 

Source Link

Document

Returns an expression specification for use in a PutItem request to DynamoDB.

Usage

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  w  w w.j a v a2  s.  com*/
    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;
}