use of siena.SienaException in project siena by mandubian.
the class JdbcMappingUtils method mapObjectKeys.
public static <T> T mapObjectKeys(Class<T> clazz, ResultSet rs, String tableName, List<Field> joinFields) {
try {
T obj = Util.createObjectInstance(clazz);
mapObjectKeys(obj, rs, tableName, joinFields);
return obj;
} catch (SienaException e) {
throw e;
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.SienaException in project siena by mandubian.
the class JdbcMappingUtils method mapField.
public static void mapField(Object obj, Field field, ResultSet rs, String tableName, List<Field> joinFields) {
Class<?> type = field.getType();
// field.setAccessible(true);
try {
if (ClassInfo.isModel(type) && !ClassInfo.isEmbedded(field)) {
JdbcClassInfo fieldClassInfo = JdbcClassInfo.getClassInfo(type);
if (joinFields == null || joinFields.size() == 0 || !joinFields.contains(field)) {
String[] fks = ClassInfo.getColumnNames(field, tableName);
Object rel = Util.createObjectInstance(type);
boolean none = false;
int i = 0;
checkForeignKeyMapping(fieldClassInfo.keys, fks, obj.getClass(), field);
for (Field f : fieldClassInfo.keys) {
Object o = rs.getObject(JdbcClassInfo.aliasFromCol(fks[i++]));
if (o == null) {
none = true;
break;
}
setFromObject(rel, f, o);
}
if (!none) {
Util.setField(obj, field, rel);
// field.set(obj, rel);
}
} else {
// this is a JOIN field
// first verifies the field is not null
Object val = rs.getObject(JdbcClassInfo.aliasFromCol(ClassInfo.getColumnNames(field, tableName)[0]));
if (val == null) {
Util.setField(obj, field, null);
return;
}
// uses join field alias
// Object rel = mapObject(type, rs, fieldClassInfo.tableName, null);
Object rel = mapObject(type, rs, fieldClassInfo.joinFieldAliases.get(field.getName()), null);
Util.setField(obj, field, rel);
}
} else {
Object val = rs.getObject(ClassInfo.getColumnNames(field, tableName)[0].replace('.', '_'));
setFromObject(obj, field, val);
}
} catch (SienaException e) {
throw e;
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.SienaException in project siena by mandubian.
the class RemotePersistenceManager method sendAndParse.
@SuppressWarnings("unchecked")
private <T> List<T> sendAndParse(Document request) {
Document response = send(request);
Element root = response.getRootElement();
if ("error".equals(root.getName())) {
throw new SienaException(root.attributeValue("class") + " " + root.getText());
}
List<Element> result = response.getRootElement().elements("object");
List<T> list = new ArrayList<T>(result.size());
for (Element element : result) {
list.add((T) Common.parseEntity(element, null));
}
return list;
}
use of siena.SienaException in project siena by mandubian.
the class RemotePersistenceManager method send.
protected Document send(Document request) {
try {
connector.connect();
serializer.serialize(request, connector.getOutputStream());
Document response = serializer.deserialize(connector.getInputStream());
connector.close();
return response;
} catch (IOException e) {
throw new SienaException(e);
}
}
use of siena.SienaException in project siena by mandubian.
the class BaseAsyncTest method testOffsetLimitStatelessPaginate2Iter.
public void testOffsetLimitStatelessPaginate2Iter() {
Discovery[] discs = new Discovery[300];
for (int i = 0; i < 300; i++) {
discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
}
pm.insert((Object[]) discs).get();
QueryAsync<Discovery> query = pm.createQuery(Discovery.class).order("id");
SienaFuture<Iterable<Discovery>> future = query.limit(50).offset(12).iter();
Iterable<Discovery> iter = future.get();
Iterator<Discovery> it = iter.iterator();
int i = 12;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(62, i);
future = query.offset(13).limit(30).iter();
iter = future.get();
it = iter.iterator();
i = 13;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(43, i);
future = query.offset(10).limit(30).iter(15);
iter = future.get();
it = iter.iterator();
i = 10;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(25, i);
future = query.paginate(6).iter();
iter = future.get();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(6, i);
future = query.nextPage().iter();
iter = future.get();
it = iter.iterator();
i = 6;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(12, i);
future = query.nextPage().iter();
iter = future.get();
it = iter.iterator();
i = 12;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(18, i);
future = query.previousPage().iter();
iter = future.get();
it = iter.iterator();
i = 6;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(12, i);
future = query.offset(10).iter(10);
iter = future.get();
it = iter.iterator();
i = 10;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(20, i);
try {
future = query.nextPage().iter();
} catch (SienaException ex) {
future = query.paginate(8).iter();
iter = future.get();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(8, i);
future = query.nextPage().iter();
iter = future.get();
it = iter.iterator();
i = 8;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(16, i);
return;
}
fail();
}
Aggregations