Primary Key Access

From: Dave Merrin (dmerri..pasystems.co.uk)
Date: Tue Oct 25 2005 - 11:29:31 EDT

  • Next message: Mike Kienenberger: "Re: Primary Key Access"

    Hi,

    sorry to bug you with another question. All your help has been great.

    I'm trying to modify the template for the class generation. I want to give
    access to primary keys. I've added the following code to the template. It
    works apart from getting a weird method name e.g. getItem_id(). Does anybody
    know how to sort this so I get something like getItemId()?

    #if( $classGen.Entity.DbEntity )
    #foreach( $idAttr in ${classGen.Entity.DbEntity.PrimaryKey} )
    #set( $classGen.Prop = $idAttr.Name )## let controller know about current
    property
       /** Read-only access to PK */
       public Integer get${classGen.cappedProp}() {
          return (getObjectId() != null && !getObjectId().isTemporary())
                   ?
    (Integer)getObjectId().getIdSnapshot().get(${classGen.propAsConstantName}_PK
    _COLUMN)
                   : null;
       }
    #end
    #end

    Unfortunately the same code is generated for foreign keys. I see from the
    documentation I should have something more like below as a result. This
    accesses the Artist to get the primary key from the artist. Does this mean
    another query is made to get the artist? If so is there any way to get the
    id's without accessing the artist? Also how do I differentiate in the
    template between a primary key and a foreign key?

    /** Read-only access to FK */
       public Integer getArtistId() {
          Artist artist = getArtist();
          return (artist != null)
                   ?
    (Integer)artist.getObjectId().getIdSnapshot().get(Artist.ARTIST_ID_PK_COLUMN
    )
                   : null;
       }

    Thanks again for all the help on the previous issues.

    Dave



    This archive was generated by hypermail 2.0.0 : Tue Oct 25 2005 - 11:31:44 EDT