You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by suntoe <qi...@technodia.com.cn> on 2006/04/28 15:56:05 UTC

Spring bean implements dao interfaces automatically based on iBatis

http://dao-zero.sourceforge.net

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 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 ) 
--
View this message in context: http://www.nabble.com/Spring-bean-implements-dao-interfaces-automatically-based-on-iBatis-t1524667.html#a4140726
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: Spring bean implements dao interfaces automatically based on iBatis

Posted by suntoe <qi...@technodia.com.cn>.
Thank you.  I hope problems and suggestions to improve it. 
--
View this message in context: http://www.nabble.com/Spring-bean-implements-dao-interfaces-automatically-based-on-iBatis-t1524667.html#a4266911
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: Spring bean implements dao interfaces automatically based on iBatis

Posted by zhang shaohua <zs...@gmail.com>.
I think this is a good job:)
2006/4/28, suntoe <qi...@technodia.com.cn>:
>
>
> http://dao-zero.sourceforge.net
>
> 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 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 )
> --
> View this message in context:
> http://www.nabble.com/Spring-bean-implements-dao-interfaces-automatically-based-on-iBatis-t1524667.html#a4140726
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>