use of siena.core.async.SienaFutureWrapper in project siena by mandubian.
the class GaePersistenceManagerAsync method get.
public SienaFuture<Void> get(final Object obj) {
final Key key = GaeMappingUtils.getKey(obj);
Future<Entity> future = ds.get(key);
Future<Void> wrapped = new SienaFutureWrapper<Entity, Void>(future) {
@Override
protected Void wrap(Entity entity) throws Exception {
GaeMappingUtils.fillModel(obj, entity);
return null;
}
};
return new SienaFutureContainer<Void>(wrapped);
}
use of siena.core.async.SienaFutureWrapper in project siena by mandubian.
the class GaePersistenceManagerAsync method insert.
public SienaFuture<Integer> insert(final Iterable<?> objects) {
List<Entity> entities = new ArrayList<Entity>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
Entity entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
GaeMappingUtils.fillEntity(obj, entity);
entities.add(entity);
}
Future<List<Key>> future = ds.put(entities);
Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {
@Override
protected Integer wrap(List<Key> generatedKeys) throws Exception {
int i = 0;
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
GaeMappingUtils.setIdFromKey(idField, obj, generatedKeys.get(i++));
}
return generatedKeys.size();
}
};
return new SienaFutureContainer<Integer>(wrapped);
}
use of siena.core.async.SienaFutureWrapper in project siena by mandubian.
the class GaePersistenceManagerAsync method update.
@Override
public SienaFuture<Integer> update(Object... objects) {
// throw new NotImplementedException("update not implemented for GAE yet");
List<Entity> entities = new ArrayList<Entity>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Entity entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);
GaeMappingUtils.fillEntity(obj, entity);
entities.add(entity);
}
Future<List<Key>> future = ds.put(entities);
Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {
@Override
protected Integer wrap(List<Key> keys) throws Exception {
return keys.size();
}
};
return new SienaFutureContainer<Integer>(wrapped);
}
use of siena.core.async.SienaFutureWrapper in project siena by mandubian.
the class GaePersistenceManagerAsync method getByKey.
public <T> SienaFuture<T> getByKey(final Class<T> clazz, final Object key) {
Key gkey = GaeMappingUtils.makeKeyFromId(clazz, key);
try {
Future<Entity> future = ds.get(gkey);
Future<T> wrapped = new SienaFutureWrapper<Entity, T>(future) {
@Override
protected T wrap(Entity entity) throws Exception {
T obj = Util.createObjectInstance(clazz);
GaeMappingUtils.fillModelAndKey(obj, entity);
return obj;
}
};
return new SienaFutureContainer<T>(wrapped);
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.core.async.SienaFutureWrapper in project siena by mandubian.
the class GaePersistenceManagerAsync method update.
@Override
public <T> SienaFuture<Integer> update(Iterable<T> objects) {
// throw new NotImplementedException("update not implemented for GAE yet");
List<Entity> entities = new ArrayList<Entity>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Entity entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);
GaeMappingUtils.fillEntity(obj, entity);
entities.add(entity);
}
Future<List<Key>> future = ds.put(entities);
Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {
@Override
protected Integer wrap(List<Key> keys) throws Exception {
return keys.size();
}
};
return new SienaFutureContainer<Integer>(wrapped);
}
Aggregations