Re: Context question

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Oct 15 2010 - 08:22:47 UTC

  • Next message: Andrey Razumovsky: "Re: Context question"

    Getting used to ObjectContext may take some time when coming from other ORM backgrounds, but in general most people have a rather smooth ride with it.

    While I can theoretically see a value of (optionally?) selecting against uncommitted objects, I've never had a practical case for it in my apps. Which can be attributed to the way how I am designing persistent code with ObjectContext behavior in mind. So... maybe you can explain the problem you are trying to solve, and we can think of a better solution?

    Andrus

    On Oct 15, 2010, at 11:09 AM, Mathias Clerc wrote:

    > 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:23:19 UTC