Re: Building expression from Null strings

From: Mike Kienenberger (mkienen..laska.net)
Date: Wed Oct 13 2004 - 16:19:02 EDT

  • Next message: $B0B9>7r: "Smartest way to realize sequence PID"

    Cyril Godefroy <cgodefro..ac.com> wrote:
    > I'm trying to do something around this:
    >
    > Expression qual = generateLikeExp("firstName", getSearchFirstName());
    > qual =qual.andExp(generateLikeExp("lastName",
    > getSearchLastName()));
    > qual =qual.andExp(generateLikeExp("userName",
    > getSearchUserName()));
    > qual =qual.andExp(generateLikeExp("email", getSearchEmail()));
    > SelectQuery query = new SelectQuery(Customer.class, qual);
    > ...
    >
    > public Expression generateLikeExp(String attribute, String
    > searchString){
    > if(!searchString.equals("") && searchString != null){
    > return ExpressionFactory.likeIgnoreCaseExp(attribute, "%" +
    > searchString + "%");
    > } else {
    > return null;
    > }
    > }
    >
    > You see where this leads me... If getFirstName() returns null, then
    > andExp() cannot be called on a null object.
    >
    > Is there an obvious way to go around this problem that I am not seeing?

    Reading my 800+ email messages backwards as time permits, so I can't
    remember if someone already answered this for you.

    I add each qualifier to a List as they are created, then use this statement
    to AND them all together at the end.

                    Expression andedQualifiers = ExpressionFactory.joinExp(Expression.AND,
    qualifierList);



    This archive was generated by hypermail 2.0.0 : Wed Oct 13 2004 - 16:18:00 EDT