cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Razumovsky <razumovsky.and...@gmail.com>
Subject Re: Context question
Date Fri, 15 Oct 2010 08:24:09 GMT
Hi Mathias,

The main reason why 1) and 3) cannot be done is that SelectQuery (and almost
any other fetching query) should support fetch size/limit and paging. This
makes "local" data useless, because we don't know where insert it to.

The reason of 2) is that Cayenne uses caching of data objects, which greatly
increases performance. So object is basically the same. You can "refresh"
the cache using RefreshQuery.

Hope that helps,

2010/10/15 Mathias Clerc <tlarhices@gmail.com>

> 2010/10/15 Andrey Razumovsky <razumovsky.andrey@gmail.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.
>



-- 
Andrey

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message