Re: missing property, but no error

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Fri Apr 29 2005 - 15:13:58 EDT

  • Next message: Sami Mohammed: "Re: missing property, but no error"

    On Apr 29, 2005, at 1:51 PM, Gentry, Michael (Contractor) wrote:

    > I've not used ExpressionFactory (I tend to stick to just Expression),
    > but you do have the option with an Expression when supplying a map to
    > omit parameters and it'll drop those out of the query. For example:
    >
    > "foo = $foo and bar = $bar"
    >
    > If you only supply $foo, your query will become "foo = $foo" (it'll
    > omit
    > the bar query). There is an option to control this and I suspect your
    > issue is closely related to this feature, but if I'm wrong someone will
    > correct me. :-)
    >
    > Actually, that brings me to the question ... Why not just use an
    > Expression?
    >
    > final Expression expression =
    > Expression.fromString("username = $username and password =
    > $password");
    > Map map = new HashMap(2);
    > map.put("username", username);
    > map.put("password", password);
    > SelectQuery query = new SelectQuery(User.class,
    > expression.expWithParameters(map));
    >
    > Of course, yours does look tighter. :-) I'm not sure which is
    > fastest.

    In your code, though, you've duplicated "username" several times -
    imagine the effect of a typo. I prefer to stay DRY (Don't Repeat
    Yourself mantra I've learned to love from Dave Thomas and the Pragmatic
    Programmer book). In fact, I'd like to even get rid of "username" in
    my code and use the User.USERNAME_PROPERTY constant to keep the
    information completely in the Cayenne mapping files :)

            Erik

    >
    > /dev/mrg
    >
    >
    > -----Original Message-----
    > From: Erik Hatcher [mailto:eri..hatchersolutions.com]
    > Sent: Friday, April 29, 2005 1:29 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: missing property, but no error
    >
    >
    > I wrote code like this:
    >
    > Expression expression = ExpressionFactory.matchExp("username",
    > username);
    > expression.andExp(ExpressionFactory.matchExp("password",
    > password));
    > SelectQuery query = new SelectQuery(User.class, expression);
    >
    > But I had not yet modeled the "password" attribute, or even the DB
    > column. Yet this code executed fine with no errors at all. Why is
    > that? Shouldn't I have gotten an error?
    >
    > Thanks,
    > Erik



    This archive was generated by hypermail 2.0.0 : Fri Apr 29 2005 - 15:14:31 EDT