Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 77925 invoked from network); 13 Apr 2007 14:39:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Apr 2007 14:39:30 -0000 Received: (qmail 72550 invoked by uid 500); 13 Apr 2007 14:39:29 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 72537 invoked by uid 500); 13 Apr 2007 14:39:29 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 72526 invoked by uid 99); 13 Apr 2007 14:39:29 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2007 07:39:29 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of larry.meadors@gmail.com designates 66.249.92.168 as permitted sender) Received: from [66.249.92.168] (HELO ug-out-1314.google.com) (66.249.92.168) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2007 07:39:22 -0700 Received: by ug-out-1314.google.com with SMTP id m2so508503ugc for ; Fri, 13 Apr 2007 07:39:00 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=jqbdhtvJJRsL7/7dmdmkZfzpRSPM6SNGv43XQeERo54vRJWOxChYonw8BOfav0NF6rZ52VTa78PzwgQk0TAV9ejMx2JlXz08R+5qNu5aVWGHi4Isq2ZwX9sBhIkQurQth0Dk0fTJIe0SHfJjDaAuBIfYALaaQaTSU/KN/wug5lI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=NpYP0/Mh8hfKn7w61xAkZuvi54PU/jkeXvlRbVs7bG/ARp7OrW2pk7GRM7MdqGgN6Sdo54ESO8oyL61NT1/UIP+rml9UXExNtKwNBDxAv/6OVRWBLwhgP0dZqvJ8tR3aYFQHWCY2PYlxTI4g0QGhpQj0DtL4rQNhOvZliA8PMpo= Received: by 10.67.11.15 with SMTP id o15mr2051577ugi.1176475140298; Fri, 13 Apr 2007 07:39:00 -0700 (PDT) Received: by 10.67.44.7 with HTTP; Fri, 13 Apr 2007 07:39:00 -0700 (PDT) Message-ID: Date: Fri, 13 Apr 2007 08:39:00 -0600 From: "Larry Meadors" Reply-To: lmeadors@apache.org Sender: larry.meadors@gmail.com To: user-java@ibatis.apache.org Subject: Re: converting iBATIS framework DAOs to the Spring Framework In-Reply-To: <5820E7E2A928DB46824297946AC2024A9A6223@pandore.ircm.priv> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <5820E7E2A928DB46824297946AC2024A9A621E@pandore.ircm.priv> <5820E7E2A928DB46824297946AC2024A9A6223@pandore.ircm.priv> X-Google-Sender-Auth: d9ddcb23c6602c4b X-Virus-Checked: Checked by ClamAV on apache.org 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 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 dataFileList) { > dataFileDao.hide(dataFileList); > } > } > > Then I have no special configuration to do in spring.xml beside > declaring the bean. > 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 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 tag) > > > > > > > > contextConfigLocation > > > > /WEB-INF/spring.xml > > > > > > > > > > > > > > > > org.springframework.web.context.ContextLoaderListener< > > /listener-class> > > > > > > > > > > > > > > > > com.listeners.SpringInit > > > > > > > > > > > > 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 > > > > > > > >