List of usage examples for com.amazonaws.services.dynamodbv2.xspec ExpressionSpecBuilder withCondition
public ExpressionSpecBuilder withCondition(Condition condition)
From source file:com.github.fge.jsonpatch.RemoveOperation.java
License:LGPL
@Override public void applyToBuilder(ExpressionSpecBuilder builder) { String attributePath = pathGenerator.apply(path); builder.addUpdate(ExpressionSpecBuilder.remove(attributePath)); //because it is an error to remove a path that does not exist //add an attribute_exists() condition builder.withCondition(ExpressionSpecBuilder.attribute_exists(pathGenerator.apply(path))); }
From source file:com.github.fge.jsonpatch.ReplaceOperation.java
License:LGPL
@Override public void applyToBuilder(ExpressionSpecBuilder builder) { //add the set operation super.applyToBuilder(builder); //because it is an error to replace a path that does not exist //add an attribute_exists() condition builder.withCondition(ExpressionSpecBuilder.attribute_exists(pathGenerator.apply(path))); }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
@Override public E update(K key, JsonPatch patch, boolean increment, long version) { final PrimaryKey pk = createKeys(key); Preconditions.checkNotNull(patch, "patch must not be null"); Preconditions.checkArgument(version >= -1); ExpressionSpecBuilder builder = patch.get(); //add a condition on item existence builder.withCondition(ExpressionSpecBuilder.attribute_exists(hashKeyName)); //add update expression for incrementing the version if (increment && versionProperty != null) { builder.addUpdate(ExpressionSpecBuilder.N(versionProperty) .set(ExpressionSpecBuilder.N(versionProperty).plus(1L))); }/* w w w.j a v a 2 s . c om*/ //add version condition if (version >= 0) { Preconditions.checkState(versionProperty != null); builder.withCondition(ExpressionSpecBuilder.N(versionProperty).eq(version)); } UpdateItemExpressionSpec spec = builder.buildForUpdate(); Preconditions.checkArgument(false == Strings.isNullOrEmpty(spec.getUpdateExpression()), "patch may not be empty"); // TODO add mechanism to JSON patch to allow iterating over list of ops try { UpdateItemOutcome updateItemOutcome = table.updateItem(new UpdateItemSpec().withExpressionSpec(spec) .withPrimaryKey(pk).withReturnValues(ReturnValue.ALL_NEW)); return convertItemToDomain(updateItemOutcome.getItem()); } catch (AmazonClientException e) { throw processUpdateItemException(key, e); } }
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 . jav 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; }