use of siena.QueryAggregated in project siena by mandubian.
the class GaeMappingUtils method mapRelation.
public static <T> T mapRelation(Query<T> query, T obj, ClassInfo info) {
// aggregators/owners
List<QueryAggregated> aggregs = query.getAggregatees();
List<QueryOwned> ownees = query.getOwnees();
if (aggregs.isEmpty() && ownees.isEmpty()) {
return obj;
}
if (aggregs.size() == 1) {
// aggregators
QueryAggregated aggreg = aggregs.get(0);
Relation rel = new Relation(RelationMode.AGGREGATION, aggreg.aggregator, aggreg.field);
Util.setField(obj, info.aggregator, rel);
} else if (aggregs.size() > 1) {
throw new SienaException("Only one aggregation per query allowed");
}
if (ownees.size() == 1) {
// owners
QueryOwned ownee = ownees.get(0);
Util.setField(obj, ownee.field, ownee.owner);
} else if (ownees.size() > 1) {
throw new SienaException("Only one owner per query allowed");
}
return obj;
}
use of siena.QueryAggregated in project siena by mandubian.
the class GaePersistenceManager method prepareKeysOnly.
private <T> PreparedQuery prepareKeysOnly(Query<T> query) {
Class<?> clazz = query.getQueriedClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
com.google.appengine.api.datastore.Query q;
// manages aggregation at first
List<QueryAggregated> aggregs = query.getAggregatees();
if (aggregs.isEmpty()) {
q = new com.google.appengine.api.datastore.Query(ClassInfo.getClassInfo(clazz).tableName);
} else if (aggregs.size() == 1) {
QueryAggregated aggreg = aggregs.get(0);
q = new com.google.appengine.api.datastore.Query(GaeMappingUtils.getKindWithAncestorField(info, ClassInfo.getClassInfo(aggreg.aggregator.getClass()), aggreg.field));
q.setAncestor(GaeMappingUtils.getKey(aggreg.aggregator));
} else {
throw new SienaException("Only one aggregation per query allowed");
}
return ds.prepare(GaeQueryUtils.addFiltersOrders(query, q).setKeysOnly());
}
use of siena.QueryAggregated in project siena by mandubian.
the class GaePersistenceManager method prepare.
private <T> PreparedQuery prepare(Query<T> query) {
Class<?> clazz = query.getQueriedClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
com.google.appengine.api.datastore.Query q;
// manages aggregation at first
List<QueryAggregated> aggregs = query.getAggregatees();
if (aggregs.isEmpty()) {
q = new com.google.appengine.api.datastore.Query(info.tableName);
return ds.prepare(GaeQueryUtils.addFiltersOrders(query, q));
} else if (aggregs.size() == 1) {
QueryAggregated aggreg = aggregs.get(0);
Key ancestorKey = GaeMappingUtils.getKey(aggreg.aggregator);
q = new com.google.appengine.api.datastore.Query(GaeMappingUtils.getKindWithAncestorField(info, ClassInfo.getClassInfo(aggreg.aggregator.getClass()), aggreg.field));
q.setAncestor(ancestorKey);
return ds.prepare(GaeQueryUtils.addFiltersOrders(query, q, ancestorKey));
} else {
throw new SienaException("Only one aggregation per query allowed");
}
}
use of siena.QueryAggregated in project siena by mandubian.
the class GaeMappingUtils method mapRelations.
public static <T> List<T> mapRelations(Query<T> query, List<T> objs, ClassInfo info) {
List<QueryAggregated> aggregs = query.getAggregatees();
List<QueryOwned> ownees = query.getOwnees();
if (aggregs.isEmpty() && ownees.isEmpty()) {
return objs;
}
if (aggregs.size() == 1) {
QueryAggregated aggreg = aggregs.get(0);
Relation rel = new Relation(RelationMode.AGGREGATION, aggreg.aggregator, aggreg.field);
for (T obj : objs) {
Util.setField(obj, info.aggregator, rel);
}
} else if (aggregs.size() > 1) {
throw new SienaException("Only one aggregation per query allowed");
}
if (ownees.size() == 1) {
// owners
QueryOwned ownee = ownees.get(0);
for (T obj : objs) {
Util.setField(obj, ownee.field, ownee.owner);
}
} else if (ownees.size() > 1) {
throw new SienaException("Only one owner per query allowed");
}
return objs;
}
Aggregations