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;
}
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;
}
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");
}
Aggregations