Example usage for com.amazonaws.services.dynamodbv2.document UpdateItemOutcome getUpdateItemResult

List of usage examples for com.amazonaws.services.dynamodbv2.document UpdateItemOutcome getUpdateItemResult

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document UpdateItemOutcome getUpdateItemResult.

Prototype

public UpdateItemResult getUpdateItemResult() 

Source Link

Document

Returns a non-null low-level result returned from the server side.

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 {/*from  w w  w.  j  a v a 2 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());
    }
}

From source file:com.github.fge.jsonpatch.JsonPatchToXSpecReplace.java

License:LGPL

@Test
public void testReplaceSinglePathNumberExtant() throws Exception {
    // setup//  w  w w.  ja v  a  2 s .co  m
    table.putItem(Item.fromMap(ImmutableMap.<String, Object>builder().put(KEY_ATTRIBUTE_NAME, VALUE)
            .put("a", "peekaboo").build()));
    String patchExpression = "[ { \"op\": \"replace\", \"path\": \"/a\", \"value\": 1 } ]";
    JsonNode jsonNode = JsonLoader.fromString(patchExpression);
    JsonPatch jsonPatch = JsonPatch.fromJson(jsonNode);
    // exercise
    ExpressionSpecBuilder builder = jsonPatch.get();
    UpdateItemExpressionSpec spec = builder.buildForUpdate();
    UpdateItemOutcome out = table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY_ATTRIBUTE_NAME, VALUE)
            .withExpressionSpec(spec).withReturnValues(ReturnValue.ALL_OLD));

    Item oldItem = Item.fromMap(InternalUtils.toSimpleMapValue(out.getUpdateItemResult().getAttributes()));
    Assert.assertTrue(oldItem.hasAttribute("a"));
    Assert.assertEquals(oldItem.getString("a"), "peekaboo");
    // verify
    Item item = table.getItem(PK);
    Assert.assertTrue(item.hasAttribute("key"));
    Assert.assertEquals(item.getString("key"), "keyValue");
    Assert.assertTrue(item.hasAttribute("a"));
    Assert.assertEquals(item.getNumber("a").longValue(), 1L);
}