use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method _deleteSingle.
private void _deleteSingle(Object obj, List<Key> keys, final Key parentKey, final ClassInfo parentInfo, final Field parentField) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Key key;
if (parentKey == null) {
key = GaeMappingUtils.getKey(obj);
} else {
key = GaeMappingUtils.getKeyFromParent(obj, parentKey, parentInfo, parentField);
}
// cascading on aggregated fields
if (!info.aggregatedFields.isEmpty()) {
for (Field f : info.aggregatedFields) {
if (ClassInfo.isModel(f.getType())) {
Object aggObj = Util.readField(obj, f);
_deleteSingle(aggObj, keys, key, info, f);
} else if (ClassInfo.isMany(f)) {
Many<?> lq = (Many<?>) Util.readField(obj, f);
if (!lq.asList().isEmpty()) {
_deleteMultiple(lq.asQuery().fetchKeys(), keys, key, info, f);
}
}
}
}
keys.add(key);
}
use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method _insertSingle.
private <T> void _insertSingle(T 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);
_insertSingle(obj, parentKey, rel.target, parentInfo, (Field) rel.discriminator);
} else {
_insertSingle(obj, null, null, null, null);
}
} else {
_insertSingle(obj, null, null, null, null);
}
}
use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method _updateSimpleMultiple.
private <T> void _updateSimpleMultiple(Iterable<T> objs, Key parentKey, ClassInfo parentInfo, Field parentField) {
List<Entity> entities = new ArrayList<Entity>();
ClassInfo info = null;
Field idField = null;
for (T obj : objs) {
if (info == null) {
info = ClassInfo.getClassInfo(obj.getClass());
idField = info.getIdField();
}
Entity entity;
Object idVal = Util.readField(obj, idField);
// id with null value means insert
if (idVal == null) {
if (parentKey == null) {
entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
} else {
entity = GaeMappingUtils.createEntityInstanceFromParent(idField, info, obj, parentKey, parentInfo, parentField);
}
GaeMappingUtils.fillEntity(obj, entity);
} else {
if (parentKey == null) {
entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);
} else {
entity = GaeMappingUtils.createEntityInstanceForUpdateFromParent(info, obj, parentKey, parentInfo, parentField);
}
GaeMappingUtils.fillEntity(obj, entity);
}
entities.add(entity);
}
if (!entities.isEmpty()) {
ds.put(entities);
}
}
use of siena.ClassInfo in project siena by mandubian.
the class PersistenceManagerLifeCycleWrapper method delete.
@Override
public void delete(Object obj) {
ClassInfo ci = ClassInfo.getClassInfo(obj.getClass());
LifeCycleUtils.executeMethods(LifeCyclePhase.PRE_DELETE, ci, obj);
pm.delete(obj);
LifeCycleUtils.executeMethods(LifeCyclePhase.POST_DELETE, ci, obj);
}
use of siena.ClassInfo in project siena by mandubian.
the class PersistenceManagerLifeCycleWrapper method get.
@Override
public <T> T get(Query<T> query) {
ClassInfo ci = ClassInfo.getClassInfo(query.getQueriedClass());
T obj = pm.get(query);
LifeCycleUtils.executeMethods(LifeCyclePhase.POST_FETCH, ci, obj);
return obj;
}
Aggregations