List of usage examples for com.amazonaws.services.dynamodbv2.model UpdateItemResult getAttributes
public java.util.Map<String, AttributeValue> getAttributes()
A map of attribute values as they appear before or after the UpdateItem
operation, as determined by the ReturnValues
parameter.
From source file:com.amazon.janusgraph.diskstorage.dynamodb.mutation.SingleUpdateWithCleanupWorker.java
License:Open Source License
@Override public Void call() throws BackendException { final UpdateItem updateBackoff = new UpdateItem(updateItemRequest, dynamoDbDelegate); final UpdateItemResult result = updateBackoff.runWithBackoff(); final Map<String, AttributeValue> item = result.getAttributes(); if (item == null) { // bail/*from www .j av a2 s . co m*/ return null; } // If the record has no Titan columns left after deletions occur, then just delete the record if (item.containsKey(Constants.JANUSGRAPH_HASH_KEY) && item.size() == ATTRIBUTES_IN_EMPTY_SINGLE_ITEM) { final DeleteItem deleteBackoff = new DeleteItem(new DeleteItemRequest() .withTableName(updateItemRequest.getTableName()).withKey(updateItemRequest.getKey()), dynamoDbDelegate); deleteBackoff.runWithBackoff(); } // void return null; }
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.AbstractDynamoDbTemplate.java
License:Apache License
@Override public GeneratedKeyHolder generateKeys(final SequenceKeyGenerator sequenceKeyGenerator) { final String sequenceName = sequenceKeyGenerator.sequenceName(); if (!sequenceConfigurations.contains(sequenceName)) { throw new IllegalStateException("Unsupported sequence: " + sequenceName); }//from ww w . j a v a 2 s .co m final Map<String, AttributeValue> key = new HashMap<>(); key.put(SEQUENCE_NAME_ATTRIBUTE, new AttributeValue(sequenceName)); final AttributeValueUpdate attributeValueUpdate = new AttributeValueUpdate().withAction("ADD") .withValue(new AttributeValue().withN(String.valueOf(sequenceKeyGenerator.keyCount()))); final Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<>(); attributeUpdates.put(SEQUENCE_CURRENT_VALUE_ATTRIBUTE, attributeValueUpdate); final String tableName = databaseSchemaHolder.schemaName() + "-" + SEQUENCE_TABLE_NAME; final UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(key) .withAttributeUpdates(attributeUpdates).withReturnValues("UPDATED_NEW"); final UpdateItemResult updateItemResult; try { updateItemResult = amazonDynamoDbClient.updateItem(updateItemRequest); } catch (final AmazonServiceException e) { throw new PersistenceResourceFailureException( "Failure while attempting DynamoDb Update (generate keys)", e); } final Map<String, AttributeValue> attributes = updateItemResult.getAttributes(); final AttributeValue currentAttributeValue = attributes.get(SEQUENCE_CURRENT_VALUE_ATTRIBUTE); final Long currentValue = Long.valueOf(currentAttributeValue.getN()); final Collection<Long> keys = new ArrayList<>(); for (long i = currentValue - sequenceKeyGenerator.keyCount(); i < currentValue; i++) { keys.add(i + 1); } return new GeneratedKeyHolder(keys); }
From source file:com.rapid7.diskstorage.dynamodb.mutation.SingleUpdateWithCleanupWorker.java
License:Open Source License
@Override public Void call() throws BackendException { ExponentialBackoff.UpdateItem updateBackoff = new ExponentialBackoff.UpdateItem(updateItemRequest, dynamoDBDelegate);/* w w w. j a v a 2 s.c om*/ UpdateItemResult result = updateBackoff.runWithBackoff(); final Map<String, AttributeValue> item = result.getAttributes(); if (item == null) { // bail return null; } // If the record has no Titan columns left after deletions occur, then just delete the record if (item.containsKey(Constants.TITAN_HASH_KEY) && item.size() == ATTRIBUTES_IN_EMPTY_SINGLE_ITEM) { ExponentialBackoff.DeleteItem deleteBackoff = new ExponentialBackoff.DeleteItem(new DeleteItemRequest() .withTableName(updateItemRequest.getTableName()).withKey(updateItemRequest.getKey()), dynamoDBDelegate); deleteBackoff.runWithBackoff(); } // void return null; }
From source file:org.iternine.jeppetto.dao.dynamodb.DynamoDBQueryModelDAO.java
License:Apache License
private T updateItem(Map<String, AttributeValue> key, UpdateExpressionBuilder updateExpressionBuilder, ConditionExpressionBuilder conditionExpressionBuilder, ResultFromUpdate resultFromUpdate) { try {//from ww w.j a va2s . c o m UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(key) .withUpdateExpression(updateExpressionBuilder.getExpression()); Map<String, AttributeValue> expressionAttributeValues; Map<String, String> expressionAttributeNames; if (conditionExpressionBuilder == null) { expressionAttributeValues = updateExpressionBuilder.getExpressionAttributeValues(); expressionAttributeNames = updateExpressionBuilder.getExpressionAttributeNames(); } else { expressionAttributeValues = new LinkedHashMap<String, AttributeValue>(); expressionAttributeNames = new LinkedHashMap<String, String>(); expressionAttributeValues.putAll(updateExpressionBuilder.getExpressionAttributeValues()); expressionAttributeNames.putAll(updateExpressionBuilder.getExpressionAttributeNames()); expressionAttributeValues.putAll(conditionExpressionBuilder.getExpressionAttributeValues()); expressionAttributeNames.putAll(conditionExpressionBuilder.getExpressionAttributeNames()); updateItemRequest.setConditionExpression(conditionExpressionBuilder.getExpression()); } if (!expressionAttributeValues.isEmpty()) { updateItemRequest.setExpressionAttributeValues(expressionAttributeValues); } if (!expressionAttributeNames.isEmpty()) { updateItemRequest.setExpressionAttributeNames(expressionAttributeNames); } if (resultFromUpdate != ResultFromUpdate.ReturnNone) { updateItemRequest .setReturnValues(resultFromUpdate == ResultFromUpdate.ReturnPreUpdate ? ReturnValue.ALL_OLD : ReturnValue.ALL_NEW); UpdateItemResult result = dynamoDB.updateItem(updateItemRequest); T t = ConversionUtil.getObjectFromItem(result.getAttributes(), entityClass); ((DynamoDBPersistable) t).__markPersisted(dynamoDB.toString()); return t; } else { dynamoDB.updateItem(updateItemRequest); return null; } } catch (Exception e) { throw new JeppettoException(e); } }