Search in sources :

Example 1 with UpdateItemRequest

use of com.amazonaws.services.dynamodbv2.model.UpdateItemRequest in project camel by apache.

the class UpdateItemCommand method execute.

@Override
public void execute() {
    UpdateItemResult result = ddbClient.updateItem(new UpdateItemRequest().withTableName(determineTableName()).withKey(determineKey()).withAttributeUpdates(determineUpdateValues()).withExpected(determineUpdateCondition()).withReturnValues(determineReturnValues()));
    addAttributesToResult(result.getAttributes());
}
Also used : UpdateItemRequest(com.amazonaws.services.dynamodbv2.model.UpdateItemRequest) UpdateItemResult(com.amazonaws.services.dynamodbv2.model.UpdateItemResult)

Example 2 with UpdateItemRequest

use of com.amazonaws.services.dynamodbv2.model.UpdateItemRequest in project jcabi-dynamo by jcabi.

the class AwsItem method put.

@Override
public Map<String, AttributeValue> put(final Map<String, AttributeValueUpdate> attrs) throws IOException {
    final AmazonDynamoDB aws = this.credentials.aws();
    final Attributes expected = this.attributes.only(this.keys);
    try {
        final UpdateItemRequest request = new UpdateItemRequest().withTableName(this.name).withExpected(expected.asKeys()).withKey(expected).withAttributeUpdates(attrs).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withReturnValues(ReturnValue.UPDATED_NEW);
        final long start = System.currentTimeMillis();
        final UpdateItemResult result = aws.updateItem(request);
        Logger.info(this, "#put('%s'): updated item to DynamoDB, %s, in %[ms]s", attrs, new PrintableConsumedCapacity(result.getConsumedCapacity()).print(), System.currentTimeMillis() - start);
        return result.getAttributes();
    } catch (final AmazonClientException ex) {
        throw new IOException(String.format("Failed to put %s into \"%s\" with %s", attrs, this.name, this.keys), ex);
    } finally {
        aws.shutdown();
    }
}
Also used : UpdateItemRequest(com.amazonaws.services.dynamodbv2.model.UpdateItemRequest) AmazonClientException(com.amazonaws.AmazonClientException) UpdateItemResult(com.amazonaws.services.dynamodbv2.model.UpdateItemResult) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) IOException(java.io.IOException)

Aggregations

UpdateItemRequest (com.amazonaws.services.dynamodbv2.model.UpdateItemRequest)2 UpdateItemResult (com.amazonaws.services.dynamodbv2.model.UpdateItemResult)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 IOException (java.io.IOException)1