use of siena.core.Many4PM in project siena by mandubian.
the class GaePersistenceManager method mapAggregated.
protected <T> T mapAggregated(T model) {
Class<?> clazz = model.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
// if there is NO listquery, we use the kindless request
for (Field f : info.aggregatedFields) {
//ClassInfo fInfo = ClassInfo.getClassInfo(fClazz);
if (ClassInfo.isOne(f)) {
One4PM<?> one = (One4PM<?>) Util.readField(model, f);
// sets the sync flag to false to tell that it should be fetched when the one is accessed!
one.setSync(false);
//hasOneMany = true;
} else if (ClassInfo.isMany(f)) {
Many4PM<?> lq = (Many4PM<?>) Util.readField(model, f);
// sets the sync flag to false to tell that it should be fetched when the many is accessed!
lq.setSync(false);
//hasOneMany = true;
}
}
/*if(!hasOneMany){
// creates a kindless query to retrieve all subentities at once.
com.google.appengine.api.datastore.Query q =
new com.google.appengine.api.datastore.Query();
Key parentKey = GaeMappingUtils.getKey(model);
q.setAncestor(parentKey);
// this removes the parent from query
q.addFilter(Entity.KEY_RESERVED_PROPERTY,
com.google.appengine.api.datastore.Query.FilterOperator.GREATER_THAN,
parentKey);
PreparedQuery pq = ds.prepare(q);
List<Entity> childEntities = pq.asList(FetchOptions.Builder.withDefaults());
for(Field f: modelMap.keySet()){
Class<?> fClazz = f.getType();
ClassInfo fInfo = modelMap.get(f);
String kind = GaeMappingUtils.getKindWithAncestorField(fInfo, info, f);
Entity found = null;
for(Entity e: childEntities){
if(kind.equals(e.getKind())){
found = e;
childEntities.remove(e);
break;
}
}
if(found != null){
Object fObj = GaeMappingUtils.mapEntity(found, fClazz);
Util.setField(model, f, fObj);
}
}
}
else {
for(Field f: modelMap.keySet()){
Class<?> fClazz = f.getType();
ClassInfo fInfo = modelMap.get(f);
String kind = GaeMappingUtils.getKindWithAncestorField(fInfo, info, f);
com.google.appengine.api.datastore.Query q =
new com.google.appengine.api.datastore.Query(kind);
Key parentKey = GaeMappingUtils.getKey(model);
q.setAncestor(parentKey);
PreparedQuery pq = ds.prepare(q);
Entity childEntity = pq.asSingleEntity();
Object fObj = GaeMappingUtils.mapEntity(childEntity, fClazz);
Util.setField(model, f, fObj);
}
}*/
return model;
}
Aggregations