Re: performQuery generics

From: Mike Kienenberger (mkienen..mail.com)
Date: Wed Dec 26 2007 - 09:29:29 EST

  • Next message: Andrus Adamchik: "Re: performQuery generics"

    On Dec 25, 2007 9:14 PM, Aristedes Maniatis <ar..sh.com.au> wrote:
    > I have to confess to not quite understanding the boundaries between
    > Expression and Query. 99% of the times that it is used, a Query is
    > just an Expression with Ordering and a root entity. But I don't
    > understand why that root entity isn't part of the Expression itself -
    > does an expression have much meaning without a root entity? It is
    > always implied within the Expression, since you can't create an
    > expression which is meaningful for Artist.class and then create a new
    > SelectQuery(Painting.class).

    Yes, you can!

    Consider this:

    select artist where artist_name = 'bob'
    select painting p, artist a where p.artist_id = a.id and artist_name = 'bob'

    The expression is the same for both -- only the object path is different.

    Expression e = ExpressionFactory.matchExp(String pathSpec, "bob");

    where

    String pathSpec = Artist.ARTIST_NAME_PROPERTY;
           or
    String pathSpec = Painting.ARTIST_PROPERTY + "." + Artist.ARTIST_NAME_PROPERTY;

    Note also, that the pastSpec has the same suffix -- all you need to do
    is adjust the prefix to account for a different root:

    String pathSpec = rootPathSpecPrefix + Artist.ARTIST_NAME_PROPERTY;

    where

    rootPathSpecPrefix = "" for Artist, Painting.ARTIST_PROPERTY + "." for
    painting, Gallery.PAINTING_LIST_PROPERTY + "." +
    Painting.ARTIST_PROPERTY + "." for gallery.



    This archive was generated by hypermail 2.0.0 : Wed Dec 26 2007 - 09:30:03 EST