Search in sources :

Example 1 with BatchDeleteAttributesRequest

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

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

the class BatchDeleteAttributesCommand method execute.

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

Example 3 with BatchDeleteAttributesRequest

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

BatchDeleteAttributesRequest (com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest)3 AmazonClientException (com.amazonaws.AmazonClientException)2 DeletableItem (com.amazonaws.services.simpledb.model.DeletableItem)2 ArrayList (java.util.ArrayList)2 SienaException (siena.SienaException)2 HashMap (java.util.HashMap)1 List (java.util.List)1