Example usage for com.amazonaws.services.dynamodbv2.document Item getNumber

List of usage examples for com.amazonaws.services.dynamodbv2.document Item getNumber

Introduction

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

Prototype

public BigDecimal getNumber(String attrName) 

Source Link

Document

Returns the value of the specified attribute in the current item as a BigDecimal; or null if the attribute either doesn't exist or the attribute value is null.

Usage

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

License:LGPL

@Test
public void testReplaceSinglePathNumberExtant() throws Exception {
    // setup//from   ww w .j ava  2 s .com
    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);
}