2010/10/15 Andrey Razumovsky <razumovsky.andre..mail.com>:
> SelectQuery is actually a query to database, so viewing not-yet-inserted
> objects with it is not possible. See recent discussion:
> http://cayenne.markmail.org/search/%20list:org.apache.cayenne.user#query:%20list%3Aorg.apache.cayenne.user+page:2+mid:6bwqse4t4czj73zq+state:results
Thank you for your answers Borut and Andrey.
I was able to do what I wanted through this hackish way :
private static List updateContentWithCurrentState(List objects,
Class<?> objectClass, Expression e,
ObjectContext context) {
//Add new objects matching the class (limits in hierarchy, see
isInstance doc)
for (Object o : context.newObjects()) {
if (objectClass.isInstance(o)) {
objects.add(o);
}
}
//Remove any object deleted
for (Object o : context.deletedObjects()) {
if (objects.contains(o)) {
objects.remove(o);
}
}
//Apply filter (to remove non matching objects added at the beggining)
if (e != null) {
objects = e.filterObjects(objects);
}
return objects;
}
Maybe it will not work in all cases, I am still early beginer but for
my tests it was enough.
I am still puzzled by standard behaviour :
1) Doing context.newObject(objectClass) and then selecting doesn't
show the new object
2) Doing a ((MyClass)context.preformQuery().get(0)).setName("new") and
then selecting will return an object with the new name
3) Doingcontext.deleteObject(object) and then selecting still returns
the original object
In 1) and 3) data is returned as it is in the db, but not in the
context (DB snapshot)
In 2) data is returned as it is in the context, but not anymore in the
db (non DB snapshot)
Quite confusing.
This archive was generated by hypermail 2.0.0 : Fri Oct 15 2010 - 08:10:16 UTC