Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 79313 invoked from network); 25 Jul 2006 00:12:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Jul 2006 00:12:48 -0000 Received: (qmail 31491 invoked by uid 500); 25 Jul 2006 00:12:47 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 31473 invoked by uid 500); 25 Jul 2006 00:12:46 -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 31462 invoked by uid 99); 25 Jul 2006 00:12:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 17:12:46 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of bluenike@gmail.com designates 64.233.182.190 as permitted sender) Received: from [64.233.182.190] (HELO nf-out-0910.google.com) (64.233.182.190) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 17:12:44 -0700 Received: by nf-out-0910.google.com with SMTP id c31so68805nfb for ; Mon, 24 Jul 2006 17:12:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Du1aMl+/yvbKZJl2d9U4Urib8bgZzdC+Iz+OkZ5niLSSY8x5b4PsxBcQYg98apmoX5C4A7/UGNDdJGcd+R7aGad0g7To4REM+vGg01ucgZ506Y6LNDhP2DG+csa3WesfRwe2yVqbKdgPbAQUD6P+Q+4PSVdwDfcjewLtX8pfGeg= Received: by 10.78.185.7 with SMTP id i7mr2045902huf; Mon, 24 Jul 2006 17:12:22 -0700 (PDT) Received: by 10.78.130.17 with HTTP; Mon, 24 Jul 2006 17:12:22 -0700 (PDT) Message-ID: <62792ae00607241712s470f386dr7208d67f7ec22b1f@mail.gmail.com> Date: Mon, 24 Jul 2006 14:12:22 -1000 From: "Aaron Luke" To: user-java@ibatis.apache.org Subject: Re: ibatis, eclipse, and tomcat In-Reply-To: <2fe5ef5b0607220839l165055b8mb2138e7568b10304@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_129431_6296554.1153786342671" References: <62792ae00607212224m3de3275es49a8a53aaa1de1e6@mail.gmail.com> <2fe5ef5b0607220839l165055b8mb2138e7568b10304@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_129431_6296554.1153786342671 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks Brandon- that was extremely helpful... it may only be tangentially relevant to the ibatis product but it is related to the ibatis documentation- if the ibatis tutorial included the missing blanks you provide below (in addition to the typo corrections you made), then someone like myself who is coming from C++ can hit the ground with a working example and learn by tweaking... which i think is the preferred way of learning. I will submit your changes to whoever owns the tutorial pdf... It's neat that the Java world allows you to plug and play any component, but if documentation is completely tool-agnostic too, it's really going to make it difficult for novices to peek in... The only thing I didn't understand is regarding the lifecycle of the SqlMapClient object... It looks like the first thread to hit my jsp page with the getSqlMapInstance static method call would cause the class to be loaded. I assume that during class loading, the static method variable sqlMap instance is initialized. I also assume it is true that it is the class loader that ensures that the sqlMap instance is only initialized once? So for example, if the first thread to cause an instantiation sqlMap is switched out during the sqlMap constructor, and the machine switches to another jsp that then makes a call to getSqlMapInstance static method, then this second thread will block pending completion of the first thread's call to the constructor? Or is it the case that static method variables can be initialized multiple times and that the class developer must handle the synchronization? If so, is the SqlMaps constructor thread-safe? My concern was that the initialization was not thread-safe and Java does not handle synchronization for static class variable instantiation, which means that we would have to initialize sqlMap before splitting control threads- which would mean it couldn't occur in a jsp (but i don't know where that would be in tomcat- as an aside- does anyone know)... Is any of this correct? Anyway, thanks again for your response... I'll put up a howto on getting running with ibatis/tomcat/eclipse for oo programmers from other camps... I think it's a cool combo you can start working with on day one... instead of spending days wading through all of the other web frameworks and acronyms and getting too ahead of yourself... Aaron On 7/22/06, Brandon Goodin wrote: > > Hmmm, > > It sounds to me like you are new to the Java world Aaron. The questions > you are asking are only partially iBATIS questions... but I'll answer > anyways. In regards to eclipse you need to make sure your jars are on the > Build Path(Classpath in pure java terms). Assuming your project is setup as > a Java project and that you are in the Java Perspective in eclipse, you can > right click a .jar file and select "Build Path > Add To Build Path". > > In regards to using SQL Maps on a JSP, this is regarded as a bad practice > for most anything in the java world. JSP pages should be a very simple > display of data that is passed to it. > > You have stated two goals in your email. You want a quick prototyping > ability and scalability. "Quick" prototyping is a rather relative word. I > would recommend that for this type of thing you consider your development > methodology. Using techniques like XP can provide you with good prototyping > time while laying the foundations of scalability. > > Finally, to answer your question. You would want to create a class that > initializes and persists your SQLMap as a static instance variable. Your JSP > page would import that class and reference it through a getSqlMapClient > method. See the following class as an example. > > ----- Start example SqlMapConfig.java ------ > > package com.somebiz.myapp.dao.ibatis; > > import java.io.Reader; > > import com.ibatis.common.resources.Resources; > import com.ibatis.dao.client.DaoManager ; > import com.ibatis.sqlmap.client.SqlMapClient; > import com.ibatis.sqlmap.client.SqlMapClientBuilder; > > public class SqlMapConfig { > > private static final SqlMapClient sqlMapClient; > > static { > > try { > String resource = "com/somebiz/myapp/dao/ibatis/sqlmapconfig.xml"; > Reader reader = Resources.getResourceAsReader(resource); > sqlMapClient = SqlMapClientBuilder.buildSqlMapClient (reader); > } catch (Exception e) { > throw new RuntimeException("Could not initialize SqmMapConfig. > Cause: " + e); > } > } > > public static SqlMapClient getSqlMapClient() { > return sqlMapClient; > } > > } > > ----- End example SqlMapConfig.java ------ > > Cheers, > Brandon > > > On 7/21/06, Aaron Luke < bluenike@gmail.com> wrote: > > > > Hi- > > > > These are 2 newbie questions... I searched everywhere for the answer... > > if i do get the answer (if it didn't exist elsewhere), I promise to put it > > up in a tutorial for people looking to do the same... > > > > All I'm trying to do is make my way through the iBATIS SQLMaps tutorial > > ( > > http://cvs.apache.org/dist/ibatis/ibatis.java/docs/iBATIS-SqlMaps-2-Tutorial.pdf), > > but I'm trying to do this on Tomcat using an Eclipse environment. > > > > The first problem is that I'm wondering where the best place to put the > > MyAppSqlConfig instantiation if you are using just JSP... Do I just > > instantiate a sqlMap at the top of each JSP page? Or is there a better way > > to do this? > > > > The second problem is that I get an error from Eclipse in the IDE when I > > enter the statement "import com.ibatis.sqlmap.client.*;" at the top of > > file for a java class that is used by our jsp test page. The error says > > that the import cannot be resolved. I have put both of the jar files ( > > ibatis-sqlmap-2.jar and ibatis-common-2.jar) in the WEB-INF/lib > > directory by drag-n-drop into the IDE. That didn't work so I also put both > > of the jar files in the tomcat/shared/lib directory as well... that didn't > > work either... what's wrong? sorry i know this is more of an eclipse/tomcat > > question... > > > > Thank you for any help in advance... we are evaluating the ability of > > Java to do quick-and-dirty prototyping and iBATIS/Eclipse/Tomcat look like > > they have a lot of potential compared to what we usually use (Perl, Python, > > etc), in additional to being able to grow into a large-scale system... It's > > just the learning curve... > > > > Thanks- > > Aaron > > > > ------=_Part_129431_6296554.1153786342671 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks Brandon- that was extremely helpful... it may only be tangentially r= elevant to the ibatis product but it is related to the ibatis documentation= - if the ibatis tutorial included the missing blanks you provide below (in = addition to the typo corrections you made), then someone like myself who is= coming from C++ can hit the ground with a working example and learn by twe= aking... which i think is the preferred way of learning.  I will submi= t your changes to whoever owns the tutorial pdf...  It's neat that the= Java world allows you to plug and play any component, but if documentation= is completely tool-agnostic too, it's really going to make it difficult fo= r novices to peek in...

The only thing I didn't understand is regarding the lifecycle of th= e SqlMapClient object...  It looks like the first thread to hit my jsp= page with the getSqlMapInstance static method call would cause the class t= o be loaded.  I assume that during class loading, the static method va= riable sqlMap instance is initialized.  I also assume it is true that = it is the class loader that ensures that the sqlMap instance is only initia= lized once?  So for example, if the first thread to cause an instantia= tion sqlMap is switched out during the sqlMap constructor, and the machine = switches to another jsp that then makes a call to getSqlMapInstance static = method, then this second thread will block pending completion of the first = thread's call to the constructor?  Or is it the case that static metho= d variables can be initialized multiple times and that the class developer = must handle the synchronization?  If so, is the SqlMaps constructor th= read-safe? My concern was that the initialization was not thread-safe and J= ava does not handle synchronization for static class variable instantiation= , which means that we would have to initialize sqlMap before splitting cont= rol threads- which would mean it couldn't occur in a jsp (but i don't know = where that would be in tomcat- as an aside- does anyone know)...  Is a= ny of this correct?

Anyway, thanks again for your response...  I'll put up a howto= on getting running with ibatis/tomcat/eclipse for oo programmers from othe= r camps...  I think it's a cool combo you can start working with on da= y one...  instead of spending days wading through all of the other web= frameworks and acronyms and getting too ahead of yourself...

Aaron

On 7/22/06, Brand= on Goodin < brandon.goodin@gmail.com> wrote:
Hmmm,

It sounds to me like you are new to the Java world Aaron.= The questions you are asking are only partially iBATIS questions... but I'= ll answer anyways. In regards to eclipse you need to make sure your jars ar= e on the Build Path(Classpath in pure java terms). Assuming your project is= setup as a Java project and that you are in the Java Perspective in eclips= e, you can right click a .jar file and select "Build Path > Add To = Build Path".

In regards to using SQL Maps on a JSP, this is regarded as a bad pr= actice for most anything in the java world. JSP pages should be a very simp= le display of data that is passed to it.

You have stated two goals = in your email. You want a quick prototyping ability and scalability. "= Quick" prototyping is a rather relative word. I would recommend that f= or this type of thing you consider your development methodology. Using tech= niques like XP can provide you with good prototyping time while laying the = foundations of scalability.

Finally, to answer your question. You would want to create a class = that initializes and persists your SQLMap as a static instance variable. Yo= ur JSP page would import that class and reference it through a getSqlMapCli= ent method. See the following class as an example.

----- Start example SqlMapConfig.java ------

package com.som= ebiz.myapp.dao.ibatis;

import java.io.Reader;

import com.ibat= is.common.resources.Resources;
import com.ibatis.dao.client.DaoManager ;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sql= map.client.SqlMapClientBuilder;

public class SqlMapConfig {

&= nbsp; private static final SqlMapClient sqlMapClient;

  static = {

    try {
      String resource = =3D "com/somebiz/myapp/dao/ibatis/sqlmapconfig.xml";
 &nb= sp;    Reader reader =3D Resources.getResourceAsReader(resou= rce);
      sqlMapClient =3D SqlMapClientBuilde= r.buildSqlMapClient (reader);
    } catch (Exception e) {
  &nbs= p;   throw new RuntimeException("Could not initialize SqmMap= Config.  Cause: " + e);
    }
  }
  public static SqlMapClient getSqlMapClient() {
  &nbs= p; return sqlMapClient;
  }

}

----- End example SqlMapConfig.java ------
=
Cheers,
Brandon


On 7/21/06, Aaron Luke < bluenike@gmail.com> wrote:
Hi-

These are 2 newbie questions... = ; I searched everywhere for the answer... if i do get the answer (if it did= n't exist elsewhere), I promise to put it up in a tutorial for people looki= ng to do the same...

All I'm trying to do is make my way through the iBATIS SQLMaps tuto= rial ( http://cvs.apache.org/dist/ibatis/ibatis.java/docs/iBATIS-SqlMaps-2-Tutoria= l.pdf), but I'm trying to do this on Tomcat using an Eclipse environmen= t.

The first problem is that I'm wondering where the best place to put= the MyAppSqlConfig instantiation if you are using just JSP... Do I just in= stantiate a sqlMap at the top of each JSP page?  Or is there a better = way to do this?

The second problem is that I get an error from Eclipse in the IDE w= hen I enter the statement "import com.ibatis.sqlmap.client.*;" at= the top of file for a java class that is used by our jsp test page.  = The error says that the import cannot be resolved.  I have put both of= the jar files ( ibatis-sqlmap-2.jar and ibatis-common-2.jar) in the WEB-INF/lib directory b= y drag-n-drop into the IDE.  That didn't work so I also put both of th= e jar files in the tomcat/shared/lib directory as well... that didn't work = either... what's wrong?  sorry i know this is more of an eclipse/tomca= t question...=20

Thank you for any help in advance...  we are evaluating the ab= ility of Java to do quick-and-dirty prototyping and iBATIS/Eclipse/Tomcat l= ook like they have a lot of potential compared to what we usually use (Perl= , Python, etc), in additional to being able to grow into a large-scale syst= em...  It's just the learning curve...

Thanks-
Aaron


------=_Part_129431_6296554.1153786342671--