Re: How does noMatchExp() work?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jul 26 2004 - 16:16:13 EDT

  • Next message: McDaniel, Joe R.: "RE: Ordering string represntations of numbers"

    Hi David,

    > qualifier = qualifier.andExp(ExpressionFactory.noMatchExp(
    > Packages.ID_PK_COLUMN, skipthis));

    > This query fails when the 'noMatchExp' is included in the qualifier.
    > What am
    > I doing wrong?

    You don't show what "fails" means. This can be many different things.
    But still let me guess by looking at the code... "noMatchExp" does a
    match based on Java Class properties; Packages.ID_PK_COLUMN is a
    database table column... So there is a conflict, as Cayenne thinks that
    Packages.ID_PK_COLUMN is a class property and it isn't.

    So how do we build the right expression... You may have noticed that
    there is an ExpressionFactory.matchExp(..) and
    ExpressionFactory.matchDbExp(..), but there is no
    ExpressionFactory.noMatchDbExp(..). This was overlooked and we may add
    it some day. For now you can rewrite the whole expression using string
    Expression API, distinguishing between DB columns and object properties
    by using a "db:" prefix (I am making up property names, please adjust
    per your model):

    Expression e = Expression.fromString("toLocation = $location and
    db:ID_COLUMN != $id and isComplete = 0 and isDeleted = 0");
    Map params = new HashMap();
    params.put("location", aLocation);
    params.put("id", new Integer(idInt));
    Expression qualifier = e.expWithParameters(params);

    Andrus

    On Jul 26, 2004, at 3:29 PM, David Norwood wrote:

    > I've got the following code:
    >
    > ObjectId skipthis = new ObjectId(Packages.class,
    > Packages.ID_PK_COLUMN,
    > [an integer here]);
    >
    > Expression qualifier = ExpressionFactory.matchExp(
    > Packages.TO_LOCATION_PROPERTY, aLocation);
    > qualifier = qualifier.andExp(ExpressionFactory.noMatchExp(
    > Packages.ID_PK_COLUMN, skipthis));
    > qualifier = qualifier.andExp(ExpressionFactory.matchExp(
    > Packages.ISCOMPLETE_PROPERTY, new Integer(0)));
    > qualifier = qualifier.andExp(ExpressionFactory.matchExp(
    > Packages.ISDELETED_PROPERTY, new Integer(0)));
    >
    > SelectQuery query = new SelectQuery(Packages.class, qualifier);
    > query.setLoggingLevel(Level.DEBUG);
    >
    > List packages = dctx.performQuery(query);
    >
    > This query fails when the 'noMatchExp' is included in the qualifier.
    > What am
    > I doing wrong?
    >
    > TIA
    >
    > -david
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Jul 26 2004 - 16:16:20 EDT