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:41:54 GMT
Ok I see where you're going with this.  I can alter my code to work that
way.  Appreciate it John.

On Fri, Jun 1, 2012 at 10:54 AM, John Huss <johnthuss@gmail.com> wrote:

> Use ExpressionFactory.matchExp instead.  Building any sort of expression
> from strings is a bad idea in my opinion.
>
> On Fri, Jun 1, 2012 at 9: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