@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKeys, String conditionExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeys) .withConditionExpression(conditionExpression) .withNameMap(nameMap) .withValueMap(valueMap)) ; }
@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKeys, Expected... expected) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeys) .withExpected(expected)); }
@Override public DeleteItemOutcome deleteItem(KeyAttribute... primaryKeyComponents) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeyComponents)); }
@Override public String remove(String key) { Assert.hasText(key, "'key' must not be empty."); awaitForActive(); Item item = this.table.deleteItem( new DeleteItemSpec() .withPrimaryKey(KEY, key) .withReturnValues(ReturnValue.ALL_OLD)) .getItem(); return getValueIfAny(item); }
/** * Convenient method to specify expressions (and the associated name map and * value map) via {@link DeleteItemExpressionSpec}. */ @Beta public DeleteItemSpec withExpressionSpec(DeleteItemExpressionSpec xspec) { return withConditionExpression(xspec.getConditionExpression()) .withNameMap(xspec.getNameMap()) .withValueMap(xspec.getValueMap()) ; } }
DeleteItemSpec itemSpec = new DeleteItemSpec().withPrimaryKey("cognitoId", "my_id", "sortKeyField", "sort_key_id"); DeleteItemOutcome outcome = table.deleteItem(itemSpec);
@Override public String remove(String key) { Assert.hasText(key, "'key' must not be empty."); awaitForActive(); Item item = this.table.deleteItem( new DeleteItemSpec() .withPrimaryKey(KEY, key) .withReturnValues(ReturnValue.ALL_OLD)) .getItem(); return getValueIfAny(item); }
@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKey) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKey)); }
@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKeys, Expected... expected) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeys) .withExpected(expected)); }
/** * Convenient method to specify expressions (and the associated name map and * value map) via {@link DeleteItemExpressionSpec}. */ @Beta public DeleteItemSpec withExpressionSpec(DeleteItemExpressionSpec xspec) { return withConditionExpression(xspec.getConditionExpression()) .withNameMap(xspec.getNameMap()) .withValueMap(xspec.getValueMap()) ; } }
@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKeys, String conditionExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeys) .withConditionExpression(conditionExpression) .withNameMap(nameMap) .withValueMap(valueMap)) ; }
/** * Returns the DynamoDB delete item spec for the specified key. * * @param key The key. * * @return The delete item spec. */ DeleteItemSpec resolveDeleteItemSpec(final Object key) { DeleteItemSpec spec = new DeleteItemSpec(); if (applyRangeKey) { spec.withPrimaryKey( itemTransformer.getHashKeyAttributeName(), resolveHashKey(key), rangeKeyName, rangeKeyValue); } else { spec.withPrimaryKey( itemTransformer.getHashKeyAttributeName(), resolveHashKey(key)); } return spec.withReturnValues(ReturnValue.ALL_OLD); // to confirm deletion }
@Override public DeleteItemOutcome deleteItem(KeyAttribute... primaryKeyComponents) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKeyComponents)); }
private static void deleteItem() { Table table = dynamoDB.getTable(tableName); try { DeleteItemSpec deleteItemSpec = new DeleteItemSpec() .withPrimaryKey("Id", 120) .withConditionExpression("#ip = :val") .withNameMap(new NameMap() .with("#ip", "InPublication")) .withValueMap(new ValueMap() .withBoolean(":val", false)) .withReturnValues(ReturnValue.ALL_OLD); DeleteItemOutcome outcome = table.deleteItem(deleteItemSpec); // Check the response. System.out.println("Printing item that was deleted..."); System.out.println(outcome.getItem().toJSONPretty()); } catch (Exception e) { System.err.println("Error deleting item in " + tableName); System.err.println(e.getMessage()); } } }
@Override public DeleteItemOutcome deleteItem(PrimaryKey primaryKey) { return doDeleteItem(new DeleteItemSpec() .withPrimaryKey(primaryKey)); }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); // Conditional delete (will fail) DeleteItemSpec deleteItemSpec = new DeleteItemSpec() .withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie")) .withConditionExpression("info.rating <= :val") .withValueMap(new ValueMap() .withNumber(":val", 5.0)); System.out.println("Attempting a conditional delete..."); try { table.deleteItem(deleteItemSpec); System.out.println("DeleteItem succeeded"); } catch (Exception e) { e.printStackTrace(); System.out.println("DeleteItem failed"); } }