ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Topic: Open Source Java

Dao-zero: implement your DAO intefaces

DaoZero is a small Java Spring bean class that can be used to reduce source of persistence tier which bases on Spring's iBatis support. It's not a wrapper of Spring iBatis support, but to replace your DAO bean class directly. In most cases, the only thing you will do is to declare a bean whose type is "daozero.ibatis.Dao" and tell DaoZero bean what's your DAO interface, then DaoZero bean will invoke iBatis mapped statement for you. No more need DAO implementation codes. DaoZero bean invokes iBatis mapped statement whose name is same as method name of DAO interface( or abstract class). Both count and index of mapped statement's parameters should be keeped same as method arguments for current implementation. DaoZero bean is a factory bean which implements org.springframework.beans.factory.FactoryBean and will create proxy object that implements DAO interface( or abstract class) for those beans need this bean which typically service beans. The proxy object takes repsonsibility for construct parameter map from invocation arguments and pass the parameter map to iBatis template method, such as queryForObject(), queryForList(), etc. The proxy object is smart enough to know what you want is a java.lang.List or a normal Object( but by current DaoZero release, it doen't support queryForMap() now. ). That proxy object is created from different way decided by whether required DAO type is interface or not. If it is interface, the proxy is created using standard JDK proxy(java.lang.reflect.Proxy), else, the proxy is created using CGLIB enhancer(net.sf.cglib.proxy.Enhancer). For a CGLIB proxy, it will try to implement all public abstract methods for the abstract DAO class proxied. In fact, I hacked iBatis, have to cast some iBatis interface to her internal implementation class, because I cannot found how to get parameter map's meta data by iBatis's API. (So sorry for the bad smell )

Programming Language: Java

Updated: 04/28/2006