Re: Internal row comparison in ExpressionFactory

From: John Armstrong (siberia..mail.com)
Date: Thu Mar 26 2009 - 23:19:07 EDT

  • Next message: Joseph Schmidt: "Relationships without FK constraints?"

    I couldn't quite get the EJBQL syntax right so I ended up using fromString

                    Expression qual = Expression.fromString("code like $license and
    claimedunits < totalunits");
                    java.util.Map params = new java.util.HashMap();
                    params.put("license", licenseCode.trim());
                    SelectQuery query = new SelectQuery(License.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
    <razumovsky.andre..mail.com> 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 <siberia..mail.com>
    >
    >> 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 = ExpressionFactory.likeIgnoreCaseExp(
    >>                              com.pgi.License.CODE_PROPERTY,
    >> licenseCode.trim())
    >>                              .andExp(
    >>                                              ExpressionFactory.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
    >>
    >



    This archive was generated by hypermail 2.0.0 : Thu Mar 26 2009 - 23:19:38 EDT