@Test public void batchDeleteAttributes() { final List<DeletableItem> deletableItems = Arrays.asList(new DeletableItem[] { new DeletableItem("ITEM1", null), new DeletableItem("ITEM2", null)}); template.send("direct:start", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchDeleteAttributes); exchange.getIn().setHeader(SdbConstants.DELETABLE_ITEMS, deletableItems); } }); assertEquals("TestDomain", amazonSDBClient.batchDeleteAttributesRequest.getDomainName()); assertEquals(deletableItems, amazonSDBClient.batchDeleteAttributesRequest.getItems()); }
@Override public <T, ID> void delete(Class<T> entityClass, Iterable<? extends ID> ids) { if (ids.iterator().hasNext()) { String domainName = getDomainName(entityClass); List<DeletableItem> deleteList = new ArrayList<DeletableItem>(); for (ID id : ids) { deleteList.add(new DeletableItem().withName((String) id)); } // max allowed batch size is 25 List<DeletableItem> batch = new ArrayList<DeletableItem>(MAX_BATCH_SIZE); for (int i = 0; i < deleteList.size(); i += MAX_BATCH_SIZE) { int batchIndex = ((i + MAX_BATCH_SIZE) < deleteList.size()) ? (i + MAX_BATCH_SIZE) : deleteList.size(); for (int j = i; j < batchIndex; j++) { batch.add(deleteList.get(j)); } LOGGER.debug(String.format("Batch size: %d", batch.size())); getDB().batchDeleteAttributes(new BatchDeleteAttributesRequest( domainName, batch)); batch.clear(); } } }
@Test public void batchDeleteAttributes() { final List<DeletableItem> deletableItems = Arrays.asList(new DeletableItem[] { new DeletableItem("ITEM1", null), new DeletableItem("ITEM2", null)}); template.send("direct:start", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchDeleteAttributes); exchange.getIn().setHeader(SdbConstants.DELETABLE_ITEMS, deletableItems); } }); }
@SuppressWarnings("unchecked") protected Collection<DeletableItem> determineDeletableItems() { return exchange.getIn().getHeader(SdbConstants.DELETABLE_ITEMS, Collection.class); }