Re: Interesting behaviour of filterObjects()

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Jul 16 2004 - 17:15:43 EDT

  • Next message: Andrus Adamchik: "[DONE] Re: Simple retrieval of an object by PK"

    Good observation... This is the expected behavior (in a sense that this
    is not a bug in the code), the question remains though how much sense
    it makes, or is it too confusing to the end user.

    Expressions do not perform types conversions mainly for performance
    reasons. I guess we should leave them alone, as this is pretty
    consistent.

    DataObjects do not throw an exception when a property is not mapped,
    but doing filterObjects() with regular Java Beans will result in
    reflection exceptions - so there is some inconsistency. I guess we may
    need to change DataObject behavior at some point by checking key names
    against ObjEntity. Need to figure out a way to do that without killing
    the performance.

    I guess for now mentioning this behavior in the docs will be a good
    thing to do.

    Andrus

    On Jul 14, 2004, at 8:30 PM, Gary Jarrel wrote:

    > Hi All!
    >
    > Maybe this is my illogical thinking but I found the following behavior
    > of
    > Expression.filterObjects() method somewhat interesting.
    >
    > I've got a list of Cayenne DataObjects cached in my DataContext. This
    > is a
    > list of "Modules" and module represents an entry in "module" table of
    > the
    > database.
    >
    > List list = ctx.performQuery("ModuleCache", false);
    >
    > Then say for example I've got a module id being 9 for example. The
    > ModuleCache has an entry with id 9 and the module class has a field
    > "moduleId"
    >
    > Say for example you set:
    >
    > String modId = "9";
    >
    > Then you create an expression:
    >
    > Expression exp = ExpressionFactory.matchExp("moduleId", modId);
    >
    > And call
    >
    > List singleModuleList = exp.filterObjects(completeList);
    >
    > The singleModuleList is of zero length. Now the reason although pretty
    > obvious is not very intuitive. It's simply because my moduleId field
    > in the
    > Module class is an Integer. I would have expected to have some sort of
    > a
    > type exception thrown rather than return an empty list. The solution
    > for me
    > was to create an expression as:
    >
    > Expression exp = ExpressionFactory.matchExp("moduleId", new
    > Integer(modId));
    >
    > The other interesting side effect I found was the creation of the
    > expression
    > as follows:
    >
    > Expression exp = ExpressionFactory.matchExp("moduled", new
    > Integer(modId));
    >
    > Notice the spelling as "moduled" rather than "moduleId". If you call a
    > filterObject method on this expression it also silently returns an
    > empty
    > list, rather than throwing an Exception notifying that the field does
    > not
    > exist.
    >
    > Anyway, sorry for the lengthy email, but though I'd point out this
    > simple
    > fact. Not 100% sure whether this behavior is expected.
    >
    > - Gary



    This archive was generated by hypermail 2.0.0 : Fri Jul 16 2004 - 17:15:49 EDT