use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method delete.
public <T> int delete(Query<T> query) {
final ArrayList<Key> keys = new ArrayList<Key>();
Class<?> clazz = query.getQueriedClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
if (!info.hasAggregatedFields) {
for (final Entity entity : prepareKeysOnly(query).asIterable(FetchOptions.Builder.withDefaults())) {
keys.add(entity.getKey());
}
} else {
// if aggregated fields, needs to retrieve all objects to scan & delete aggregated children
List<T> models = query.fetch();
_deleteMultiple(models, keys, null, null, null);
}
ds.delete(keys);
return keys.size();
}
use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method mapOwned.
protected <T> T mapOwned(T model) {
Class<?> clazz = model.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
for (Field f : info.ownedFields) {
if (ClassInfo.isOne(f)) {
One4PM<?> lq = (One4PM<?>) Util.readField(model, f);
// sets the sync flag to false to tell that it should be fetched when the listquery is accessed!
lq.setSync(false);
} 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 listquery is accessed!
lq.setSync(false);
}
}
return model;
}
use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method save.
public int save(Iterable<?> objects) {
List<Object> entities2Insert = new ArrayList<Object>();
List<Object> entities2Update = new ArrayList<Object>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
Object idVal = Util.readField(obj, idField);
// id with null value means insert
if (idVal == null) {
entities2Insert.add(obj);
} else // id with not null value means update
{
entities2Update.add(obj);
}
}
return insert(entities2Insert) + update(entities2Update);
}
use of siena.ClassInfo in project siena by mandubian.
the class GaePersistenceManager method _insertPutEntities.
private <T> int _insertPutEntities(Iterable<Entity> entities, Iterable<T> objects) {
List<Key> generatedKeys = ds.put(entities);
int i = 0;
Map<Key, Map<Field, List<Object>>> keyMap = new HashMap<Key, Map<Field, List<Object>>>();
List<ClassInfo> infos = new ArrayList<ClassInfo>();
List<Object> relObjects = new ArrayList<Object>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
GaeMappingUtils.setIdFromKey(idField, obj, generatedKeys.get(i));
if (info.hasAggregatedFields) {
infos.add(info);
Map<Field, List<Object>> objectMap = new HashMap<Field, List<Object>>();
keyMap.put(generatedKeys.get(i), objectMap);
_populateAggregateFieldMap(objectMap, info, obj);
}
if (info.hasOwnedFields) {
_populateOwnedList(relObjects, info, obj);
}
i++;
}
if (!keyMap.isEmpty()) {
_insertMultipleMapFromParent(keyMap, infos);
}
if (!relObjects.isEmpty()) {
// uses save because we don't know if the objects where already saved or not
save(relObjects);
}
return generatedKeys.size();
}
use of siena.ClassInfo 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);
}
Aggregations