use of siena.SienaException 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;
}
use of siena.SienaException in project siena by mandubian.
the class SdbPersistenceManager method rawGet.
protected <T> int rawGet(Iterable<T> models) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildBatchGetQuery(models, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
try {
checkDomain(domainBuf.toString());
SelectResult res = sdb.select(req);
int nb = SdbMappingUtils.mapSelectResult(res, models);
// join management
// gets class
Class<?> clazz = null;
for (T obj : models) {
if (clazz == null) {
clazz = obj.getClass();
break;
}
}
if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
mapJoins(models);
}
return nb;
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
}
use of siena.SienaException 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 siena.SienaException 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 siena.SienaException in project siena by mandubian.
the class SdbNativeSerializer method embed.
public static void embed(PutAttributesRequest req, String embeddingColumnName, Object embeddedObj) {
Class<?> clazz = embeddedObj.getClass();
if (clazz.isArray() || Collection.class.isAssignableFrom(clazz)) {
throw new SienaException("can't serializer Array/Collection in native mode");
}
for (Field f : ClassInfo.getClassInfo(clazz).updateFields) {
String propValue = SdbMappingUtils.objectFieldToString(embeddedObj, f);
if (propValue != null) {
ReplaceableAttribute attr = new ReplaceableAttribute(getEmbeddedAttributeName(embeddingColumnName, f), propValue, true);
req.withAttributes(attr);
} else {
if (ClassInfo.isEmbeddedNative(f)) {
SdbNativeSerializer.embed(req, getEmbeddedAttributeName(embeddingColumnName, f), Util.readField(embeddedObj, f));
}
}
}
}
Aggregations