Re: Object Metadata

From: Mike Kienenberger (mkienen..laska.net)
Date: Fri Mar 26 2004 - 08:53:27 EST

  • Next message: Andrus Adamchik: "[ANN] Cayenne 1.0.7 is out"

    To keep your code without hardcoded DB field references, I would suggest
    getting the ObjEntity instead, retrieving the ObjAttribute by model name,
    then getDbAttribute() for that ObjAttribute.

    That way, if your model ever changes, your code will automatically keep up.

    Note that EntityResolver can retrieve by DataObject instance as well as
    DataObject class, so there's no need to hardcode a DataObject.class value in
    your code if you're already working with a specific instance.

    I just threw in the code I had in front of me which happened to need to
    retrieve a DbEntity by class.

    -Mike

    Steve Wells <stwell..wnmail.net> wrote:
    > Thanks Mike, worked a treat. I'd just add this line:
    >
    > DbAttribute dbAttr = (DbAttribute)
    > aDbEntity.getAttribute("some_db_fld_name");
    >
    > //Then we can do things like:
    > dbAttr.getMaxLength();
    >
    > ----- Original message -----
    > From: "Mike Kienenberger" <mkienen..laska.net>
    > To: "Steve Wells" <stwell..wnmail.net>
    > Date: Fri, 26 Mar 2004 01:29:28 -0500
    > Subject: Re: Object Metadata
    >
    > Steve Wells <stwell..wnmail.net> wrote:
    > > Does anyone know if its possible to programatically get any info about a
    > > data object? In particular I'm after the field length. Using 1.1 M4.
    > > I've noticed there is DbAttribute.getMaxLength() method, but can't
    figure
    > > how to get to this from a CayenneDataObject.
    >
    > Don't have time to answer this comprehensively, but look at
    > EntityResolver,
    >
    > Ie,
    >
    > EntityResolver anEntityResolver =
    > aDataContext.getEntityResolver();
    > DbEntity aDbEntity = anEntityResolver.lookupDbEntity(aClass);
    >
    > This is just one example I had in front of me.
    >
    >
    > --
    > http://www.fastmail.fm - Access your email from home and the web



    This archive was generated by hypermail 2.0.0 : Fri Mar 26 2004 - 08:52:58 EST