@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)) ; }
/** * 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)) ; }
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"); } }
/** * 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()) ; } }
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()); } } }