ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Luke" <bluen...@gmail.com>
Subject Re: ibatis, eclipse, and tomcat
Date Tue, 25 Jul 2006 00:12:22 GMT
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...


On 7/22/06, Brandon 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 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
> >

View raw message