Search in sources :

Example 41 with ClassInfo

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);
}
Also used : Field(java.lang.reflect.Field) Many(siena.core.Many) Key(com.google.appengine.api.datastore.Key) ClassInfo(siena.ClassInfo)

Example 42 with ClassInfo

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

Example 43 with ClassInfo

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

Example 44 with ClassInfo

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);
}
Also used : ClassInfo(siena.ClassInfo)

Example 45 with ClassInfo

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;
}
Also used : ClassInfo(siena.ClassInfo)

Aggregations

ClassInfo (siena.ClassInfo)68 Field (java.lang.reflect.Field)33 ArrayList (java.util.ArrayList)24 Key (com.google.appengine.api.datastore.Key)23 SienaException (siena.SienaException)21 Entity (com.google.appengine.api.datastore.Entity)17 QueryResultList (com.google.appengine.api.datastore.QueryResultList)10 List (java.util.List)10 DeletableItem (com.amazonaws.services.simpledb.model.DeletableItem)6 Item (com.amazonaws.services.simpledb.model.Item)6 ReplaceableItem (com.amazonaws.services.simpledb.model.ReplaceableItem)6 SQLException (java.sql.SQLException)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 SienaRestrictedApiException (siena.SienaRestrictedApiException)5 Relation (siena.core.Relation)5 IOException (java.io.IOException)4 QueryFilterSearch (siena.QueryFilterSearch)4 Many4PM (siena.core.Many4PM)4 SienaFutureContainer (siena.core.async.SienaFutureContainer)4