The Artima Developer Community
Sponsored Link

Java Buzz Forum
Repository supersets DAO

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Bill de hÓra

Posts: 1137
Nickname: dehora
Registered: May, 2003

Bill de hÓra is a technical architect with Propylon
Repository supersets DAO Posted: Sep 20, 2008 9:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Bill de hÓra.
Original Post: Repository supersets DAO
Feed Title: Bill de hÓra
Feed URL: http://www.dehora.net/journal/atom.xml
Feed Description: FD85 1117 1888 1681 7689 B5DF E696 885C 20D8 21F8
Latest Java Buzz Posts
Latest Java Buzz Posts by Bill de hÓra
Latest Posts From Bill de hÓra

Advertisement

Phillip Calçado: "More and more I’ve seem the Repository been used as a fancy name for DAOs. It is very common nowadays to have things named Repository that create SQL/HQL/EJBQL queries or deal with database transactions or connections. Only a DAO with a different name."

This resonates with me. Here's SpringSource's definition of their @Repository annotation: "Indicates that an annotated class is a "Repository" (or "DAO")." That's mixing up two distinct concepts - worse, the Repository pattern is a superset of the DAO, so it's wrong.

The intent of a Repository is to abstract out the kind of storage you are using, not just the details of a particular relational database. What the Repository isa Dao interface gives a developer is a structural decoupling from the database, so you can use HSQL or Mocks for testing, or support multiple backends in production, but it still has the assumption that you are using "One Relational Database" and that tends to mean in code each supposed Repository is mapped onto tables.

Reducing the concept of a Repository to a DAO isn't helpful. It means the industry (or maybe just Spring ;) will need to introduce a third concept down the line or redefine what was meant by "Repository". Granted it doesn't help that the Repository pattern in Domain Driven Design isn't well explained, and you can argue that there's nothing inherently "per table" in the DAO or DataMapper patterns, but in reality that's how most of us them.

Recently in work I did an extended spike on what will be a shared data system in our products. It'll get called heavily so it probably 'Needs To Scale' and perhaps support functional splits, in practical terms that meant keeping an eye on the data joins. For that reason I started the spike with Hibernate shards. What I found is that the Repository-isa-DAO approach falls apart when you need to either carefully order the serialisation sequence to put related data on the same physical partition or where you're organising your relational data to be treelike with minimal joins (so it could in principle be functionally split later). Normally that logic would be exposed in Domain Facade and per object save methods; the problem with sharding is that you can call saves out of order in what otherwise would be reasonable code. In my case what I found was that Hibernate Shards was putting objects that should be related to each other on different shards - not good! Some quick fixes later and I had the corrected the persistence layer, by making sure the object graph was properly cued. All that logic had to pushed back behind an interface - the Repository. And this is where the Repository abstraction shines, especially in conjunction with Builders. You give the Repo an object graph and it takes care of the serialisation, the physical allocation of data, and removes the assumption you're using a single relational database.  DAOs by contrast don't remove the single database assumption. I suspect that unlike DAOs, Repositories are part of the domain and not a detail of persistence mechanism

And of course it should to be said that if you are building on a single database (and that's most of us, most of the time), DAO/DataMapper are enough of an persistence abstraction and Repositories are probably pattern noise - use a DomainFacade and move on.

Read: Repository supersets DAO

Topic: Episode 136 - Cracks in the Web UI Powerbase from DrunkAndRetired.com Previous Topic   Next Topic Topic: First Conky Config

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use