@Test public void deleteHashRangeItemTest() { putItemWithHashKeyAndRangeKey(); putItemWithHashKeyAndRangeKeyOverwriteItem(); String hashCode = "hash2"; String rangeCode = "range2"; TestClassWithHashRangeKey value = mapper.load(TestClassWithHashRangeKey.class, hashCode, rangeCode); Assert.assertNotNull("Value not found.", value); Assert.assertEquals("Wrong hashCode.", hashCode, value.getHashCode()); Assert.assertEquals("Wrong rangeCode.", rangeCode, value.getRangeCode()); Assert.assertEquals("Wrong stringData.", "string2b", value.getStringData()); Assert.assertEquals("Wrong intData.", 22, value.getIntData()); Assert.assertEquals( "Wrong stringSetData.", set("stringSetVal2b1", "stringSetVal2b2"), value.getStringSetData()); Assert.assertEquals("Wrong numberSetData.", set(5, 6), value.getNumberSetData()); mapper.delete(value); TestClassWithHashRangeKey value2 = mapper.load(TestClassWithHashRangeKey.class, hashCode, rangeCode); Assert.assertNull("Value2 should not be found.", value2); }
private void deleteNodeHistoryItem(String nid, String time) { DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.ConsistentReads.CONSISTENT); NodeHistory updatedItem; NodeHistory deletedItem; if (time != null) { updatedItem = mapper.load(NodeHistory.class, nid, time, config); mapper.delete(updatedItem); deletedItem = mapper.load(NodeHistory.class, updatedItem.getNodeID(), updatedItem.getTime(), config); } else { updatedItem = mapper.load(NodeHistory.class, nid, config); mapper.delete(updatedItem); deletedItem = mapper.load(NodeHistory.class, updatedItem.getNodeID(), config); } if (deletedItem == null) System.out.println("Done - The item is deleted."); else System.out.println("Fail - The item is still remained."); }
/* * Deletes the specified user and all of its attribute/value pairs. */ public static void deleteUser(UserPreference deleteUserPreference) { AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb(); DynamoDBMapper mapper = new DynamoDBMapper(ddb); try { mapper.delete(deleteUserPreference); } catch (AmazonServiceException ex) { LoginActivity.clientManager.wipeCredentialsOnAuthError(ex); } }
public void removeItemFromCart(Long cartId) { DynamoDBMapper mapper = this.conn.getMapper(); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition scanCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withN(cartId.toString())); scanFilter.put("CartId", scanCondition); scanExpression.setScanFilter(scanFilter); System.out.println("Going to retrieve item."); PaginatedScanList<CartItem> items = mapper.scan(CartItem.class, scanExpression); System.out.println("Number of items retrived. " + items.size()); System.out.println("Going to remove a cartItem with productId: " + items.get(0).getProductId()); mapper.delete(items.get(0)); }
@Test public void deleteHashItemTest() { putItemWithHashKey(); putItemWithHashKeyOverwriteItem(); String code = "hash1"; TestClassWithHashKey value = mapper.load(TestClassWithHashKey.class, code); Assert.assertNotNull("Value not found.", value); Assert.assertEquals("Wrong code.", code, value.getCode()); Assert.assertEquals("Wrong stringData.", "string1", value.getStringData()); Assert.assertEquals("Wrong intData.", 1, value.getIntData()); Assert.assertEquals( "Wrong stringSetData.", set("stringSetVal1", "stringSetVal2"), value.getStringSetData()); Assert.assertEquals("Wrong numberSetData.", set(1, 2), value.getNumberSetData()); mapper.delete(value); TestClassWithHashKey value2 = mapper.load(TestClassWithHashKey.class, code); Assert.assertNull("Value2 should not be found.", value2); }