Example usage for com.amazonaws.services.dynamodbv2.model ReturnValue UPDATED_OLD

List of usage examples for com.amazonaws.services.dynamodbv2.model ReturnValue UPDATED_OLD

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ReturnValue UPDATED_OLD.

Prototype

ReturnValue UPDATED_OLD

To view the source code for com.amazonaws.services.dynamodbv2.model ReturnValue UPDATED_OLD.

Click Source Link

Usage

From source file:com.exorath.service.treasurehunt.dynamodb.DynamoDBService.java

License:Apache License

@Override
public PutResult setTreasure(UUID playerId, String treasureId) {
    UpdateItemSpec spec = new UpdateItemSpec().withPrimaryKey(PRIM_KEY, playerId.toString())
            .withAttributeUpdate(new AttributeUpdate(TREASURES_FIELD).addElements(treasureId))
            .withReturnValues(ReturnValue.UPDATED_OLD);
    try {// ww w  .  j a  v a2 s.c  o  m
        UpdateItemOutcome outcome = table.updateItem(spec);
        if (!outcome.getUpdateItemResult().toString().contains(treasureId)) {
            logger.info("Successfully set treasure " + treasureId + " for player " + playerId);
            return new PutResult();
        } else {
            logger.warn(
                    "Attempted to set treasure " + treasureId + " for player " + playerId + " a second time");
            return new PutResult("Treasure " + treasureId + " already set for player " + playerId);
        }
    } catch (ConditionalCheckFailedException ex) {
        logger.warn(
                "Updated treasure " + treasureId + " for player " + playerId + " failed\n:" + ex.getMessage());
        return new PutResult(ex.getMessage());
    }
}