use of siena.ClassInfo in project siena by mandubian.
the class GaeMappingUtils method getKey.
public static Key getKey(Object obj) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
try {
Field idField = info.getIdField();
Object value = Util.readField(obj, idField);
// TODO verify that returning NULL is not a bad thing
if (value == null)
return null;
Class<?> type = idField.getType();
if (idField.isAnnotationPresent(Id.class)) {
Id id = idField.getAnnotation(Id.class);
switch(id.value()) {
case NONE:
// long or string goes toString
return KeyFactory.createKey(ClassInfo.getClassInfo(clazz).tableName, value.toString());
case AUTO_INCREMENT:
// as a string with auto_increment can't exist, it is not cast into long
if (Long.TYPE == type || Long.class.isAssignableFrom(type)) {
return KeyFactory.createKey(ClassInfo.getClassInfo(clazz).tableName, (Long) value);
}
return KeyFactory.createKey(ClassInfo.getClassInfo(clazz).tableName, value.toString());
case UUID:
return KeyFactory.createKey(ClassInfo.getClassInfo(clazz).tableName, value.toString());
default:
throw new SienaException("Id Generator " + id.value() + " not supported");
}
} else
throw new SienaException("Field " + idField.getName() + " is not an @Id field");
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.ClassInfo in project siena by mandubian.
the class PersistenceManagerLifeCycleWrapper method get.
@Override
public void get(Object obj) {
ClassInfo ci = ClassInfo.getClassInfo(obj.getClass());
LifeCycleUtils.executeMethods(LifeCyclePhase.PRE_FETCH, ci, obj);
pm.get(obj);
LifeCycleUtils.executeMethods(LifeCyclePhase.POST_FETCH, ci, obj);
}
use of siena.ClassInfo in project siena by mandubian.
the class PersistenceManagerLifeCycleWrapper method update.
@Override
public void update(Object obj) {
ClassInfo ci = ClassInfo.getClassInfo(obj.getClass());
LifeCycleUtils.executeMethods(LifeCyclePhase.PRE_UPDATE, ci, obj);
pm.update(obj);
LifeCycleUtils.executeMethods(LifeCyclePhase.POST_UPDATE, ci, obj);
}
use of siena.ClassInfo in project siena by mandubian.
the class PersistenceManagerLifeCycleWrapper method save.
@Override
public void save(Object obj) {
ClassInfo ci = ClassInfo.getClassInfo(obj.getClass());
LifeCycleUtils.executeMethods(LifeCyclePhase.PRE_SAVE, ci, obj);
pm.save(obj);
LifeCycleUtils.executeMethods(LifeCyclePhase.POST_SAVE, ci, obj);
}
use of siena.ClassInfo 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);
}
}
}
Aggregations