Re: Primary keys in expressions

From: Cris Daniluk (cris.danilu..mail.com)
Date: Tue Feb 07 2006 - 11:49:01 EST

  • Next message: Cris Daniluk: "Re: SQLTemplate / inExp"

    On 2/2/06, Dave Merrin <dmerri..pasystems.co.uk> wrote:
    > Hi,
    >
    > I want to be able to use a primary key in expressions. I see there are two
    > possible ways of doing this. The first is to prefix the column name with
    > 'db:'. The second is to set up another mapping in my map file from an
    > objentity to the existing dbentity.
    >
    > Which is the best way?

    If you map a key in the modeler, it means you are responsible for
    setting it. Not recommended to do this just for searching.

    Why do you need to include the PK in an expression? Odds are you don't
    need to. If you just need to resolve a PK to a DataObject, you should
    use DataObjectUtils (or the new supercool SingleObjectQuery if you are
    using 1.2).

    If not, you probably can use the DataObjects in your expressions,
    rather than the PKs... i.e.

    Expression findPaintings = Expression.matchExp(Painting.TO_ARTIST, artist);

    >
    > And while I'm looking at this code why doesn't the generated code for normal
    > properties use the constants i.e.
    >
    > public static final String DESCRIPTION_PROPERTY = "description";
    >
    > public String getDescription() {
    > return (String)readProperty("description");
    > }
    >

    Err... technically it does use the constant :) This is pre-compiled
    code. On the first pass by the compiler, all instances of
    DESCRIPTION_PROPERTY will be converted to "description". At runtime,
    all strings are further interned so that there is only one
    "description" string in the database... at least in this case. So, it
    is really the same thing. And since its generated code, what do you
    care? :)

    If its keeping you up at night, you could modify the template to use
    the constant fairly easily.

    Cris



    This archive was generated by hypermail 2.0.0 : Tue Feb 07 2006 - 11:49:03 EST