Search in sources :

Example 1 with DeletableItem

use of com.amazonaws.services.simpledb.model.DeletableItem in project camel by apache.

the class SdbComponentIntegrationTest method batchDeleteAttributes.

@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);
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) Test(org.junit.Test)

Example 2 with DeletableItem

use of com.amazonaws.services.simpledb.model.DeletableItem in project siena by mandubian.

the class SdbPersistenceManager method deleteByKeys.

@Override
public <T> int deleteByKeys(Class<T> clazz, Iterable<?> keys) {
    List<DeletableItem> doList = new ArrayList<DeletableItem>();
    int nb = 0;
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    for (Object key : keys) {
        doList.add(SdbMappingUtils.createDeletableItemFromKey(clazz, key));
        nb++;
    }
    try {
        checkDomain(domain);
        int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
        for (int i = 0; i < doList.size(); i += len) {
            int sz = i + len;
            if (sz > doList.size()) {
                sz = doList.size();
            }
            sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(domain, doList.subList(i, sz)));
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) BatchDeleteAttributesRequest(com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) SienaException(siena.SienaException)

Example 3 with DeletableItem

use of com.amazonaws.services.simpledb.model.DeletableItem in project camel by apache.

the class SdbComponentTest method batchDeleteAttributes.

@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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) Test(org.junit.Test)

Example 4 with DeletableItem

use of com.amazonaws.services.simpledb.model.DeletableItem in project camel by apache.

the class SdbComponentSpringTest method batchDeleteAttributes.

@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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) Test(org.junit.Test)

Example 5 with DeletableItem

use of com.amazonaws.services.simpledb.model.DeletableItem in project siena by mandubian.

the class SdbPersistenceManager method delete.

@Override
public int delete(Iterable<?> models) {
    Map<String, List<DeletableItem>> doMap = new HashMap<String, List<DeletableItem>>();
    int nb = 0;
    for (Object obj : models) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<DeletableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<DeletableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createDeletableItem(obj));
        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<DeletableItem> doList = doMap.get(domain);
            int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
            for (int i = 0; i < doList.size(); i += len) {
                int sz = i + len;
                if (sz > doList.size()) {
                    sz = doList.size();
                }
                sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(domain, doList.subList(i, sz)));
            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) BatchDeleteAttributesRequest(com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Aggregations

DeletableItem (com.amazonaws.services.simpledb.model.DeletableItem)5 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 Test (org.junit.Test)3 AmazonClientException (com.amazonaws.AmazonClientException)2 BatchDeleteAttributesRequest (com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest)2 ArrayList (java.util.ArrayList)2 SienaException (siena.SienaException)2 HashMap (java.util.HashMap)1 List (java.util.List)1