public SienaFuture<Integer> save(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;
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);
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
{
int i=0;
for(Object obj:objects){
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
Object idVal = Util.readField(obj, idField);
if(idVal == null){
GaeMappingUtils.setIdFromKey(idField, obj, keys.get(i++));
}
}