use of siena.core.Relation 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.core.Relation in project siena by mandubian.
the class GaePersistenceManager method update.
public void update(Object obj) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
if (info.hasAggregator) {
Relation rel = (Relation) Util.readField(obj, info.aggregator);
if (rel != null && rel.mode == RelationMode.AGGREGATION) {
ClassInfo parentInfo = ClassInfo.getClassInfo(rel.target.getClass());
Key parentKey = GaeMappingUtils.makeKey(parentInfo, rel.target);
if (!info.hasAggregatedFields && !info.hasOwnedFields) {
_updateSimple(obj, info, parentKey, parentInfo, (Field) rel.discriminator);
} else {
_updateComplex(obj, parentKey, parentInfo, (Field) rel.discriminator);
}
} else {
if (!info.hasAggregatedFields && !info.hasOwnedFields) {
_updateSimple(obj, info, null, null, null);
} else {
_updateComplex(obj, null, null, null);
}
}
} else {
if (!info.hasAggregatedFields && !info.hasOwnedFields) {
_updateSimple(obj, info, null, null, null);
} else {
_updateComplex(obj, null, null, null);
}
}
}
use of siena.core.Relation in project siena by mandubian.
the class GaePersistenceManager method delete.
public void delete(Object obj) {
List<Key> keys = new ArrayList<Key>();
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
if (info.hasAggregator) {
Relation rel = (Relation) Util.readField(obj, info.aggregator);
if (rel != null && rel.mode == RelationMode.AGGREGATION) {
ClassInfo parentInfo = ClassInfo.getClassInfo(rel.target.getClass());
Key parentKey = GaeMappingUtils.makeKey(parentInfo, rel.target);
_deleteSingle(obj, keys, parentKey, parentInfo, (Field) rel.discriminator);
} else {
_deleteSingle(obj, keys, null, null, null);
}
} else {
_deleteSingle(obj, keys, null, null, null);
}
ds.delete(keys);
}
use of siena.core.Relation in project siena by mandubian.
the class GaePersistenceManager method _updateMultiple.
private <T> int _updateMultiple(Iterable<T> objects) {
HashMap<PersistenceType, List<Entity>> entitiesMap = new HashMap<PersistenceType, List<Entity>>();
HashMap<PersistenceType, List<Object>> objectsMap = new HashMap<PersistenceType, List<Object>>();
HashMap<PersistenceType, List<Key>> keysMap = new HashMap<PersistenceType, List<Key>>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
if (info.hasAggregator) {
Relation rel = (Relation) Util.readField(obj, info.aggregator);
if (rel != null && rel.mode == RelationMode.AGGREGATION) {
ClassInfo parentInfo = ClassInfo.getClassInfo(rel.target.getClass());
Key parentKey = GaeMappingUtils.makeKey(parentInfo, rel.target);
_updateBuildMaps(entitiesMap, objectsMap, keysMap, obj, parentKey, parentInfo, (Field) rel.discriminator);
} else {
_updateBuildMaps(entitiesMap, objectsMap, keysMap, obj, null, null, null);
}
} else {
_updateBuildMaps(entitiesMap, objectsMap, keysMap, obj, null, null, null);
}
}
return _updateManageMaps(entitiesMap, objectsMap, keysMap);
}
use of siena.core.Relation in project siena by mandubian.
the class GaePersistenceManager method _insertMultiple.
private <T> int _insertMultiple(Iterable<T> objects) {
List<Entity> entities = new ArrayList<Entity>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
if (info.hasAggregator) {
Relation rel = (Relation) Util.readField(obj, info.aggregator);
if (rel != null && rel.mode == RelationMode.AGGREGATION) {
ClassInfo parentInfo = ClassInfo.getClassInfo(rel.target.getClass());
Key parentKey = GaeMappingUtils.makeKey(parentInfo, rel.target);
_insertAddEntity(entities, obj, info, parentKey, parentInfo, (Field) rel.discriminator);
} else {
_insertAddEntity(entities, obj, info, null, null, null);
}
} else {
_insertAddEntity(entities, obj, info, null, null, null);
}
}
return _insertPutEntities(entities, objects);
}
Aggregations