Search in sources :

Example 1 with BatchPutAttributesRequest

use of com.amazonaws.services.simpledb.model.BatchPutAttributesRequest 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 2 with BatchPutAttributesRequest

use of com.amazonaws.services.simpledb.model.BatchPutAttributesRequest 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)

Example 3 with BatchPutAttributesRequest

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

the class BatchPutAttributesCommand method execute.

public void execute() {
    BatchPutAttributesRequest request = new BatchPutAttributesRequest().withDomainName(determineDomainName()).withItems(determineReplaceableItems());
    log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
    this.sdbClient.batchPutAttributes(request);
    log.trace("Request sent");
}
Also used : BatchPutAttributesRequest(com.amazonaws.services.simpledb.model.BatchPutAttributesRequest)

Aggregations

BatchPutAttributesRequest (com.amazonaws.services.simpledb.model.BatchPutAttributesRequest)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ReplaceableItem (com.amazonaws.services.simpledb.model.ReplaceableItem)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 SienaException (siena.SienaException)2