Re: superclass template question

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Wed May 11 2005 - 13:08:27 EDT

  • Next message: Erik Hatcher: "Re: superclass template question"

    On May 11, 2005, at 11:07 AM, Mike Kienenberger wrote:
    > Erik Hatcher <eri..hatchersolutions.com> wrote:
    >
    >> I want to generate something like this in each of my superclasses:
    >>
    >> static public final User forPK(Object pk) {
    >> return (User) DataObjectUtils.objectForPK(getCurrentDataContext
    >> (), User.class, pk);
    >> }
    >>
    >> First of all, is this approach reasonable to do? Are others doing
    >> something similar? getCurrentDataContext() comes from my custom base
    >> class and pulls the DataContext from thread local storage. My goal
    >> is to keep direct Cayenne dependence out of my Tapestry code, and for
    >> things like looking up an object by its primary key, I'd like to that
    >> to be clean and straightforward to use. My reliance on Cayenne will
    >> ideally be indirect as in the above finder method.
    >>
    >
    > You might find it easier to create a BaseDataObject class, and
    > insert it
    > between CayenneDataObject and each of your generated classes.

    I already do that... ("... comes from my custom base class" :).

    > Then you can put methods common to all entity classes in
    > BaseDataObject.

    But then they aren't specific to the type. For example, I think it'd
    be handy to have this:

         User user = User.forPK(key);

    than

         User user = (User) User.forKey(User.class, key);

    > It's easier to maintain java code than Velocity java templates.

    Well, depends on the use case :)

    > For example (and this is two-year-old code predating DataObjectUtils):

    DataObjectUtils provides what I'm looking for, I'm just trying to
    make it cleaner and simpler for my UI code to work with.

    >> Second - how can I get the package name of User when generating
    >> _User? I have superclasses generated into a separate package than
    >> the subclass objects (which I create manually).
    >>
    >
    > I think it's a bad idea to have your superclass directly refer to the
    > subclass.

    In general, I agree. In this case, as was said also on this thread,
    Cayenne super/sub classes are different - they are built to work
    together intimately and the subclasses are there to provide business
    code.

    > I also don't think that information is available.

    It might not be - at my first glance, I didn't see what I needed
    available.

    > What task are you trying to accomplish?

    Simplicity for code working with my model is the goal.

         Erik



    This archive was generated by hypermail 2.0.0 : Wed May 11 2005 - 13:08:57 EDT