cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mathias Clerc <>
Subject Re: Context question
Date Fri, 15 Oct 2010 08:09:24 GMT
2010/10/15 Andrey Razumovsky <>:
> SelectQuery is actually a query to database, so viewing not-yet-inserted
> objects with it is not possible. See recent discussion:

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)) {
        //Remove any object deleted
        for (Object o : context.deletedObjects()) {
            if (objects.contains(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.

View raw message