Search in sources :

Example 1 with ReplaceableItem

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

the class BatchPutAttributesCommandTest method determineReplaceableItems.

@Test
public void determineReplaceableItems() {
    assertNull(this.command.determineReplaceableItems());
    List<ReplaceableItem> replaceableItems = new ArrayList<ReplaceableItem>();
    replaceableItems.add(new ReplaceableItem("ITEM1"));
    exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ITEMS, replaceableItems);
    assertEquals(replaceableItems, this.command.determineReplaceableItems());
}
Also used : ArrayList(java.util.ArrayList) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) Test(org.junit.Test)

Example 2 with ReplaceableItem

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

the class SdbComponentSpringTest method batchPutAttributes.

@Test
public void batchPutAttributes() {
    final List<ReplaceableItem> replaceableItems = Arrays.asList(new ReplaceableItem[] { new ReplaceableItem("ITEM1") });
    template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchPutAttributes);
            exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ITEMS, replaceableItems);
        }
    });
    assertEquals("TestDomain", amazonSDBClient.batchPutAttributesRequest.getDomainName());
    assertEquals(replaceableItems, amazonSDBClient.batchPutAttributesRequest.getItems());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) Test(org.junit.Test)

Example 3 with ReplaceableItem

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

the class SdbComponentTest method batchPutAttributes.

@Test
public void batchPutAttributes() {
    final List<ReplaceableItem> replaceableItems = Arrays.asList(new ReplaceableItem[] { new ReplaceableItem("ITEM1") });
    template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchPutAttributes);
            exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ITEMS, replaceableItems);
        }
    });
    assertEquals("TestDomain", amazonSDBClient.batchPutAttributesRequest.getDomainName());
    assertEquals(replaceableItems, amazonSDBClient.batchPutAttributesRequest.getItems());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) Test(org.junit.Test)

Example 4 with ReplaceableItem

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

the class SdbPersistenceManager method update.

public <T> int update(Iterable<T> models) {
    Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
    int nb = 0;
    for (Object obj : models) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<ReplaceableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<ReplaceableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createItem(obj));
        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<ReplaceableItem> 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.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) BatchPutAttributesRequest(com.amazonaws.services.simpledb.model.BatchPutAttributesRequest) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Example 5 with ReplaceableItem

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

the class SdbPersistenceManager method insert.

@Override
public int insert(Iterable<?> objects) {
    Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
    int nb = 0;
    for (Object obj : objects) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<ReplaceableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<ReplaceableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createItem(obj));
        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<ReplaceableItem> 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.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) BatchPutAttributesRequest(com.amazonaws.services.simpledb.model.BatchPutAttributesRequest) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Aggregations

ReplaceableItem (com.amazonaws.services.simpledb.model.ReplaceableItem)8 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 SienaException (siena.SienaException)3 AmazonClientException (com.amazonaws.AmazonClientException)2 BatchPutAttributesRequest (com.amazonaws.services.simpledb.model.BatchPutAttributesRequest)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 SienaRestrictedApiException (siena.SienaRestrictedApiException)1