Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 2057 invoked from network); 27 Mar 2009 16:48:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Mar 2009 16:48:18 -0000 Received: (qmail 57346 invoked by uid 500); 27 Mar 2009 16:48:18 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 57333 invoked by uid 500); 27 Mar 2009 16:48:18 -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 57323 invoked by uid 99); 27 Mar 2009 16:48:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 16:48:18 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.221.136] (HELO mail-qy0-f136.google.com) (209.85.221.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 16:48:12 +0000 Received: by qyk42 with SMTP id 42so2075155qyk.26 for ; Fri, 27 Mar 2009 09:47:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.82.76 with SMTP id a12mr1081987qcl.7.1238172469695; Fri, 27 Mar 2009 09:47:49 -0700 (PDT) In-Reply-To: <479ffcd60903262019x3cfe35e2u256337f69b9f74f4@mail.gmail.com> References: <479ffcd60903260955l770d113aw6dde67e89d31de88@mail.gmail.com> <3219fff70903261233n69492272lbb9e9632572f6118@mail.gmail.com> <479ffcd60903262019x3cfe35e2u256337f69b9f74f4@mail.gmail.com> Date: Fri, 27 Mar 2009 12:47:49 -0400 Message-ID: <5adb61290903270947qfb200a5u3ca034475499c263@mail.gmail.com> Subject: Re: Internal row comparison in ExpressionFactory From: Michael Gentry To: user@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Use "likeIgnoreCase" instead of "like" ... On Thu, Mar 26, 2009 at 11:19 PM, John Armstrong wrote= : > I couldn't quite get the EJBQL syntax right so I ended up using fromStrin= g > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Expression qual =3D Expression.fromString(= "code like $license and > claimedunits < totalunits"); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0java.util.Map params =3D new java.util.Has= hMap(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0params.put("license", licenseCode.trim()); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0SelectQuery query =3D new SelectQuery(Lice= nse.class, > qual).queryWithParameters(params); > > Seemed to work although I need to tweak the like for case > insensitivity. I'll do that tomorrow. > > Thanks- > John- > > On Thu, Mar 26, 2009 at 12:33 PM, Andrey Razumovsky > wrote: >> Hi John, >> >> You should try EJBQL: >> select t0 from License t0 where t0.claimedunits < t0.totalunits AND .... >> >> http://cayenne.apache.org/doc/ejbqlquery.html >> >> 2009/3/26 John Armstrong >> >>> Hi, I need to do a selection on a table partially based on comparing >>> two elements >>> of that table. Basically a 'total' and a 'current' where total is a >>> changing value and needs to be compared to current to see if the row >>> is valid. Its a floating license system for an app I am building. >>> >>> This obviously does not work since it expects a numeric, not a string, >>> in the value: >>> >>> Expression qual =3D ExpressionFactory.likeIgnoreCaseExp( >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0com.pgi.Lice= nse.CODE_PROPERTY, >>> licenseCode.trim()) >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.andExp( >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0ExpressionFactory.lessExp( >>> >>> com.pgi.License.CLAIMEDUNITS_PROPERTY, >>> >>> com.pgi.License.TOTALUNITS_PROPERTY)); >>> >>> How can I get to to generate SQL like this : >>> >>> SELECT t0.license, t0.code, t0.licensetype, t0.product, t0.id, >>> t0.validfrom, t0.totalunits, t0.user, t0.validto, t0.datecreated, >>> t0.claimedunits FROM license t0 WHERE (UPPER(t0.code) LIKE >>> UPPER('7GEN-BTPTDF')) AND (t0.claimedunits < t0.totalunits); >>> >>> How would I structure an Expression so that it does an internal >>> comparison. I know an SQLTemplate can do it, is this one of those >>> times that ExpressionFactory is not really suited to the task? >>> >>> >>> J >>> >> >