You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Ashish Kulkarni <ku...@yahoo.com> on 2005/10/24 17:50:15 UTC

best method to get SqlMapClient in web application

Hello
What is the best way to get SqlMapClient in a web
application
1 , Define a singleton pattern class, and create a
instance of SqlMapClient to use by all classes which
need to access data.

2, Define a AbstractClass and put method to get
SqlMapClient in constructor of this class, and then
each class which needs to get data extends this class


3, Create Instance of SqlMapClient in one of the init
servlets, and store this SqlMapClient in
ServletContext and pass it as one of the parameters to
all data classes

4, or any other method

Ashish


	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: best method to get SqlMapClient in web application

Posted by Larry Meadors <lm...@apache.org>.
The other issue with statics is that they are virtually impossible to
mock for testing.

One pattern I have used was to put references to my dao classes on my
business logic classes. I then created two constructors - one without
args, and one with the dao instances as parameters. The no-arg
constructor pulled the dao classes from the dao manager, and the other
injected them. That way, when I tested, I could plug in different dao
impls.

Spring makes this TONS easier though.

Larry


On 10/25/05, Jeff Butler <je...@gmail.com> wrote:
> I would say it's not *exactly* singleton, but close enough.  And it
> certainly works.  As to the question "why not this?", I have these thoughts:
>
> <joking>It's not cool as cool as the other ways, and we're all about
> cool</joking>
>
> On a more serious note, I do try to avoid Singletons and static
> methods/variables if possible.  Sometimes it's not possible, but if there is
> a simple alternative I will take it.  I think the best reason I can give for
> this philosophy is that I want to be in more explicit control over when
> initialization occurs.  Static variables are initialized at first class
> reference, and it's not always easy to predict when that will be.
>
> But, of course, this is more philosophy than science.  Sometimes in our
> efforts to do something elegant, we make things too complex.  There can be a
> trade off between simple and elegant - your milage may vary.  If it works,
> and is maintainable, and you are happy with it, then I say "go for it".
>
> Jeff Butler
>
>
>
> On 10/25/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
> > Alan
> > What you are doing is singleton pattern, it makes sure
> > that there is only one instance of SqlMapClient
> > through out your application.
> >
> > Ashish
> >
> >
> >
> > --- Alan Chandler <al...@chandlerfamily.org.uk> wrote:
> >
> > > On Monday 24 Oct 2005 16:50, Ashish Kulkarni wrote:
> > > > Hello
> > > > What is the best way to get SqlMapClient in a web
> > > > application
> > > > 1 , Define a singleton pattern class, and create a
> > > > instance of SqlMapClient to use by all classes
> > > which
> > > > need to access data.
> > > >
> > > > 2, Define a AbstractClass and put method to get
> > > > SqlMapClient in constructor of this class, and
> > > then
> > > > each class which needs to get data extends this
> > > class
> > > >
> > > >
> > > > 3, Create Instance of SqlMapClient in one of the
> > > init
> > > > servlets, and store this SqlMapClient in
> > > > ServletContext and pass it as one of the
> > > parameters to
> > > > all data classes
> > > >
> > > > 4, or any other method
> > >
> > > I have been following this thread without really
> > > understanding it.
> > >
> > > I would be interested in any comments on what I do,
> > > which I think is point 1
> > > (but I am new to Java and I am not sure I understand
> > > what a singleton is
> > > properly).  In particular, I am not sure I
> > > understand what the potential
> > > Gotcha's are.  Why doesn't everybody do it this way,
> > > it seems so SIMPLE.
> > >
> > > The reason I do this is that I am attempting to
> > > avoid creating a session to
> > > early in my application - but this has not been
> > > commented on in the thread at
> > > all.
> > >
> > > This is my basic class:
> > >
> > > package uk.org.chandlerfamily.sqlmap.famtree;
> > >
> > > import com.ibatis.common.resources.Resources;
> > > import com.ibatis.sqlmap.client.*;
> > > import java.io.Reader;
> > >
> > > public class FamtreeMap {
> > >       private static final SqlMapClient sqlMap;
> > >       static {
> > >         try {
> > >             String resource =
> > >
> > "uk/org/chandlerfamily/sqlmap/famtree/SqlMapConfig.xml";
> > >             Reader reader = Resources.getResourceAsReader
> > > (resource);
> > >             sqlMap =
> > > SqlMapClientBuilder.buildSqlMapClient(reader);
> > >          } catch (Exception e) {
> > >             e.printStackTrace();
> > >             throw new RuntimeException ("Error
> > > initializing DataMap class. Cause: "
> > > + e);
> > >          }
> > >       }
> > >       public static SqlMapClient getSqlMapInstance () {
> > >         return sqlMap;
> > >       }
> > >
> > > }
> > >
> > >
> > >
> > > and then whenever I want to do something with my
> > > database I do
> > >
> > >               SqlMapClient map=FamtreeMap.getSqlMapInstance ();
> > >               try {
> > >                       map.startTransaction();
> > > ...
> > > ...
> > >
> > > --
> > > Alan Chandler
> > > http://www.chandlerfamily.org.uk
> > > Open Source. It's the difference between trust and
> > > antitrust.
> > >
> >
> >
> >
> >
> > __________________________________
> > Yahoo! FareChase: Search multiple travel sites in one click.
> > http://farechase.yahoo.com
> >
>
>

Re: best method to get SqlMapClient in web application

Posted by Eugeny N Dzhurinsky <eu...@jdevelop.com>.
On Tue, Oct 25, 2005 at 10:00:31AM -0500, Jeff Butler wrote:
> I would say it's not *exactly* singleton, but close enough. And it certainly
> works. As to the question "why not this?", I have these thoughts:
>  <joking>It's not cool as cool as the other ways, and we're all about
> cool</joking>
>  On a more serious note, I do try to avoid Singletons and static
> methods/variables if possible. Sometimes it's not possible, but if there is
> a simple alternative I will take it. I think the best reason I can give for
> this philosophy is that I want to be in more explicit control over when
> initialization occurs. Static variables are initialized at first class
> reference, and it's not always easy to predict when that will be.
>  But, of course, this is more philosophy than science. Sometimes in our
> efforts to do something elegant, we make things too complex. There can be a
> trade off between simple and elegant - your milage may vary. If it works,
> and is maintainable, and you are happy with it, then I say "go for it".

Completely agree, initialization order of classes in general is ambigous, so
you may fall in mazy problems with simple reason at the background (some class
was depend of static section initialization of another class, but JVM thinks
in different way).

Regarding iBATIS SqlClientMap instance - in web application I'm keeping it
inside some static variable of some servlet, which is auto-loaded at container
startup, and then using static method to get an instance of this private
static member. That's it and it works fine :)

-- 
Eugene N Dzhurinsky

Re: best method to get SqlMapClient in web application

Posted by Jeff Butler <je...@gmail.com>.
I would say it's not *exactly* singleton, but close enough. And it certainly
works. As to the question "why not this?", I have these thoughts:
 <joking>It's not cool as cool as the other ways, and we're all about
cool</joking>
 On a more serious note, I do try to avoid Singletons and static
methods/variables if possible. Sometimes it's not possible, but if there is
a simple alternative I will take it. I think the best reason I can give for
this philosophy is that I want to be in more explicit control over when
initialization occurs. Static variables are initialized at first class
reference, and it's not always easy to predict when that will be.
 But, of course, this is more philosophy than science. Sometimes in our
efforts to do something elegant, we make things too complex. There can be a
trade off between simple and elegant - your milage may vary. If it works,
and is maintainable, and you are happy with it, then I say "go for it".
 Jeff Butler

 On 10/25/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
>
> Alan
> What you are doing is singleton pattern, it makes sure
> that there is only one instance of SqlMapClient
> through out your application.
>
> Ashish
>
>
>
> --- Alan Chandler <al...@chandlerfamily.org.uk> wrote:
>
> > On Monday 24 Oct 2005 16:50, Ashish Kulkarni wrote:
> > > Hello
> > > What is the best way to get SqlMapClient in a web
> > > application
> > > 1 , Define a singleton pattern class, and create a
> > > instance of SqlMapClient to use by all classes
> > which
> > > need to access data.
> > >
> > > 2, Define a AbstractClass and put method to get
> > > SqlMapClient in constructor of this class, and
> > then
> > > each class which needs to get data extends this
> > class
> > >
> > >
> > > 3, Create Instance of SqlMapClient in one of the
> > init
> > > servlets, and store this SqlMapClient in
> > > ServletContext and pass it as one of the
> > parameters to
> > > all data classes
> > >
> > > 4, or any other method
> >
> > I have been following this thread without really
> > understanding it.
> >
> > I would be interested in any comments on what I do,
> > which I think is point 1
> > (but I am new to Java and I am not sure I understand
> > what a singleton is
> > properly). In particular, I am not sure I
> > understand what the potential
> > Gotcha's are. Why doesn't everybody do it this way,
> > it seems so SIMPLE.
> >
> > The reason I do this is that I am attempting to
> > avoid creating a session to
> > early in my application - but this has not been
> > commented on in the thread at
> > all.
> >
> > This is my basic class:
> >
> > package uk.org.chandlerfamily.sqlmap.famtree;
> >
> > import com.ibatis.common.resources.Resources;
> > import com.ibatis.sqlmap.client.*;
> > import java.io.Reader;
> >
> > public class FamtreeMap {
> > private static final SqlMapClient sqlMap;
> > static {
> > try {
> > String resource =
> >
> "uk/org/chandlerfamily/sqlmap/famtree/SqlMapConfig.xml";
> > Reader reader = Resources.getResourceAsReader
> > (resource);
> > sqlMap =
> > SqlMapClientBuilder.buildSqlMapClient(reader);
> > } catch (Exception e) {
> > e.printStackTrace();
> > throw new RuntimeException ("Error
> > initializing DataMap class. Cause: "
> > + e);
> > }
> > }
> > public static SqlMapClient getSqlMapInstance () {
> > return sqlMap;
> > }
> >
> > }
> >
> >
> >
> > and then whenever I want to do something with my
> > database I do
> >
> > SqlMapClient map=FamtreeMap.getSqlMapInstance ();
> > try {
> > map.startTransaction();
> > ...
> > ...
> >
> > --
> > Alan Chandler
> > http://www.chandlerfamily.org.uk
> > Open Source. It's the difference between trust and
> > antitrust.
> >
>
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
>

Re: best method to get SqlMapClient in web application

Posted by Ashish Kulkarni <ku...@yahoo.com>.
Alan
What you are doing is singleton pattern, it makes sure
that there is only one instance of SqlMapClient
through out your application.

Ashish



--- Alan Chandler <al...@chandlerfamily.org.uk> wrote:

> On Monday 24 Oct 2005 16:50, Ashish Kulkarni wrote:
> > Hello
> > What is the best way to get SqlMapClient in a web
> > application
> > 1 , Define a singleton pattern class, and create a
> > instance of SqlMapClient to use by all classes
> which
> > need to access data.
> >
> > 2, Define a AbstractClass and put method to get
> > SqlMapClient in constructor of this class, and
> then
> > each class which needs to get data extends this
> class
> >
> >
> > 3, Create Instance of SqlMapClient in one of the
> init
> > servlets, and store this SqlMapClient in
> > ServletContext and pass it as one of the
> parameters to
> > all data classes
> >
> > 4, or any other method
> 
> I have been following this thread without really
> understanding it.  
> 
> I would be interested in any comments on what I do,
> which I think is point 1 
> (but I am new to Java and I am not sure I understand
> what a singleton is 
> properly).  In particular, I am not sure I
> understand what the potential 
> Gotcha's are.  Why doesn't everybody do it this way,
> it seems so SIMPLE.
> 
> The reason I do this is that I am attempting to
> avoid creating a session to 
> early in my application - but this has not been
> commented on in the thread at 
> all.
> 
> This is my basic class:
> 
> package uk.org.chandlerfamily.sqlmap.famtree;
> 
> import com.ibatis.common.resources.Resources;
> import com.ibatis.sqlmap.client.*;
> import java.io.Reader;
> 
> public class FamtreeMap {
> 	private static final SqlMapClient sqlMap;
> 	static {
> 	  try {
> 	      String resource = 
>
"uk/org/chandlerfamily/sqlmap/famtree/SqlMapConfig.xml";
> 	      Reader reader = Resources.getResourceAsReader
> (resource);
> 	      sqlMap =
> SqlMapClientBuilder.buildSqlMapClient(reader);
> 	   } catch (Exception e) {
> 	      e.printStackTrace();
> 	      throw new RuntimeException ("Error
> initializing DataMap class. Cause: " 
> + e);
> 	   }
> 	}
> 	public static SqlMapClient getSqlMapInstance () {
> 	  return sqlMap;
> 	}
> 
> }
> 
> 
> 
> and then whenever I want to do something with my
> database I do
> 
> 		SqlMapClient map=FamtreeMap.getSqlMapInstance();
> 		try {
> 			map.startTransaction();
> ...
> ...
> 
> -- 
> Alan Chandler
> http://www.chandlerfamily.org.uk
> Open Source. It's the difference between trust and
> antitrust.
> 



		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

Re: best method to get SqlMapClient in web application

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Monday 24 Oct 2005 16:50, Ashish Kulkarni wrote:
> Hello
> What is the best way to get SqlMapClient in a web
> application
> 1 , Define a singleton pattern class, and create a
> instance of SqlMapClient to use by all classes which
> need to access data.
>
> 2, Define a AbstractClass and put method to get
> SqlMapClient in constructor of this class, and then
> each class which needs to get data extends this class
>
>
> 3, Create Instance of SqlMapClient in one of the init
> servlets, and store this SqlMapClient in
> ServletContext and pass it as one of the parameters to
> all data classes
>
> 4, or any other method

I have been following this thread without really understanding it.  

I would be interested in any comments on what I do, which I think is point 1 
(but I am new to Java and I am not sure I understand what a singleton is 
properly).  In particular, I am not sure I understand what the potential 
Gotcha's are.  Why doesn't everybody do it this way, it seems so SIMPLE.

The reason I do this is that I am attempting to avoid creating a session to 
early in my application - but this has not been commented on in the thread at 
all.

This is my basic class:

package uk.org.chandlerfamily.sqlmap.famtree;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.*;
import java.io.Reader;

public class FamtreeMap {
	private static final SqlMapClient sqlMap;
	static {
	  try {
	      String resource = 
"uk/org/chandlerfamily/sqlmap/famtree/SqlMapConfig.xml";
	      Reader reader = Resources.getResourceAsReader (resource);
	      sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
	   } catch (Exception e) {
	      e.printStackTrace();
	      throw new RuntimeException ("Error initializing DataMap class. Cause: " 
+ e);
	   }
	}
	public static SqlMapClient getSqlMapInstance () {
	  return sqlMap;
	}

}



and then whenever I want to do something with my database I do

		SqlMapClient map=FamtreeMap.getSqlMapInstance();
		try {
			map.startTransaction();
...
...

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

Re: best method to get SqlMapClient in web application

Posted by Jeff Butler <je...@gmail.com>.
Sure - the singleton works fine. But you don't have to make the GetData
class dependant on the servlet. You could pass the SqlMapClient as a
parameter to the methods in your GetData class (or in a constructor) - then
there's no Servlet dependency
 Another thing to look at...iBATIS DAOs. Write your GetData class as an
iBATIS DAO. Then put a DAOManager in the servlet context. Your
servlets/actions/etc. could pull the DaoManager out of the context and
retrieve the DAO from the DaoManager. Everything is nicely encapsulated and
there are no unusual dependencies. This is what I always do if there is no
EJB container involved (with an EJB container, I would put the DAOManager in
a Singleton).
 Jeff Butler

 On 10/24/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
>
> Jeff
> Suppose if i have a following class
> GetData, which has following code
> sqlMapClient.delete("deleteCOExternal",coDataBean);
>
> This GetData class is being called by a servlet, then
> this servlet has to get sqlMapClient from servlet
> context and pass it to GetData class,
> this way we are tying GetData with servlet, If i have
> to call GetData without using servlet then i will have
> to design my own ServletContext type of setup.
>
> Have you ever tried to user singleton pattern to get
> sqlMapClient,
> and then in GetData class do
> GetMySqlMap.getInstance().getSqlMap()
> This way we dont have class GetData depend on servlet.
>
> Ashish
>
>
>
> --- Jeff Butler <je...@gmail.com> wrote:
>
> > Here's a listener:
> > package somepackage;
> >
> > import javax.servlet.ServletContextEvent ;
> > import javax.servlet.ServletContextListener;
> >
> > public class ContextListener implements
> > ServletContextListener {
> >
> > public ContextListener() {
> > super();
> > }
> > public void contextInitialized(ServletContextEvent
> > sce) {
> > // generate your client through normal methods
> > SqlMapClient client = createSqlMapClient();
> >
> >
> sce.getServletContext().setAttribute(SqlMapClient.class.getName(),
> > client);
> > }
> > public void contextDestroyed(ServletContextEvent
> > sce) {
> > }
> > }
> > Then you need to write a method somewhere like
> > this:
> > public SqlMapClient getSqlMapClient(ServletContext
> > context) {
> > return (SqlMapClient)
> > context.getAttribute(SqlMapClient.class.getName());
> > }
> > You also need to configure the listener in web.xml.
> > Pretty simple...
> > Jeff Butler
> >
> > On 10/24/05, Ashish Kulkarni
> > <ku...@yahoo.com> wrote:
> > >
> > > Jeff
> > > Can you provide me a sample code of putting
> > > SqlMapClient in servlet context with listener and
> > > access it from class which requires to access it
> > >
> > > Ashish
> > >
> > > --- Jeff Butler < jeffgbutler@gmail.com> wrote:
> > >
> > > > I don't know if it's the best or not, but I
> > often
> > > > times put the SqlMapClient
> > > > into the servlet context with a listener. I
> > think
> > > > this is essentially what
> > > > Spring does too.
> > > > Jeff Butler
> > > >
> > > > On 10/24/05, Ashish Kulkarni
> > > > < kulkarni_ash1312@yahoo.com> wrote:
> > > > >
> > > > > Hello
> > > > > What is the best way to get SqlMapClient in a
> > web
> > > > > application
> > > > > 1 , Define a singleton pattern class, and
> > create a
> > > > > instance of SqlMapClient to use by all classes
> > > > which
> > > > > need to access data.
> > > > >
> > > > > 2, Define a AbstractClass and put method to
> > get
> > > > > SqlMapClient in constructor of this class, and
> > > > then
> > > > > each class which needs to get data extends
> > this
> > > > class
> > > > >
> > > > >
> > > > > 3, Create Instance of SqlMapClient in one of
> > the
> > > > init
> > > > > servlets, and store this SqlMapClient in
> > > > > ServletContext and pass it as one of the
> > > > parameters to
> > > > > all data classes
> > > > >
> > > > > 4, or any other method
> > > > >
> > > > > Ashish
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > __________________________________
> > > > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > > > http://mail.yahoo.com
> > > > >
> > > >
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Start your day with Yahoo! - Make it your home
> > page!
> > > http://www.yahoo.com/r/hs
> > >
> >
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>

Re: best method to get SqlMapClient in web application

Posted by Ashish Kulkarni <ku...@yahoo.com>.
Jeff
Suppose if i have a following class 
GetData, which has following code
sqlMapClient.delete("deleteCOExternal",coDataBean);

This GetData class is being called by a servlet, then
this servlet has to get sqlMapClient from servlet
context and pass it to GetData class, 
this way we are tying GetData with servlet, If i have
to call GetData without using servlet then i will have
to design my own ServletContext type of setup.

Have you ever tried to user singleton pattern to get
sqlMapClient, 
and then in GetData class do 
GetMySqlMap.getInstance().getSqlMap()
This way we dont have class GetData depend on servlet.

Ashish



--- Jeff Butler <je...@gmail.com> wrote:

> Here's a listener:
>  package somepackage;
> 
> import javax.servlet.ServletContextEvent;
> import javax.servlet.ServletContextListener;
> 
> public class ContextListener implements
> ServletContextListener {
> 
> public ContextListener() {
> super();
> }
>  public void contextInitialized(ServletContextEvent
> sce) {
>  // generate your client through normal methods
>  SqlMapClient client = createSqlMapClient();
> 
>
sce.getServletContext().setAttribute(SqlMapClient.class.getName(),
>  client);
> }
>   public void contextDestroyed(ServletContextEvent
> sce) {
> }
> }
>  Then you need to write a method somewhere like
> this:
>  public SqlMapClient getSqlMapClient(ServletContext
> context) {
>  return (SqlMapClient)
>  context.getAttribute(SqlMapClient.class.getName());
> }
>  You also need to configure the listener in web.xml.
> Pretty simple...
>  Jeff Butler
> 
>  On 10/24/05, Ashish Kulkarni
> <ku...@yahoo.com> wrote:
> >
> > Jeff
> > Can you provide me a sample code of putting
> > SqlMapClient in servlet context with listener and
> > access it from class which requires to access it
> >
> > Ashish
> >
> > --- Jeff Butler <je...@gmail.com> wrote:
> >
> > > I don't know if it's the best or not, but I
> often
> > > times put the SqlMapClient
> > > into the servlet context with a listener. I
> think
> > > this is essentially what
> > > Spring does too.
> > > Jeff Butler
> > >
> > > On 10/24/05, Ashish Kulkarni
> > > <ku...@yahoo.com> wrote:
> > > >
> > > > Hello
> > > > What is the best way to get SqlMapClient in a
> web
> > > > application
> > > > 1 , Define a singleton pattern class, and
> create a
> > > > instance of SqlMapClient to use by all classes
> > > which
> > > > need to access data.
> > > >
> > > > 2, Define a AbstractClass and put method to
> get
> > > > SqlMapClient in constructor of this class, and
> > > then
> > > > each class which needs to get data extends
> this
> > > class
> > > >
> > > >
> > > > 3, Create Instance of SqlMapClient in one of
> the
> > > init
> > > > servlets, and store this SqlMapClient in
> > > > ServletContext and pass it as one of the
> > > parameters to
> > > > all data classes
> > > >
> > > > 4, or any other method
> > > >
> > > > Ashish
> > > >
> > > >
> > > >
> > > >
> > > > __________________________________
> > > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > > http://mail.yahoo.com
> > > >
> > >
> >
> >
> >
> >
> > __________________________________
> > Start your day with Yahoo! - Make it your home
> page!
> > http://www.yahoo.com/r/hs
> >
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: best method to get SqlMapClient in web application

Posted by Jeff Butler <je...@gmail.com>.
Here's a listener:
 package somepackage;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextListener implements ServletContextListener {

public ContextListener() {
super();
}
 public void contextInitialized(ServletContextEvent sce) {
 // generate your client through normal methods
 SqlMapClient client = createSqlMapClient();

sce.getServletContext().setAttribute(SqlMapClient.class.getName(),
 client);
}
  public void contextDestroyed(ServletContextEvent sce) {
}
}
 Then you need to write a method somewhere like this:
 public SqlMapClient getSqlMapClient(ServletContext context) {
 return (SqlMapClient)
 context.getAttribute(SqlMapClient.class.getName());
}
 You also need to configure the listener in web.xml. Pretty simple...
 Jeff Butler

 On 10/24/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
>
> Jeff
> Can you provide me a sample code of putting
> SqlMapClient in servlet context with listener and
> access it from class which requires to access it
>
> Ashish
>
> --- Jeff Butler <je...@gmail.com> wrote:
>
> > I don't know if it's the best or not, but I often
> > times put the SqlMapClient
> > into the servlet context with a listener. I think
> > this is essentially what
> > Spring does too.
> > Jeff Butler
> >
> > On 10/24/05, Ashish Kulkarni
> > <ku...@yahoo.com> wrote:
> > >
> > > Hello
> > > What is the best way to get SqlMapClient in a web
> > > application
> > > 1 , Define a singleton pattern class, and create a
> > > instance of SqlMapClient to use by all classes
> > which
> > > need to access data.
> > >
> > > 2, Define a AbstractClass and put method to get
> > > SqlMapClient in constructor of this class, and
> > then
> > > each class which needs to get data extends this
> > class
> > >
> > >
> > > 3, Create Instance of SqlMapClient in one of the
> > init
> > > servlets, and store this SqlMapClient in
> > > ServletContext and pass it as one of the
> > parameters to
> > > all data classes
> > >
> > > 4, or any other method
> > >
> > > Ashish
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > http://mail.yahoo.com
> > >
> >
>
>
>
>
> __________________________________
> Start your day with Yahoo! - Make it your home page!
> http://www.yahoo.com/r/hs
>

Re: best method to get SqlMapClient in web application

Posted by Ashish Kulkarni <ku...@yahoo.com>.
Jeff
Can you provide me a sample code of putting
SqlMapClient in servlet context with listener and
access it from class which requires to access it

Ashish

--- Jeff Butler <je...@gmail.com> wrote:

> I don't know if it's the best or not, but I often
> times put the SqlMapClient
> into the servlet context with a listener. I think
> this is essentially what
> Spring does too.
>  Jeff Butler
> 
>  On 10/24/05, Ashish Kulkarni
> <ku...@yahoo.com> wrote:
> >
> > Hello
> > What is the best way to get SqlMapClient in a web
> > application
> > 1 , Define a singleton pattern class, and create a
> > instance of SqlMapClient to use by all classes
> which
> > need to access data.
> >
> > 2, Define a AbstractClass and put method to get
> > SqlMapClient in constructor of this class, and
> then
> > each class which needs to get data extends this
> class
> >
> >
> > 3, Create Instance of SqlMapClient in one of the
> init
> > servlets, and store this SqlMapClient in
> > ServletContext and pass it as one of the
> parameters to
> > all data classes
> >
> > 4, or any other method
> >
> > Ashish
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
> 



		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

Re: best method to get SqlMapClient in web application

Posted by Jeff Butler <je...@gmail.com>.
I don't know if it's the best or not, but I often times put the SqlMapClient
into the servlet context with a listener. I think this is essentially what
Spring does too.
 Jeff Butler

 On 10/24/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
>
> Hello
> What is the best way to get SqlMapClient in a web
> application
> 1 , Define a singleton pattern class, and create a
> instance of SqlMapClient to use by all classes which
> need to access data.
>
> 2, Define a AbstractClass and put method to get
> SqlMapClient in constructor of this class, and then
> each class which needs to get data extends this class
>
>
> 3, Create Instance of SqlMapClient in one of the init
> servlets, and store this SqlMapClient in
> ServletContext and pass it as one of the parameters to
> all data classes
>
> 4, or any other method
>
> Ashish
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>

Re: best method to get SqlMapClient in web application

Posted by Michael Campbell <mi...@gmail.com>.
I'm using Spring's iBatis support for this.  Fairly easy to set up and
works very well.

On 10/24/05, Ashish Kulkarni <ku...@yahoo.com> wrote:
> Hello
> What is the best way to get SqlMapClient in a web
> application
> 1 , Define a singleton pattern class, and create a
> instance of SqlMapClient to use by all classes which
> need to access data.
>
> 2, Define a AbstractClass and put method to get
> SqlMapClient in constructor of this class, and then
> each class which needs to get data extends this class
>
>
> 3, Create Instance of SqlMapClient in one of the init
> servlets, and store this SqlMapClient in
> ServletContext and pass it as one of the parameters to
> all data classes
>
> 4, or any other method
>
> Ashish
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>


--
I tend to view "truly flexible" by another term: "Make everything
equally hard". -- DHH