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