RE: How find DataSource?
It can be done, use poolman. Easiest DB pool to get going, works well with more DB than others. http://sourceforge.net/projects/poolman Edgar -Original Message- From: Vic Cekvenich [mailto:[EMAIL PROTECTED] Sent: Monday, December 22, 2003 4:50 PM To: [EMAIL PROTECTED] Subject: Re: How find DataSource? e-denton Java Programmer wrote: Has anyone set up a connection pool using web.xml? Steps? Examples? Tips? No one has, it can't be done. You can declare it in web.xml, that's all. Read Rick Reumans tutorial on ibatis dao and ibatis petstore 3 example and do that, and you will be in a good place. It's sad, no books on this. All JDBC books talk about JDBC 1.0, not about JDBC 3 pooleddatasource, or DAO. Vic, I might have two problems with keeping it in a static block. 1. My container can be passivated, so everything must be serializable. Passivation is not a good idea ever, so just ignore it. Change the co-lo or host if you have to. It sure does not give scalability to the host or to app. hth, .V - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How find DataSource?
Hi, How about a plugIn? Regards marco -Original Message- From: e-denton Java Programmer [mailto:[EMAIL PROTECTED] Sent: 22 December 2003 14:11 To: Struts Users Mailing List Subject: Re: How find DataSource? Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples -howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
I put mine in a static block of the base DAO. (static as in once per class, and all DAO's extend my base DAO). .V e-denton Java Programmer wrote: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
how about putting it into DynaActionForm::initialize which initialises the beans anyhow.. -Martin this way your connections are - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, December 22, 2003 9:31 AM Subject: Re: How find DataSource? I put mine in a static block of the base DAO. (static as in once per class, and all DAO's extend my base DAO). .V e-denton Java Programmer wrote: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
repost (news error?) Martin Gainty wrote: how about putting it into DynaActionForm::initialize which initialises the beans anyhow.. -Martin A DAO in a form or a bean hmmm. If that is what you want to do in an MVC framework. I don't do data source in formbeans. Take a peak at PetStore 3 on ibatis. (even Spring uses that as MVC example, but not w/ Struts) .V - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
I neglected to mention that my servlet container can be passivated on my virtual host. So, all objects must be serializable and I can't use static variables. - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, December 22, 2003 8:31 AM Subject: Re: How find DataSource? I put mine in a static block of the base DAO. (static as in once per class, and all DAO's extend my base DAO). .V e-denton Java Programmer wrote: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
Quoting e-denton Java Programmer [EMAIL PROTECTED]: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. That turns out not to be the recommended pattern, for at least two reasons: * If your app server supports the ability to dynamically reconfigure DataSource objects while your app is running, the object retrieved via JNDI might change each time. * If you retrieve it once and then put it someplace (such as in a servlet context attribute) then any code that wants to retrieve it will need a reference to the ServletContext object (and therefore be dependent on the servlet API). Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Consider setting up a utility class with a public static method called getDataSource() that actually does the lookup every time. Then you can call it like: DataSource ds = MyUtils.getDataSource(jdbc/TestDB); or, even go a step farther and have it return a connection for you ... that way you're hiding how the connection pooling is being done as well, and just operating at the SQL level. Thanks again, Will Craig - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
Quoting e-denton Java Programmer [EMAIL PROTECTED]: I neglected to mention that my servlet container can be passivated on my virtual host. So, all objects must be serializable and I can't use static variables. Yet another reason to look it up every time rather than caching it. Craig - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, December 22, 2003 8:31 AM Subject: Re: How find DataSource? I put mine in a static block of the base DAO. (static as in once per class, and all DAO's extend my base DAO). .V e-denton Java Programmer wrote: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
Wow, my personal saga of discovery continues... Apparently I have been trying to set up connection pooling *both* in server.xml context *and* in web.xml unnecessarily. Well, the server.xml works, but then I have the problem of where to store the DataStore object and how my Data Access Objects will access it. Has anyone set up a connection pool using web.xml? Steps? Examples? Tips? I can't even seem to change the driver without problems. And, web.xml doesn't use JNDI, does it? Has anyone used server.xml instead? Where did you keep the DataSource Object? I looked into keeping it in the session, but then I have to pass session to my DAOs--ick. (I am writing my own DAOs.) Vic, I might have two problems with keeping it in a static block. 1. My container can be passivated, so everything must be serializable. 2. I hope to only look it up once for efficiency's sake. Martin, I assume you mean to extend DynaActionForm and override initialize, but that means tying myself to Struts. (Like I'm not already!) Ideally, I shouldn't have to modify the framework. Thanks, Will - Original Message - From: Martin Gainty [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Monday, December 22, 2003 1:41 PM Subject: Re: How find DataSource? how about putting it into DynaActionForm::initialize which initialises the beans anyhow.. -Martin this way your connections are - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, December 22, 2003 9:31 AM Subject: Re: How find DataSource? I put mine in a static block of the base DAO. (static as in once per class, and all DAO's extend my base DAO). .V e-denton Java Programmer wrote: Merry Christmas, Wow, I finally connected to my data source! Now, I want to put the code somewhere it will be executed only once, and save the DataSource object where Actions, beans, etc. can get at it. That way, I don't have to perform the lookup all the time. Any suggestions on where to put the one time setup code, and where to save the DataSource object reference (in the application?). Thanks again, Will - Original Message - From: Vic Cekvenich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, December 20, 2003 12:14 PM Subject: Re: How find DataSource? See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
e-denton Java Programmer wrote: Has anyone set up a connection pool using web.xml? Steps? Examples? Tips? No one has, it can't be done. You can declare it in web.xml, that's all. Read Rick Reumans tutorial on ibatis dao and ibatis petstore 3 example and do that, and you will be in a good place. It's sad, no books on this. All JDBC books talk about JDBC 1.0, not about JDBC 3 pooleddatasource, or DAO. Vic, I might have two problems with keeping it in a static block. 1. My container can be passivated, so everything must be serializable. Passivation is not a good idea ever, so just ignore it. Change the co-lo or host if you have to. It sure does not give scalability to the host or to app. hth, .V - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How find DataSource?
Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How find DataSource?
See sample source code section here: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Ex: Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); Of course what you do with the data source depends on your DAO implementataion (iBatis, Hibrenate, etc.) .V hylepc wrote: Hi, From a Data Acess Object (DAO), I need to access a DataSource (like getServletContext().getAttribute (Globals.DATA_SOURCE_KEY)). But, I don't have access to the servlet variable. What is the proper way to get the DataSource from a DAO which is called by an Action but doesn't extend Action? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]