Re: Negating an expression

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jan 19 2004 - 23:53:16 EST

  • Next message: Jim Menard: "Re: Negating an expression"

    Jim, Mike,

    ExpressionFactory doesn't have a shortcut method for NOT. I guess I'll
    need to add it eventually. For now you can use this:

                Expression negated =
    ExpressionFactory.unaryExp(Expression.NOT, expressionToNegate);

    Andrus

    On Jan 19, 2004, at 11:11 PM, Mike Kienenberger wrote:

    > Jim Menard <jim..o.com> wrote:
    >> I'd like to be able to build an expression that is a negation of
    >> another expression, but I can't figure out how to do so using Cayenne
    >> Expressions. In SQL, I want to do something like
    >>
    >> NOT (person.name LIKE '%Smith%' OR person.name LIKE '%Jones%')
    >>
    >> I know that I can write this as
    >>
    >> person.name NOT LIKE '%Smith%' AND person.name NOT LIKE '%Jones%'
    >>
    >> but can I build an expression the first way, with NOT?
    >>
    >> I can't simply rewrite the expressions using the latter example
    >> because
    >> I'm dynamically building an expression from smaller pieces.
    >
    > Actually, you could using Boolean logic transformations, but it'd be a
    > bit
    > more parsing work:
    >
    > [If I remember correctly....]
    >
    > NOT (A or B ...or C) = (Not A) and (Not B) ...and (Not C)
    > NOT (A and B ...and C) = (Not A) or (Not B) ...or (Not C)
    >
    > I don't remember finding a unary NOT operator, but I didn't look that
    > hard,
    > since, due to my pulldown-construction technique, it was enough that
    > every
    > expression type I used also had a negated form.
    >
    > I suspect there is one -- it's probably just not documented as well as
    > the
    > rest, so you'll need to look through the expressions source code.
    >
    > -Mike
    >



    This archive was generated by hypermail 2.0.0 : Mon Jan 19 2004 - 23:53:23 EST