Re: Cayenne Spring Integration

From: Mike Kienenberger (mkienen..mail.com)
Date: Wed Feb 22 2006 - 17:14:51 EST

  • Next message: Cris Daniluk: "Re: Cayenne Spring Integration"

    Thanks for pointing this out.

    I'm kinda glancing through the cayenne-spring code that I dropped in
    when I started my JSF+spring project last year, and I'm guessing that
    I don't even use most of it it.

    I wonder how much of it is really ever called?

    A quick check leads to this: everything could be replaced by the
    following 40 lines, most of which are white space. I think the only
    thing I lose is that methods now throw Cayenne exceptions rather than
    DAO exceptions. Guess I'll try running like this for awhile -- it
    lets me dump many otherwise unused spring jars.

    import java.util.List;

    import org.objectstyle.cayenne.DataObjectUtils;
    import org.objectstyle.cayenne.access.DataContext;
    import org.objectstyle.cayenne.query.SelectQuery;

    public class CayenneTemplate
    {
        public CayenneTemplate()
        {
            super();
        }

        protected DataContext threadDataContext()
        {
            return DataContext.getThreadDataContext();
        }

        protected List performQuery(SelectQuery query)
        {
            return threadDataContext().performQuery(query);
        }

        protected void commitChanges()
        {
            threadDataContext().commitChanges();
        }

        protected Object objectForPK(final Class dataObjectClass, final Object pk)
        {
            return DataObjectUtils.objectForPK(threadDataContext(),
    dataObjectClass, pk);
        }

        public void setAutoRollback(boolean b)
        {
            // TODO Auto-generated method stub
        }
    }

    On 2/22/06, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > Posting our private email exchange with Malcolm Edgar regarding
    > Spring integration module. I was feeling the same way about it
    > (cayenne already does a lot of what people normally expect from
    > Spring), and I am glad that someone with practical Spring knowledge
    > confirms that. I guess one area where we can still improve the
    > integration is participation in external transactions (rolling back
    > or even replacing thread DataContext when a Spring transaction is
    > rolled back due to a failure outside Cayenne).
    >
    > Andrus
    >
    >
    > On Feb 22, 2006, at 6:31 AM, Malcolm Edgar wrote:
    >
    > > Hi Andrus,
    > >
    > > I have been looking at the Cayenne Spring integration code for the
    > > last few weeks, getting it working nicely with Click. I have learned a
    > > lot in the process, and now have a much better understanding of
    > > Cayenne.
    > >
    > > The interesting thing that came out of this experience is that I dont
    > > think there is really any significant need for Cayenne Spring
    > > integration, because of the way Cayenne is designed.
    > >
    > > Spring is good an providing a easy to use API wrapper around difficult
    > > to use APIs. However the DataContext API is very good, so the
    > > CayenneTemplate does not add much/any value.
    > >
    > > Spring maps checked persistence framework exceptions in
    > > RuntimeException making the API easier to program to. However Cayenne
    > > uses unchecked exceptions to this isn't an issue.
    > >
    > > Spring can provide an open session in view filter to help deal with
    > > Hibernates lazy loading problems in web applications. Cayenne however
    > > doesn't have this issue as all registered objects are "attached" and
    > > can lazy load when rendering in web pages.
    > >
    > > Spring provides an Transaction wrapper ontop of JDBC or Hibernate
    > > calls. Cayenne transactions are already nicely encapsulated in the
    > > DataContext.
    > >
    > > Another problem with Hibernate is that operations (transactions) than
    > > span multiple requests is difficult to managed, as detached object
    > > must be reattached to the new Session. JBOSS is attempting to address
    > > this issue with Seam. This issue and the lazy loading problem with
    > > Hibernate are difficult issues for web teams to deal with.
    > >
    > > The Cayenne session based DataContext transaction provides a unit of
    > > work approach which better fits the web application space.
    > >
    > > Spring assists with injecting Session dependencies in
    > > HibernateTemplate classs. Cayenne doesn't have this issue as the
    > > thread local DataContext can be obtained directly in DAO or service
    > > layer code.
    > >
    > > I think Spring is good for service layer code, but it hasn't really
    > > got much to contribute to Cayenne; possibly configuration, but that is
    > > a pretty marginal benefit.
    > >
    > > I will be settling on Click, Spring and Cayenne for a medical practice
    > > CRM application I will slowly be building over the next year.
    > >
    > > If there is anything I can do to contribute to Cayenne please let me
    > > know. I will do my best, but I have to admit I dont have much time
    > > between a new baby, work, Click and building a CRM application out of
    > > hours.
    > >
    > > regards Malcolm Edgar
    > >
    > > p.s. - I think Cayenne is excellent. I dont think it gets anywhere
    > > near the attention it deserves. I am writing up some observations on
    > > learning Cayenne as a newbie.
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 22 2006 - 17:14:54 EST