use of siena.Query 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.Query 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.Query in project siena by mandubian.
the class GaePersistenceManager method fillAggregated.
protected <T> void fillAggregated(ClassInfo info, T ancestor, Key ancestorKey) {
// now gets aggregated one2one (one2many are retrieved by ListQuery except with @Join)
for (Field f : info.aggregatedFields) {
Class<?> cClazz = f.getType();
ClassInfo cInfo = ClassInfo.getClassInfo(cClazz);
if (ClassInfo.isModel(cClazz)) {
// creates a query for fieldname:child_tablename
com.google.appengine.api.datastore.Query q = new com.google.appengine.api.datastore.Query(GaeMappingUtils.getKindWithAncestorField(cInfo, info, f));
PreparedQuery pq = ds.prepare(q.setAncestor(ancestorKey));
Entity cEntity = pq.asSingleEntity();
Object cObj = Util.createObjectInstance(cClazz);
GaeMappingUtils.fillModelAndKey(cObj, cEntity);
Util.setField(ancestor, f, cObj);
} else // todo manage joined one2many listquery
if (ClassInfo.isMany(f)) {
Many4PM<?> lq = (Many4PM<?>) Util.readField(ancestor, f);
// sets the sync flag to false to tell that it should be fetched when the listquery is accessed!
lq.setSync(false);
}
}
}
Aggregations