Re: Suggestions

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Sep 01 2003 - 16:55:07 EDT

  • Next message: Andrus Adamchik: "Re: Object validation"

    Hi Brad,

    I appreciate you offering help with Cayenne, but please take some time
    and learn how the framework operates. There is documentation and
    examples available. You may find that most of the things you need are
    already there. Sometimes trying to interpret Cayenne in terms of some
    other frameworks that you've used can lead you in the wrong direction.

    On Sunday, August 31, 2003, at 11:07 PM, Brad Messerle wrote:
    > guess the question i have is, is
    > a data context global? In a fat client I assume I can
    > hold onto a data context and then reuse it. In a
    > server enviroment, what is the proper way of reuseing
    > it?

    Scope of DataContext is normally one user session (whatever that means
    in the context of a given application). It combines features of
    transaction and data source objects that can be found in other
    frameworks. Basically it is the isolated view of data changes made by a
    single user. It is all in the documentation, e.g.:

    http://objectstyle.org/cayenne/userguide/datactxt/index.html

    > So to make a long story longer. I would like to
    > implement a home collection to my business objects.
    > The methods would be like...
    >
    > findById(anId)
    > basicCreate()
    > allInstances()
    >
    > I assume all i would have to do is tie the datacontext
    > into the home objects. So the million dollar question
    > is.. What would be the best way of doing this?

    All these things can be easily done with Cayenne (findById is bit
    controversial in Cayenne philosophy though - PK value is normally
    opaque, but it can still be done). If you look at the examples supplied
    with Cayenne, you'll see how to do it. Start by obtaining a DataContext
    for your session, and then you can do all the stuff.

    1. E.g., here is "basicCreate":

    Artist artist = (Artist)context.createAndRegisterNewObject("Artist");

    .. Very clear and easy. Of course something like this:

    Artist artist = Artist.newArtist(context);

    would be shorter and won't have a cast, but the difference is not
    really that important.

    2. Another example, "allInstances":

    List allInstances = context.performQuery(new SelectQuery(Artist.class));

     From what I can tell without looking any deeper, the methods above can
    probably be added to class generation templates without changing any
    framework code (Ant CayenneGen task allows customizing templates). They
    can be static methods on a given business class, each taking a
    DataContext instance as the argument.

    Regards
    Andrus



    This archive was generated by hypermail 2.0.0 : Mon Sep 01 2003 - 16:54:10 EDT