// our object is not linked to another object...so it doesn't have any key
if(objVal == null) {
continue;
}
Key key = GaeMappingUtils.getKey(objVal);
List<Key> keys = fieldMap.get(field);
if(!keys.contains(key))
keys.add(key);
}
}
Map<Field, Map<Key, Entity>> entityMap =
new HashMap<Field, Map<Key, Entity>>();
try {
// retrieves all joined entities per field
for(Field field: fieldMap.keySet()){
Future<Map<Key, Entity>> entities = ds.get(fieldMap.get(field));
// gets the future here because we need it so we wait for it
entityMap.put(field, entities.get());
}
}catch(Exception ex){
throw new SienaException(ex);
}
// associates linked models to their models
// linkedModels is just a map to contain entities already mapped
Map<Key, Object> linkedModels = new HashMap<Key, Object>();
Object linkedObj;
Entity entity;
for (final T model : models) {
for(Field field: fieldMap.keySet()){
Object objVal = Util.readField(model, field);
// our object is not linked to another object...so it doesn't have any key
if(objVal == null) {
continue;
}
Key key = GaeMappingUtils.getKey(objVal);
linkedObj = linkedModels.get(key);
if(linkedObj==null){
entity = entityMap.get(field).get(key);
linkedObj = objVal;
GaeMappingUtils.fillModel(linkedObj, entity);