Generic DAO is a Java package which allows a developer to skip writing DAOs for their persistence objects when they are using Spring and JDBC or Hibernate. It is a lightweight ORM package without the loss of control or increase in complexity which is experienced with some of the heavier weight ORM packages.
It is designed to make it easier and faster for developers to write their DAOs without having to rewrite the same old boring save/delete/etc functions over and over for each persistent type but also not having to have implementation dependencies in their DAO interfaces. It also allows for good control over which persistent objects are usable within the DAO and is easy to extend so you can add your own DAO methods. Configuration is easily handled via spring configuration but can also be handled programmatically, however, since the package depends on the spring framework you are best off using it with spring.
Generic DAO allows a developer to write their persistent objects as POJOs with no dependencies. It supports an approach between the anemic domain model (or service/manager model) methodology and the use of a rich domain model (or heavy DDD). The use of simple POJOs as persistent objects makes it easy to swap around storage mechanisms while allowing the developer to use their model objects throughout their application and even expose them for use by other applications.
The package includes functionality for all the basic ORM CRUD type methods along with search methods and batch methods. The JDBC part of the package includes support for caching all the DAO methods (which could also be used with the hibernate part but hibernate has its own caching so you should probably use that). It also includes interceptor points for before and after all read and write methods. For simpler use cases, you can write your POJOs, make them persistent, create your DDL and not have to write a single line of DAO code.
The package is built on and depends on the spring framework.
The package was originally created by Aaron Zeckoski for the Evaluation System project but was repackaged to make it distributable by request.
Projects using generic DAO would create a POJO like this:
They would create a DAO service like this:
And finally use the DAO in their services like this:
Where do I get the generic dao jar?
How do I use generic dao?
There are extensive javadocs and source code available with the jar in maven. These detail exactly how to use the generic dao package and install it and I don't want to repeat them here. In a nutshell, you just need to drop the jar anywhere you normally would for an app/webapp and then begin using it.
Maven site: https://source.sakaiproject.org/maven2/org/sakaiproject/generic-dao/site/
includes javadocs and information about the project
Javadocs also available here: https://source.sakaiproject.org/maven2/org/sakaiproject/generic-dao/site/apidocs/index.html
Note: You should use the ones in maven for the package you downloaded to make sure they are correct!
Where do I get the generic dao source?
It's in the jar package! But you can also get to it here:
What if I find an issue?
This is the URL for the issue tracker:
I encourage you to enter suggestions there or send them to me directly. Please report any bugs there as well. I will fix them as quickly as I can. I believe in the policy of release early and often so you will tend to find many versions of generic-dao but rest assured that I make API changes rarely and breaking API changes almost never.
Code examples that are using this?
Generic DAO is used in large scale production deployments and has proven to be reliable and stable.
- Here are some examples of Sakai applications that are using it:
- Tasklist production - https://source.sakaiproject.org/contrib/tasklist/trunk/
- Tasklist sample tool - https://source.sakaiproject.org/contrib/programmerscafe/trunk/tasklist/
- Evaluation System - https://source.sakaiproject.org/contrib/evaluation/
- Blog Wow - https://source.sakaiproject.org/contrib/programmerscafe/blogwow/
- Entity Broker - https://source.sakaiproject.org/svn/entitybroker/trunk/
- RSF ORM - http://www2.caret.cam.ac.uk/rsfwiki/
- There are other examples from tools and services in the Sakai project source
- The code has extensive integration and unit tests. These are a good place to look for examples of proper usage.
- Sample spring configs: https://source.sakaiproject.org/contrib/programmerscafe/genericdao/trunk/src/test/
- Various tests and sample persistent POJOs: https://source.sakaiproject.org/contrib/programmerscafe/genericdao/trunk/src/test/org/sakaiproject/genericdao/test/
- 0.5 - Alpha test release
- Basic DAO funcitonality
- 0.7 - Beta test release
- Added properties searching
- 0.8 - Oct 20, 2006 (Stable release)
- Added support for wrapper invoker
- Added ability to do comparison searches
- 0.9 - Nov 15, 2006
- Fixes for documentation
- Added ability to do sorts
- Added transactional sets
- Implementation change: init method no longer located in CompleteHiberateGenericDao, this could cause build failures when updating from 0.8 to 0.9, simply remove the init-method attribute from the spring config OR add in your own init method to your dao impl.
- 0.9.1 - Oct 10, 2007
- Added fixes to make the package compatible with Hibernate 3.2.5
- Still backwards compatible
- 0.9.5 - April, 2008
- Added support for JDBC SQL usage (along with Hibernate)
- Supports HSQL, MySQL, Oracle, DB2, Postgres, MSSQL, and Derby
- Updated the interfaces to use a common search object which is easier to use than the many find interfaces
- Switched the main method to be called GeneralGenericDao (deprecated CompleteGenericDao and findByExample)
- Added reflection utilities to support automatic mapping of object data onto DB columns (based on and compatible with Apache BeanUtils)
- Updated maven 2 POM and removed the logging dependency
- Added support for JDBC SQL usage (along with Hibernate)
- 0.9.8 - May, 2008
- Added interceptor support for all methods
- Added caching support for all read and count methods
- Updated the reflection utilities to provide 90% of the needed functionality
- Added support for annotations and public fields
- Bug fixes and improvements to make usage easier
- 1.0 - ?
What is the license?
The license is Apache 2 for use in open source projects.