Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 3298 invoked from network); 10 Apr 2007 17:10:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Apr 2007 17:10:32 -0000 Received: (qmail 8527 invoked by uid 500); 10 Apr 2007 17:10:35 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 8513 invoked by uid 500); 10 Apr 2007 17:10:35 -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 8502 invoked by uid 99); 10 Apr 2007 17:10:35 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2007 10:10:35 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of Christian.Poitras@ircm.qc.ca designates 207.162.51.27 as permitted sender) Received: from [207.162.51.27] (HELO pandore.ircm.qc.ca) (207.162.51.27) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2007 10:10:28 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C77B93.172775F9" Subject: RE: iBATIS, Spring, and transactions... Date: Tue, 10 Apr 2007 13:10:08 -0400 Message-ID: <5820E7E2A928DB46824297946AC2024A9A6213@pandore.ircm.priv> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: iBATIS, Spring, and transactions... Thread-Index: Acd7euQi7Z5e7JwjTaGQSOLi7MJZ5wAALf0gAAQQQjAAAYtkIA== References: <5820E7E2A928DB46824297946AC2024A9A6210@pandore.ircm.priv> From: "Poitras Christian" To: X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. ------_=_NextPart_001_01C77B93.172775F9 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable First, you can still use BeanAction with Spring DAO. =20 The most simple solution to set your static variable is to get it from Spring. First get the SpringContext and do the following. private static final TheService instance =3D springContext.getBean("theService"); =20 The way you can get SpringContext is relaitve on how you initialize it. This is a code sample of how you can access it if you use org.springframework.web.context.ContextLoaderListener. /** * Listen for Spring initialization. *=20 * @author poitrac */ public class SpringInit implements ServletContextListener { =20 /** * Spring's WebApplicationContext. */ private static WebApplicationContext springContext; =20 public SpringInit() { super(); } =20 /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Se rvletContextEvent) */ public void contextInitialized(ServletContextEvent event) { springContext =3D WebApplicationContextUtils.getWebApplicationContext(event.getServletCont ext()); } =20 /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.Serv letContextEvent) */ public void contextDestroyed(ServletContextEvent event) { } =20 /** * Returns Spring's WebApplicationContext. * @return Spring's WebApplicationContext. */ public static ApplicationContext getApplicationContext() { return springContext; } } =20 Christian ________________________________ From: Meindert [mailto:meindert@pastelebusiness.com]=20 Sent: Tuesday, 10 April 2007 12:30 To: user-java@ibatis.apache.org Subject: RE: iBATIS, Spring, and transactions... I'm busy converting and went to the site http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp What is quite a clear explanation :-) =20 I'm converting a project that is based on the jpetstore, what is using org.apache.struts.beanaction.BeanAction in my struts-config.xml The above mentioned site has got a different approach. My question is; a) can I still use org.apache.struts.beanaction.BeanAction? I only want to change the DAO to Spring DAO because IBATIS DAO is depreciated and if so b) The BeanAction class is using private static final TheService theService =3D TheService.getInstance(); to connect with the service object, what created itself static; private static final TheService instance =3D new TheService(); =20 How do I get a instance from the spring created service object? My service object get's created by spring using the following config in spring.xml; And code; public TheService (TheDao theDao){ this.theDao =3D theDao; } =20 Kind Regards Meindert =20 =20 =20 -----Original Message----- From: Poitras Christian [mailto:Christian.Poitras@ircm.qc.ca]=20 Sent: 10 April 2007 04:25 PM To: user-java@ibatis.apache.org; lmeadors@apache.org Subject: RE: iBATIS, Spring, and transactions... =20 That would be a great idea! It's always welcome to see some code to show each steps. My app is already to big to use it direclty as an example...=20 =20 Christian =20 I'll check if I can provide you with my smaller app (contains only 2 actions, but it does not have any transaction). I'll just add the insert/updates I used at first to fill database. =20 -----Original Message----- From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of Larry Meadors Sent: Tuesday, 10 April 2007 10:16 To: user-java@ibatis.apache.org Subject: Re: iBATIS, Spring, and transactions... =20 That would be AWESOME, if you want, I can help with proofing, etc. =20 Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. =20 Larry =20 =20 On 4/10/07, Poitras Christian wrote: > I have to say that it would be really nice to have an "how to" for=20 > passing from iBATIS DAO to Spring DAO... > I made a french document about that question. I could transalte it to=20 > english in the next weeks and put it on the wiki... ------_=_NextPart_001_01C77B93.172775F9 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
First, you can still use BeanAction with Spring = DAO.
 
The most simple solution to set your static = variable is to=20 get it from Spring.
First get the SpringContext and do the=20 following.
private static final = TheService instance=20 =3D springContext.getBean("theService");
 
The way you can get SpringContext is = relaitve on how=20 you initialize it. This is a code sample of how you can access it if you = use=20 org.springframework.web.context.ContextLoaderListener.
/**
 * Listen for Spring=20 initialization.
 *
 * @author = poitrac
 */
public=20 class SpringInit implements ServletContextListener = {
   =20
    /**
     * Spring's=20 WebApplicationContext.
     = */
   =20 private static WebApplicationContext = springContext;
   =20
    public SpringInit()=20 {
        = super();
   =20 }
   
    /*=20 (non-Javadoc)
     * @see=20 javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Ser= vletContextEvent)
    =20 */
    public void = contextInitialized(ServletContextEvent=20 event) {
        springContext =3D = WebApplicationContextUtils.getWebApplicationContext(event.getServletConte= xt());
   =20 }
   
    /*=20 (non-Javadoc)
     * @see=20 javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.Servl= etContextEvent)
    =20 */
    public void = contextDestroyed(ServletContextEvent event)=20 {
    }
   
   =20 /**
     * Returns Spring's=20 WebApplicationContext.
     * @return Spring's=20 WebApplicationContext.
     = */
   =20 public static ApplicationContext getApplicationContext()=20 {
        return=20 springContext;
    }
}
 
Christian


From: Meindert=20 [mailto:meindert@pastelebusiness.com]
Sent: Tuesday, 10 April = 2007=20 12:30
To: user-java@ibatis.apache.org
Subject: RE: = iBATIS,=20 Spring, and transactions...

I'm busy converting and = went to=20 the site = http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp<= /o:p>

What is quite a clear = explanation=20 :-)

 

I'm converting a project = that is=20 based on the jpetstore, what is using = org.apache.struts.beanaction.BeanAction in=20 my struts-config.xml

The above mentioned site = has got a=20 different approach.

My question=20 is;

a) can I still use=20 org.apache.struts.beanaction.BeanAction? I only want to change the DAO = to Spring=20 DAO because IBATIS DAO is depreciated

and if=20 so

b) The BeanAction class = is=20 using

private static final = TheService=20 theService =3D TheService.getInstance();

to connect with the = service=20 object, what created itself static;

private static final = TheService instance=20 =3D new TheService();

 

How do I get a instance = from the=20 spring created service object?

My service object = get’s created by=20 spring using the following config in = spring.xml;

<bean id=3D" theService "=20 class=3D"com.service.TheService ">

       =20 <constructor-arg index=3D"0" = ref=3D"theDao"/>

   =20 </bean>

And=20 code;

public TheService (TheDao=20 theDao){

      = this.theDao =3D theDao;

  = }

 

Kind Regards

 Meindert

 

 

 

-----Original Message-----
From: Poitras = Christian=20 [mailto:Christian.Poitras@ircm.qc.ca]
Sent: 10 April 2007 04:25 = PM
To:=20 user-java@ibatis.apache.org;=20 lmeadors@apache.org
Subject: RE:=20 iBATIS, Spring, and transactions...

 

That would be a great = idea!

It's always welcome to see some code to show = each steps.=20 My app is

already to big to use it direclty as an = example...=20

 

Christian

 

I'll check if I can provide you with my = smaller app=20 (contains only 2

actions, but it does not have any=20 transaction).

I'll just add the insert/updates I used at = first to fill=20 database.

 

-----Original = Message-----

From: larry.meadors@gmail.com=20 [mailto:larry.meadors@gmail.com] On Behalf

Of Larry Meadors

Sent: Tuesday, 10 April 2007=20 10:16

To: user-java@ibatis.apache.org

Subject: Re: iBATIS, Spring, and=20 transactions...

 

That would be AWESOME, if you want, I can help = with=20 proofing, etc.

 

Maybe someone else would be willing to provide = a=20 *simple* iBATIS DAO

sample application that we could convert and = then=20 document the process.

 

Larry

 

 

On 4/10/07, Poitras Christian=20 <Christian.Poitras@ircm.qc.ca> wrote:

> I have to say that it would be really = nice to have=20 an "how to" for

> passing from iBATIS DAO to Spring=20 DAO...

> I made a french document about that = question. I=20 could transalte it to

> english in the next weeks and put it on = the=20 wiki...

------_=_NextPart_001_01C77B93.172775F9--