cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: Cayenne pattern quesiton
Date Tue, 30 Mar 2010 22:20:21 GMT
I used DAOs in my last set of Cayenne projects, and other than dealing
with injecting the DAO into the methods needing them, it worked really
well.  I went with a central ServiceLocator pattern to a DAOFactory to
deal with that situation as we had no IoC providers.

I used templates to generate 90% of the DOA methods, and used a
generation gap pattern to add in custom find methods when needed.

As for the usefulness, a DAO as an interface and injected resource
makes it incredibly simple to write unit tests.

I'm now working on a JPA project where we are using the static methods
on entity classes, and it's pretty much impossible to write easy unit
tests.   Instead I have to try to mock up pieces of the JPA layer
instead, which is orders of magnitude more difficult.  It didn't help
that we dropped entities-as-interfaces at the same time :)


On Tue, Mar 30, 2010 at 5:32 PM, Robert Zeigler
<robert.zeigler@roxanemy.com> wrote:
> 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 @InjectDao 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
>> <mgentry@masslight.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,  <MGargano@escholar.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
>>>>
>>>
>
>

Mime
View raw message