use of siena.ClassInfo in project siena by mandubian.
the class SdbMappingUtils method mapSelectResultToListOrderedFromKeys.
public static <T> void mapSelectResultToListOrderedFromKeys(SelectResult res, List<T> resList, Class<T> clazz, Iterable<?> keys) {
List<Item> items = res.getItems();
ClassInfo info = ClassInfo.getClassInfo(clazz);
boolean found;
for (Object key : keys) {
found = false;
for (Item item : items) {
if (item.getName().equals(getItemNameFromKey(clazz, key))) {
T obj = Util.createObjectInstance(clazz);
fillModel(item, clazz, info, obj);
resList.add(obj);
items.remove(item);
found = true;
break;
}
}
if (!found) {
// if not found, puts NULL in the list
resList.add(null);
}
}
}
use of siena.ClassInfo in project siena by mandubian.
the class SdbMappingUtils method getDomainName.
public static String getDomainName(Class<?> clazz, String prefix) {
ClassInfo ci = ClassInfo.getClassInfo(clazz);
if (ClassInfo.isAutoIncrement(ci.getIdField())) {
throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
}
String domain = prefix + ci.tableName;
return domain;
}
use of siena.ClassInfo in project siena by mandubian.
the class SdbMappingUtils method mapSelectResultToList.
public static <T> void mapSelectResultToList(SelectResult res, List<T> resList, Class<T> clazz, int offset) {
List<Item> items = res.getItems();
ClassInfo info = ClassInfo.getClassInfo(clazz);
for (int i = offset; i < items.size(); i++) {
Item item = items.get(i);
T obj = Util.createObjectInstance(clazz);
fillModel(item, clazz, info, obj);
resList.add(obj);
}
}
use of siena.ClassInfo in project siena by mandubian.
the class SdbPersistenceManager method update.
public void update(Object obj) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
String domain = SdbMappingUtils.getDomainName(clazz, prefix);
try {
checkDomain(domain);
sdb.putAttributes(SdbMappingUtils.createPutRequest(domain, clazz, info, obj));
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
}
use of siena.ClassInfo in project siena by mandubian.
the class SdbPersistenceManager method save.
@Override
public void save(Object obj) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
//Entity entity;
Object idVal = Util.readField(obj, idField);
// id with null value means insert
if (idVal == null) {
insert(obj);
} else // id with not null value means update
{
update(obj);
}
}
Aggregations