コード例 #1
0
  public DeleteItemResult unmarshall(JsonUnmarshallerContext context) throws Exception {
    DeleteItemResult deleteItemResult = new DeleteItemResult();

    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.currentToken;
    if (token == null) token = context.nextToken();

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("Attributes", targetDepth)) {
          deleteItemResult.setAttributes(
              new MapUnmarshaller<String, AttributeValue>(
                      StringJsonUnmarshaller.getInstance(),
                      AttributeValueJsonUnmarshaller.getInstance())
                  .unmarshall(context));
        }
        if (context.testExpression("ConsumedCapacityUnits", targetDepth)) {
          context.nextToken();
          deleteItemResult.setConsumedCapacityUnits(
              DoubleJsonUnmarshaller.getInstance().unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getCurrentDepth() <= originalDepth) break;
      }

      token = context.nextToken();
    }

    return deleteItemResult;
  }
コード例 #2
0
 @Test
 public void deleteItem() {
   KeySchema schema =
       new KeySchema(
           new KeySchemaElement()
               .withAttributeName("id")
               .withAttributeType(ScalarAttributeType.S));
   createTable(tableName, schema);
   AttributeValue hash = new AttributeValue("ad"); // createStringAttribute();
   getClient()
       .putItem(new PutItemRequest().withTableName(tableName).withItem(createGenericItem(hash)));
   DeleteItemRequest request =
       new DeleteItemRequest().withTableName(tableName).withKey(new Key(hash));
   DeleteItemResult result = getClient().deleteItem(request);
   Assert.assertNotNull(result.getConsumedCapacityUnits());
 }
コード例 #3
0
 @Test
 public void deleteItemWithHashKeyAndRangeKey() {
   KeySchema schema =
       new KeySchema(
           new KeySchemaElement()
               .withAttributeName("id")
               .withAttributeType(ScalarAttributeType.S));
   schema.setRangeKeyElement(
       new KeySchemaElement().withAttributeName("range").withAttributeType(ScalarAttributeType.N));
   createTable(tableName, schema);
   AttributeValue hash = new AttributeValue("ad");
   AttributeValue range1 = new AttributeValue().withN("1");
   AttributeValue range2 = new AttributeValue().withN("2");
   getClient()
       .putItem(
           new PutItemRequest()
               .withTableName(tableName)
               .withItem(createGenericItem(hash, range1)));
   getClient()
       .putItem(
           new PutItemRequest()
               .withTableName(tableName)
               .withItem(createGenericItem(hash, range2)));
   Key key1 = new Key().withHashKeyElement(hash).withRangeKeyElement(range1);
   Key key2 = new Key().withHashKeyElement(hash).withRangeKeyElement(range2);
   DeleteItemRequest request1 =
       new DeleteItemRequest()
           .withTableName(tableName)
           .withKey(key1)
           .withReturnValues(ReturnValue.ALL_OLD);
   DeleteItemRequest request2 =
       new DeleteItemRequest()
           .withTableName(tableName)
           .withKey(key2)
           .withReturnValues(ReturnValue.ALL_OLD);
   DeleteItemResult result = getClient().deleteItem(request1);
   Assert.assertNotNull(result.getAttributes());
   result = getClient().deleteItem(request2);
   Assert.assertNotNull(result.getAttributes());
 }