List of usage examples for com.amazonaws.services.dynamodbv2.xspec ExpressionSpecBuilder addUpdate
public ExpressionSpecBuilder addUpdate(UpdateAction updateAction)
From source file:com.github.fge.jsonpatch.CopyOperation.java
License:LGPL
@Override public void applyToBuilder(ExpressionSpecBuilder builder) { String copyPath = pathGenerator.apply(from); String setPath = pathGenerator.apply(path); //set the attribute in the path location builder.addUpdate(new PathSetAction(ExpressionSpecBuilder.attribute(setPath), ExpressionSpecBuilder.attribute(copyPath))); }
From source file:com.github.fge.jsonpatch.MoveOperation.java
License:LGPL
@Override public void applyToBuilder(ExpressionSpecBuilder builder) { String removePath = pathGenerator.apply(from); String setPath = pathGenerator.apply(path); //remove the attribute in the from location builder.addUpdate(ExpressionSpecBuilder.remove(removePath)); //set the attribute in the path location builder.addUpdate(new PathSetAction(ExpressionSpecBuilder.attribute(setPath), ExpressionSpecBuilder.attribute(removePath))); }
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:/*from w w w.j a va 2 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: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: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))); }/*from www. j a v a 2 s . c o m*/ //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); } }