this follows
Returning ScrollableResults using Spring topic, about applying AOP interceptor instead of HibernateCallbacks use, answered by Juergen.
Applying AOP interceptor requires to have an interface for any class you use. Hopefully when designing DAOs, one would typically design them to be implementable with any persistence technologie (being JDBC, ORM, JDO, etc.). So it doesn't matter much.
But since I integrated Spring in my apps, I had to get rid of my DAOFactory in which I could specify the type of DAO to be implemented. So I could dynamically specify the implementation to use via a parameter.
I have some services (managers) that requires JdbcDAO AND HibernateDAO
Since Spring integration I had no other choice than providing 2 different DAOs to my Service via applicationContext.xml. I-e, the type of DAO used by the service is hardcoded in the service.
It's not really due to Spring, since before its integration I anyway had to specify a parameter to the Factory for it to know which implementation to give back. So it was also kind of hardcoded.
But this Interceptor stuff makes me realise I could have an interceptor between service definition and DAO def. in the applicationContext.xml. I-e when the Service tries to load its DAO an Interceptor gives him the desired implementation following specification in a xml file.
I wouldn't need something like this anymore (with 2 different adherentDAO)
Code:
<!-- AdherentService -->
<bean id="adherentServiceTarget" class="org.xx.adherent.service.AdherentService" singleton="true">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="adherentDAO">
<ref bean="adherentDAO"/>
</property>
<property name="adherentDAOJdbc">
<ref bean="adherentDAOJdbc"/>
</property>
<property name="commonDAO">
<ref bean="commonDAO"/>
</property>
</bean>
but only:
Code:
<!-- AdherentService -->
<bean id="adherentServiceTarget" class="org.xx.adherent.service.AdherentService" singleton="true">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="adherentDAO">
<ref bean="adherentDAO"/>
</property>
<property name="commonDAO">
<ref bean="commonDAO"/>
</property>
</bean>
Am I any clear?
I think of something that could dynamically associates beans following an xml configuration.
such method 1 of such classA: HibernateDAO
such method 2 of such classB: JdbcDAO
being an AOP framweork, would it be possible to plug something like this on Spring?? Interceptor between Beans??? Or would it require some refactoring? Or is it even already possible?
OUps! I think I'm realizing the power of AOP !!!
I'm a real beginner in AOP so it would probably takes me ages to understand how Spring effectively works, but it sound really usefull to be able to implement Interceptor. (which is an AOP concept, isn't it?)
Any thought on this is welcome.