cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Faust <arjfa...@gmail.com>
Subject Re: Weirdnes with Expression's filterObjects results
Date Fri, 01 Jun 2012 15:50:33 GMT
Thanks everybody.  I'm gonna switch the code over to use the
ExpressionFactory methods.  Not that big of a deal.  Appreciate it.

On Fri, Jun 1, 2012 at 11:44 AM, Michael Gentry <mgentry@masslight.net>wrote:

> Expression.fromString() does indeed take a string, but allows for
> placeholders, too:
>
>
> Expression expression = Expression.fromString("lastName = $lastName");
>
> Map parameters = new HashMap(1);
> parameters.put("lastName", "andy");
>
> SelectQuery query = new SelectQuery(Person.class,
> expression.expWithParameters(parameters));
>
>
> Should allow you to put booleans (and other values) in there, too.  In
> general, though, I agree with John that it is better (safer --
> compiler can check values) to use the ExpressionFactory.* methods.
>
> mrg
>
>
> On Fri, Jun 1, 2012 at 10:44 AM, Andrew Faust <arjfandy@gmail.com> wrote:
> > Hey John appreciate the fast response...thanks.
> >
> > So....
> >  String myFilter = "lastName = 'andy'"
> > I understand that.... However
> >  String myFilter = "isStaffMember = 'true'"
> > How do you translate that into it's "object" form as you recommended?
>  The
> > Expression.*fromString* method requires a String.  Are you suggesting I
> use
> > a different filtering method that takes objects as parametes and not
> > strings?  Thanks again..
> >
> > On Fri, Jun 1, 2012 at 10:31 AM, John Huss <johnthuss@gmail.com> wrote:
> >
> >> The string 'true' is not the same as the literal value true.  Same for
> >> dates.  You need to pass these objects in object form, not as strings.
> >>
> >> On Fri, Jun 1, 2012 at 8:59 AM, Andrew Faust <arjfandy@gmail.com>
> wrote:
> >>
> >> > Good morning everybody.  I am using the following code with (mostly)
> good
> >> > results:
> >> >
> >> >
> >> > =============================================================
> >> >
> >> > String filterExpr = "*lastName* = 'Simth';
> >> >
> >> > SelectQuery personQuery = new SelectQuery(Person.*class*);
> >> >
> >> > List<Person> fullPersonList = ormContext.performQuery(personQuery);
> >> >
> >> > Expression filterExp = Expression.*fromString*(filterExpr);
> >> >
> >> > List<Person> filteredPersonList =
> >> filterExp.filterObjects(fullPersonList);
> >> >
> >> > =============================================================
> >> >
> >> > This works well on any combination of operators such as =, >, <,
and
> so
> >> > on.  This also worrks ok with numeric fields.  So, for string and
> numeric
> >> > fields this code works ok.
> >> >
> >> >
> >> >
> >> > *HOWEVER*; when I try to filter fields that are booleans or dates
> then I
> >> *
> >> > always* get back an empty results set.  For example...
> >> >
> >> >
> >> >
> >> > Change filterExpr to *filterExpr = "isStaffMember = 'true'"* runs ok
> but
> >> > returns 0 records which is NOT correct.  Note that if I don't use the
> '
> >> > character then I get runtime EXCEPTIONS.
> >> >
> >> > Change filterExpr to *filterExpr = "startDate = '2012-02-01'" *again
> runs
> >> > ok but returns 0 records which is NOT correct.
> >> >
> >> >
> >> >
> >> > Here are some of my runtime particulars:
> >> >
> >> > JDK/JRE: 1.6.0_31
> >> >
> >> > Cayenne version: 3.0.2
> >> >
> >> > DerbyDB version: 10.8.1.2
> >> >
> >> > The database/java fields are: String=VARCHAR/String; numbers are
> >> > integer/Integer; dates are DATE/Date; and booleans are
> boolean/Boolean.
> >> >
> >> >
> >> >
> >> > In summary, the filterExpFilterObjects(...) seems to work fine IF the
> >> > fields are strings or numbers; but is NOT working as expected with
> Dates
> >> or
> >> > Booleans.  Any ideas anyone?
> >> >
> >>
>

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