considered to be a lack of modularity. Ideally, such data-access logic should be encapsulated within DAOs but, unfortunately, GORM does not explicitly support them.

SUMMARY

GORM provides an innovative style of O/R mapping that simplifies application code. One of the key ways it does this is by leveraging the dynamic features of the Groovy language. GORM injects persistence-related methods into domain classes at runtime. It eliminates a significant amount of data-access methods and classes, while still decoupling the business logic from the ORM framework.

GORM’s extensive use of CoC simplifies application code. Provided that GORM’s defaults for table and column names match the schema, a class can be mapped to the database schema with little or no configuration. GORM also injects every domain class with primary-key and version-number fields, which further reduces the amount of coding required.

GORM has some limitations. It does not easily support multiple databases. Dynamic finder methods cannot have an intentional revealing name that encapsulates the query. GORM lacks support for DAO classes, even though complex applications might benefit from the improved modularity that they offer. Applications that work with a legacy schema will not be able to take advantage of CoC since they require explicit configuration of ORM.

Despite these limitations, developers of a wide range of applications will find GORM extremely useful. Developers can use GORM independently of Grails but it is targeted at Web application developers who can benefit from the rapid development capabilities of the Grails framework. In addition, GORM is best used when developing applications that access a single database or when using database middleware that makes multiple databases appear as a single database. Developers will get the most benefit from GORM when they have control over the database schema and can leverage GORM’s CoC features. Q

 

ACKNOWLEDGEMENTS

I would like to thank the following reviewers for the helpful feedback on drafts of this article: Ajay Govindara-jan, Azad Bolour, Dmitriy Volk, Brad Neighbors, and Scott Davis. I would also like to thank the members of the SF Bay Groovy and Grails meet-up and the anonymous ACM Queue reviewers who provided feedback on this article.

 

REFERENCES

1. Bauer, C., Gavin, K. 2006. Java Persistence with Hibernate. Manning Publications.

2. Oracle TopLink; http://www.oracle.com/technology/ products/ias/toplink/ index.html.

3. Apache OpenJPA; http://openjpa.apache.org/.

4. NHibernate; http://sourceforge.net/projects/nhiber-nate/.

5. Thomas, D., Hansson, D., Breedt, L., Clark, M., Fuchs, T., Schwarz, A. 2005. Agile Web Development with Rails. Pragmatic Bookshelf.

6. Thomas, D., Fowler, C., Hunt, A. 2004. Programming Ruby: The Pragmatic Programmers’ Guide. Pragmatic Bookshelf.

7. Rocher, G. 2006. The Definitive Guide to Grails. Apress.

8. Koenig, D., Glover, A., King, P., Laforge, G., Skeet, J. 2007. Groovy in Action. Manning Publications.

9. Walls, C., Breidenbach, R. 2007. Spring in Action, second edition. Manning Publications.

10. Java SE Desktop Technology; http://java.sun.com/ javase/technologies/desktop/javabeans/index.jsp.

11. Domain-specific language; http://www.martinfowler. com/bliki/DomainSpecifi cLanguage.html.

12. Dijkstra. E. W. 1982. On the role of scientific thought. In Selected Writings on Computing: A Personal Perspective. Springer-Verlag: 60-66.

13. Marinescu, F. 2007. EJB Design Patterns: Advanced Patterns, Processes, and Idioms. Manning Publications.

14. Mellqvist, P. Don’t repeat the DAO! 2006; http://www. ibm.com/developerworks/java/library/j-genericdao. html.

15. Fowler, M. 2004. Inversion of control containers and the dependency injection pattern; http://www.martin-fowler.com/articles/injection.html.

16. The Spring Framework Reference Documentation. See @Configurable; http://static.springframework. org/spring/docs/2.5.x/reference/ index.html.

 

LOVE IT, HATE IT? LET US KNOW feedback@acmqueue.com or www.acmqueue.com/forums

 

CHRIS RICHARDSON is a developer and architect with more than 20 years of experience. He is the author of POJOs in Action (Manning Publications, 2006), which describes how to build enterprise Java applications with POJOs and lightweight frameworks. He runs a consulting and training company that specializes in helping companies build better software faster. He has been a technical leader at Insignia, BEA, and elsewhere. Richardson has a computer science degree from the University of Cambridge in England and lives in Oakland, California. Web site and blog: www.chris-richardson.net. © 2008 ACM 1542-7730/08/0500 $5.00

References:

http://www.acmqueue.com

http://openjpa.apache.org/

mailto:feedback@acmqueue.com

http://www.acmqueue.com/forums

http://www.oracle.com/technology/products/ias/toplink/index.html

http://www.oracle.com/technology/products/ias/toplink/index.html

http://sourceforge.net/projects/nhibernate/

http://sourceforge.net/projects/nhibernate/

http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp

http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp

http://www.martinfowler.com/bliki/DomainSpecificLanguage.html

http://www.martinfowler.com/bliki/DomainSpecificLanguage.html

http://www.ibm.com/developerworks/java/library/j-genericdao.html

http://www.ibm.com/developerworks/java/library/j-genericdao.html

http://www.martinfowler.com/articles/injection.html

http://www.martinfowler.com/articles/injection.html

http://static.springframework.org/spring/docs/2.5.x/reference/index.html

http://static.springframework.org/spring/docs/2.5.x/reference/index.html

http://www.chrisrichardson.net

http://www.chrisrichardson.net

Archives