Re: Cayenne pattern quesiton

From: Robert Zeigler (robert.zeigle..oxanemy.com)
Date: Tue Mar 30 2010 - 17:32:05 EDT

  • Next message: Mike Kienenberger: "Re: Cayenne pattern quesiton"

    Daos can be useful in certain contexts. In particular, if you have
    some means of automagically generating the dao. :)
    For instance, on a Tapestry5 + hibernate-based project I'm working on
    right now, there's a DaoSource service.
    What's more, is there's an..njectDao annotation that plays nicely
    with T5's pages and components.
    So you can do something like:

    @InjectDao(User.class)
    Dao<User> userDao;

    public List<User> getAllUsers() {
         return userDao.listAll();//or something like this.
    }

    The key piece being the fact that Dao<User> wasn't code you have to
    write (or even generate).

    It can make things convenient, but, like Michael and John, I tend away
    from Dao's.

    Robert

    On Mar 30, 2010, at 3/304:26 PM , John Armstrong wrote:

    > My latest project has a lot of DAO going on and while it made sense
    > (for
    > some reason, habit?) at first I regret going that way and will, over
    > time,
    > be migrating into the same pattern that Michael highlights. Its
    > really just
    > a big useless layer for all the reasons he highlights, at least in my
    > context.
    >
    > John-
    >
    > On Tue, Mar 30, 2010 at 2:20 PM, Michael Gentry
    > <mgentr..asslight.net>wrote:
    >
    >> Hi Mike,
    >>
    >> I personally tend to not create DAOs for Cayenne. If I need a
    >> findBy*
    >> type method, I just add it to the Cayenne-generated class as a static
    >> method. (For example, I have a User.withUsernameAndPassword() static
    >> method in my User class.) For findById, you can use DataObjectUtils
    >> directly if you like:
    >>
    >> http://cayenne.apache.org/doc/api/org/apache/cayenne/DataObjectUtils.html
    >> (objectForPK)
    >>
    >> Of course, this is just what I tend to do. Your mileage and that of
    >> others will likely vary. To me, part of the concept of the DAO is
    >> that you can transparently and magically change the DAO code to use a
    >> different ORM and if everything else is using the DAOs, it'll all
    >> just
    >> work. Of course, the assumes that every single ORM works exactly the
    >> same way (they don't) and it also means you are choosing your ORM for
    >> failure (because you expect the need to swap them out). Cayenne
    >> works
    >> differently than Hibernate which works differently than other
    >> ORMs. I
    >> choose an ORM for the features it gives me. To me it doesn't make as
    >> much sense to code with the DAOs (especially when they limit the use
    >> of your ORM), but I'm sure others will disagree with me. :-)
    >>
    >> mrg
    >>
    >>
    >> On Tue, Mar 30, 2010 at 4:51 PM, <MGargan..scholar.com> wrote:
    >>> When using Cayenne are DAO's still the pattern used for findAll,
    >>> findByProperty, and findById query methods or is there some better
    >>> way to
    >>> do this in Cayenne? For example in the pet store project I see
    >>> DAO's
    >>> being implemented, but I know that example was taken from other
    >>> projects
    >>> that use DAO's to begin with so I'm not sure if it was just
    >>> retrofitted
    >> to
    >>> use DAO's with Cayenne. I tried to look at some other examples
    >>> from the
    >>> website, but most of those are either not complex enough to
    >>> warrant that
    >>> kind of structure or the links are dead. I hope this is
    >>> clear. :) Also
    >>> if DAO's are the recommended pattern to use is there a tool (i.e.
    >>> eclipse
    >>> plugin) that will generate them?
    >>>
    >>> Thanks.
    >>> -Mike
    >>>
    >>



    This archive was generated by hypermail 2.0.0 : Tue Mar 30 2010 - 17:32:52 EDT