public SienaFuture<Void> save(final Object obj) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
final Field idField = info.getIdField();
final Entity entity;
final Object idVal = Util.readField(obj, idField);
// id with null value means insert
if(idVal == null){
entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
}
// id with not null value means update
else{
entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);
}
GaeMappingUtils.fillEntity(obj, entity);
Future<Key> future = ds.put(entity);
Future<Void> wrapped = new SienaFutureWrapper<Key, Void>(future) {
@Override
protected Void wrap(Key generatedKey) throws Exception
{
if(idVal == null){
GaeMappingUtils.setIdFromKey(idField, obj, entity.getKey());
}
return null;
}
};