Search in sources :

Example 6 with Relation

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);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Relation(siena.core.Relation) ArrayList(java.util.ArrayList) Key(com.google.appengine.api.datastore.Key) ClassInfo(siena.ClassInfo)

Example 7 with Relation

use of siena.core.Relation 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);
    }
}
Also used : Relation(siena.core.Relation) Key(com.google.appengine.api.datastore.Key) ClassInfo(siena.ClassInfo)

Aggregations

Relation (siena.core.Relation)7 Key (com.google.appengine.api.datastore.Key)5 ClassInfo (siena.ClassInfo)5 ArrayList (java.util.ArrayList)3 Entity (com.google.appengine.api.datastore.Entity)2 QueryAggregated (siena.QueryAggregated)2 QueryOwned (siena.QueryOwned)2 SienaException (siena.SienaException)2 QueryResultList (com.google.appengine.api.datastore.QueryResultList)1 HashMap (java.util.HashMap)1 List (java.util.List)1