List of usage examples for com.amazonaws.services.dynamodbv2.document UpdateItemOutcome getItem
public Item getItem()
From source file:com.nodestone.ksum.RecordProcessor.java
License:Open Source License
/** * Update DynamoDB record://www. j a v a 2 s. c o m * - updating updates count * - updating total sum */ private void updateRecord(RawData rawData) { UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("CustomerId", rawData.custId) .withUpdateExpression("set TotalSum = TotalSum + :val, Updates = Updates + :inc") .withValueMap( new ValueMap().withNumber(":val", Integer.parseInt(rawData.value)).withNumber(":inc", 1)) .withReturnValues(ReturnValue.UPDATED_NEW); try { UpdateItemOutcome outcome = this.dbTable.updateItem(updateItemSpec); LOG.info("UpdateItem succeeded:\n" + outcome.getItem().toJSONPretty()); } catch (Exception e) { LOG.info("Update failed with exception:"); LOG.info(e.getMessage()); } }
From source file:io.ignitr.dispatchr.manager.core.data.ClientRepository.java
License:Apache License
/** * * @param newClient/* w w w . ja v a 2 s. c o m*/ * @return */ public Observable<Client> update(Client newClient) { return findOne(newClient.getClientId()).last().map(oldClient -> { Table clientTable = dynamoDB.getTable(CLIENT_TABLE_NAME); UpdateItemOutcome outcome = clientTable .updateItem(new UpdateItemSpec().withPrimaryKey("clientId", oldClient.getClientId()) .withAttributeUpdate(new AttributeUpdate("ownerName").put(newClient.getOwnerName())) .withAttributeUpdate(new AttributeUpdate("ownerEmail").put(newClient.getOwnerEmail()))); Item item = outcome.getItem(); return convertFromItem(item); }); }
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 ava 2s. 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); } }