Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 51973CD98 for ; Fri, 1 Jun 2012 15:42:22 +0000 (UTC) Received: (qmail 365 invoked by uid 500); 1 Jun 2012 15:42:22 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 347 invoked by uid 500); 1 Jun 2012 15:42:22 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 338 invoked by uid 99); 1 Jun 2012 15:42:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 15:42:22 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of arjfandy@gmail.com designates 209.85.216.43 as permitted sender) Received: from [209.85.216.43] (HELO mail-qa0-f43.google.com) (209.85.216.43) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 15:42:15 +0000 Received: by qadb33 with SMTP id b33so599984qad.16 for ; Fri, 01 Jun 2012 08:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Img8ebk9PYii1MUb9YaRQaiWm9RhJUEOa7LWCNzPPCg=; b=NvdB+rei+wAy9Nkk9L9M1wxjWlCsTKp4L/SZ/t8V1CZNm2RoDtOC7pn/iKLQ9yRlQ8 nz2kd7tHn/oz6k4dA21OVUIYTZUyK9RTNEDmcPIa4J2/kYpX6dSPsRPSgrRjhf+t/NRD yM9M1hcQdJ/GnkELIkDKXvr1HqnhQg67x+ExMYFthgqsEjIqi/sBQxM84iIIr8s5x/bu cO2VvjQJPtdFlHKwS1v5u8q8rTfHmJ4rEX3K2GwmUepe3xWGM3B4Lq5FvtutX3sNj8sY GWLdVXIui68jVBdRcX2n2dmLi79ViFbZ0eQYW0WMVQHSblYRly7NJIQ95OEwJH+Uuicw pgoA== MIME-Version: 1.0 Received: by 10.224.189.19 with SMTP id dc19mr4638315qab.76.1338565314752; Fri, 01 Jun 2012 08:41:54 -0700 (PDT) Received: by 10.229.157.10 with HTTP; Fri, 1 Jun 2012 08:41:54 -0700 (PDT) In-Reply-To: References: Date: Fri, 1 Jun 2012 11:41:54 -0400 Message-ID: Subject: Re: Weirdnes with Expression's filterObjects results From: Andrew Faust To: user@cayenne.apache.org Content-Type: multipart/alternative; boundary=20cf3033464d182f1604c16b06d1 X-Virus-Checked: Checked by ClamAV on apache.org --20cf3033464d182f1604c16b06d1 Content-Type: text/plain; charset=ISO-8859-1 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 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 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 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 > 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 fullPersonList = ormContext.performQuery(personQuery); > > > > > > > > Expression filterExp = Expression.*fromString*(filterExpr); > > > > > > > > List 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? > > > > > > > > > > --20cf3033464d182f1604c16b06d1--