ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: converting iBATIS framework DAOs to the Spring Framework
Date Fri, 13 Apr 2007 14:39:00 GMT
You guys rock! :)

Thanks for taking this on, and getting it documented. It will be a
major help for both new and existing users.

Larry


On 4/13/07, Poitras Christian <Christian.Poitras@ircm.qc.ca> wrote:
> In fact, this was just a recommandation to cut Spring xml file size and
> management. Stripes is not required in any way.
> I only use 1 class in Stripes and only 2 of my classes have any link
> with this.
>
> I personnaly recommand to convert to Spring without Stripes first! Once
> it is done and it works, then you can check out if Stripes can reduce
> management of Spring config files.
>
> I'll add a supplement wiki page to indicate what are the advantages of
> using Stripes to reduce Spring config file.
>
> Christian
>
> -----Original Message-----
> From: Meindert [mailto:meindert@pastelebusiness.com]
> Sent: Friday, 13 April 2007 09:59
> To: user-java@ibatis.apache.org
> Subject: RE: converting iBATIS framework DAOs to the Spring Framework
>
> Another framework? How much work is it to convert an existing project
> (like jpetstore)?
>
> -----Original Message-----
> From: Poitras Christian [mailto:Christian.Poitras@ircm.qc.ca]
> Sent: 12 April 2007 03:57 PM
> To: user-java@ibatis.apache.org; lmeadors@apache.org
> Subject: RE: converting iBATIS framework DAOs to the Spring Framework
>
> I also suggest to use Stripes to cut the size of Spring config file.
>
> By adding @SpringBean annotation in front of properties (event private),
> Stripes will fill these properties by simulating the auto-wire process
> of Spring (even if no setter/getter/constructor exists).
>
> For instance, if I have a class like this
> /**
>  * Manage DataFile.
>  *
>  * @author poitrac
>  */
> public class DataFileManagement {
>     public DataFileManagement() {
>         super();
>     }
>     /**
>      * For DataFile management.
>      */
>     @SpringBean private DataFileDao dataFileDao;
>     /**
>      * Hides DataFiles.
>      * @param dataFileList DataFiles to hide from search requests.
>      */
>     @Transactional
>     public synchronized void hide(List<DataFile> dataFileList) {
>         dataFileDao.hide(dataFileList);
>     }
> }
>
> Then I have no special configuration to do in spring.xml beside
> declaring the bean.
> <bean id="dataFileManagement"
> class="ca.qc.ircm.management.DataFileManagement"/>
>
> It's possible to use the feature without using the web framework of
> Stripes. To do so, you juste need to add a PostProcessor.
> /**
>  * Injection bean dependencies based on Annotation.
>  *
>  * @author poitrac
>  */
> public class AnnotationInjector implements BeanPostProcessor,
> ApplicationContextAware, Ordered {
>     public AnnotationInjector() {
>         super();
>     }
>     /**
>      * ApplicationContext for bean injection.
>      */
>     private ApplicationContext applicationContext;
>     /* (non-Javadoc)
>      * @see
> org.springframework.beans.factory.config.BeanPostProcessor#postProcessBe
> foreInitialization(java.lang.Object, java.lang.String)
>      */
>     public Object postProcessBeforeInitialization(Object bean, String
> beanName) throws BeansException {
>         return bean;
>     }
>     /* (non-Javadoc)
>      * @see
> org.springframework.beans.factory.config.BeanPostProcessor#postProcessAf
> terInitialization(java.lang.Object, java.lang.String)
>      */
>     public Object postProcessAfterInitialization(Object bean, String
> beanName) throws BeansException {
>         SpringHelper.injectBeans(bean, applicationContext);
>         return bean;
>     }
>     /* (non-Javadoc)
>      * @see org.springframework.core.Ordered#getOrder()
>      */
>     public int getOrder() {
>         return Ordered.HIGHEST_PRECEDENCE;
>     }
>     /*
>      *  (non-Javadoc)
>      * @see
> org.springframework.context.ApplicationContextAware#setApplicationContex
> t(org.springframework.context.ApplicationContext)
>      */
>     public void setApplicationContext(ApplicationContext
> applicationContext) {
>         this.applicationContext = applicationContext;
>     }
> }
>
> Here I use HIGHEST_PRECEDENCE since Stripes requires to set properties
> (without setters) before it is enhanced by cglib.
>
> I prefer to just declare my beans in Spring and update my code and not
> the xml file (I always forget about updating xml anyway...).
>
>
> Christian
>
>
> -----Original Message-----
> From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
> Of Larry Meadors
> Sent: Thursday, 12 April 2007 07:35
> To: user-java@ibatis.apache.org
> Subject: Re: converting iBATIS framework DAOs to the Spring Framework
>
> I'll add this to the wiki, and clean up anything I see in it that looks
> odd.
>
> Larry
>
>
> On 4/12/07, Meindert <meindert@pastelebusiness.com> wrote:
> >
> >
> >
> > Hi all.
> >
> > I've documented the process of converting jpetshop5, and would like to
>
> > know if it is right?
> >
> > Also I don't know what to do with the
> > com.ibatis.dao.client.DaoException thrown in SequenceSqlMapDao?
> >
> > I'm going to add the transaction on OrderService now.
> >
> >
> > Steps to convert jpetshop5 to ibatis-spring
> >
> >
> >
> > The DAO iBATIS has been depreciated and it is recommended to replace
> > this with the spring framework. This document describes the steps
> > taken to convert from ibatis dao to spring dao. I work on the project
> > in netbeans so some terminology used might be incorrect for other
> > IDE's
> >
> >
> >
> > Prerequisite is to have a project similar to jpetstore5, and have it
> > connected to a 'normal' database
> >
> > (There is support for hssqldb in the DaoConfig class what we are going
>
> > to throw away.)
> >
> >
> > Lib jar files;
> >
> > Remove the old ibatis jar files from the class path and create the
> > reference to the new ibatis and spring jars
> >
> > Remove ibatis-common-2.jar
> > Remove ibatis-dao-2.jar
> > Remove ibatis-sqlmap-2.jar
> > Add ibatis-2.3.0.677.jar
> > Add spring.jar
> > Add commons-dbcp-1.2.1.jar
> > Add commons-pool-1.2.jar
> > Add commons-collections.jar
> >
> >
> > Com.ibatis.jpetstore.persistence.sqlmapdao
> >
> > Change the BaseSqlMapDao to;
> >
> > package com.ibatis.jpetstore.persistence.sqlmapdao;
> >
> > import org.springframework.orm.ibatis.SqlMapClientTemplate;
> >
> > public class BaseSqlMapDao extends SqlMapClientTemplate {
> >
> >     protected static final int PAGE_SIZE = 4;
> >
> > }
> >
> > All the other SqlMapDao files;
> >
> > Remove the public AccountSqlMapDao(DaoManager daoManager)  methode
> >
> > Remove import com.ibatis.dao.client.DaoManager;
> > Com.ibatis.jpetstore.service
> >
> > The DAO will be injected by spring, thus the constructor can be
> > deleted
> >
> > Example for AccountService, remove the public AccountService()methode
> >
> > (also remove import com.ibatis.dao.client.DaoManager;)
> >
> > There is a transaction in OrderService.java, this transaction must be
> > handled by Spring, remove it here for now. Also remove it out of the
> > constructor;
> >
> > public OrderService(ItemDao itemDao, OrderDao orderDao, SequenceDao
> > sequenceDao) {
> >
> >     this.itemDao = itemDao;
> >
> >     this.orderDao = orderDao;
> >
> >     this.sequenceDao = sequenceDao;
> >
> >   }
> >
> >
> > The Link between spring and ibatis
> >
> > Add the SpringInit.java class to a new package com.listeners
> >
> > This class will be instantiated on load of the website and will pass
> > the reference to the spring managed objects
> > Com.ibatis.jpetstore.presentation
> >
> >
> >
> > The presentation layer must connect with the spring managed service
> > layer
> >
> > So replace;
> >
> > public AccountBean() {
> >
> >     this(new AccountService(), new CatalogService());
> >
> >   }
> >
> > With
> >
> > public AccountBean() {
> >
> >      this((AccountService)
> > SpringInit.getApplicationContext().getBean("accountService"),
> >
> >           (CatalogService)
> > SpringInit.getApplicationContext().getBean("catalogService"));
> >
> >   }
> >
> > And add import com.listeners.SpringInit;
> >
> > Repeat for the other classes
> >
> >
> > Configuration
> >
> > First setup the listeners to have SpringInit initiated on loading of
> > the site
> >
> > Add to web.xml (after <description> tag)
> >
> > <context-param>
> >
> >         <param-name>contextConfigLocation</param-name>
> >
> >         <param-value>/WEB-INF/spring.xml</param-value>
> >
> > </context-param>
> >
> >
> >
> > <listener>
> >
> > <listener-class>org.springframework.web.context.ContextLoaderListener<
> > /listener-class>
> >
> > </listener>
> >
> >
> >
> > <listener>
> >
> >  <listener-class>com.listeners.SpringInit</listener-class>
> >
> > </listener>
> >
> >
> >
> > As you can see it is looking for /WEB-INF/spring.xml create this file.
> > Attached is the one I created for jpetstore5
> >
> >
> > Cleanup
> >
> > Throw away DaoConfig.java and dao.xml out of
> > com.ibatis.jpetstore.persistence, and the reference to it in the
> > Service classes
> >
> >
> >
>
>

Mime
View raw message