Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 89994 invoked from network); 7 Dec 2005 06:27:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Dec 2005 06:27:37 -0000 Received: (qmail 1973 invoked by uid 500); 7 Dec 2005 06:27:35 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 1940 invoked by uid 500); 7 Dec 2005 06:27:34 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 1929 invoked by uid 99); 7 Dec 2005 06:27:34 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2005 22:27:34 -0800 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [61.95.200.204] (HELO mail2.world2web.com) (61.95.200.204) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 06 Dec 2005 22:27:31 -0800 Received: (qmail 2136 invoked from network); 7 Dec 2005 11:58:25 +0530 Received: from unknown (HELO polaris) (192.168.0.69) by 192.168.0.1 with SMTP; 7 Dec 2005 11:58:25 +0530 Reply-To: From: "Anuradha S.Athreya" To: "'Apache Torque Users List'" Subject: RE: Creating common connection pool Date: Wed, 7 Dec 2005 12:02:16 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 In-Reply-To: <8F5843B903F59D4C8C6806BB49A39119062908@dukece-mail3.dukece.com> Thread-Index: AcX3Kg/qPZdLN6E/SjWWlWxV2o46KQAIkEqAAIaom4AAE3DN4ABQhJ7g X-Virus-Checked: Checked by ClamAV on apache.org Message-Id: <20051207062734.37C4A10FB00B@asf.osuosl.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N I did place all the torque related jars in the shared/lib and Torque.properties file in the shared/classes folder. It was then I saw that I had a problem with the new connection being created every time. (and later sent out the related mail). I still havent been able to resolve this issue. Is there any configuration setting I need to change in the Torque.properties file? I did not see any parameter with which I could set the max no of connection which would be cached in a pool(Or is it same as torque.dsfactory.bookstore.pool.defaultMaxActive=10????) Please help! Regards Anuradha -----Original Message----- From: Greg Monroe [mailto:Greg.Monroe@DukeCE.com] Sent: Monday, December 05, 2005 9:57 PM To: Apache Torque Users List Subject: RE: Creating common connection pool D'oh... got my names mixed up... use Shared/lib for the Torque and support libs. Not common. Common is the one for engine/valves. Shared is for web-app shared libs. (But the JDBC drivers really should go in common since they can be used by valves, etc.) -----Original Message----- From: Greg Monroe [mailto:Greg.Monroe@DukeCE.com] Sent: Monday, December 05, 2005 9:53 PM To: torque-user@db.apache.org Subject: RE: Creating common connection pool On 1) One item I forgot to mention was that all the torque libs (supporting and torque*.jar) should probably be in the common/lib directory. What you are seeing is due to Tomcat's (and Java's) class loader hierarchy. Pooling uses static variables to maintain the list of connections. If a class is loaded from the WEB-INF lib directory, it (and the associated static vars) are separate from other web app classes of the same name. Putting the required jar files into the common\lib directory will let there be a single shared set of classes (and static pool vars). FWIW: Tomcat has multiple levels of loaders based on the various lib directories. System/lib is used for bootstraping, Shared/lib is used for "Engine" related items (like valve code, etc). Common/lib is used for stuff shared across web-apps. Generally, all shared application stuff should go into the commons/lib directory. Only use the higher two if you need to. On 2) Sorry, don't use Turbine so I can't help you there. > -----Original Message----- > From: Anuradha S.Athreya > > > Hi Greg, > > I did try this option and it worked like a charm! > > Couple of clarifications: > 1. This is the ConnectionPooling mechanism I'm using - as set in the > Torque.properties file: > > ## Using commons-dbcp > > torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory > .SharedPoolDat > aSourceFactory > > #torque.dsfactory.bookstore.factory=org.apache.torque.dsfactor > y.PerUserPoolD > ataSourceFactory > torque.dsfactory.bookstore.pool.defaultMaxActive=10 > torque.dsfactory.bookstore.pool.testOnBorrow=true > torque.dsfactory.bookstore.pool.validationQuery=SELECT 1 > torque.dsfactory.bookstore.connection.driver = com.mysql.jdbc.Driver > torque.dsfactory.bookstore.connection.url = > jdbc:mysql://localhost:3306/anuradhasa > torque.dsfactory.bookstore.connection.user = anuradhasa > torque.dsfactory.bookstore.connection.password = anuradhasa > > > Now, in the code to get a connection, when I invoke: > Connection conn = Torque.getConnection(); --- I observed > that it is creating a new connection object every time, > instead of using the same connection object from the > connection pool. Is this how it should happen? > > 2. We are currently using Turbine 2.1 ONLY for connection > pooling. Is it possible for me to initialise turbine similar > to how we initialised torque, common to 2 servlet contexts? > If I am able to achive this, I could continue with the > Turbine, instead of movinng to Torque. > > Regards > Anuradha > > -----Original Message----- > From: Greg Monroe [mailto:Greg.Monroe@DukeCE.com] > Sent: Friday, December 02, 2005 8:43 PM > To: Apache Torque Users List; anuradhasa@world2web.com > Subject: RE: Creating common connection pool > > Here's what I do: > > 1) Make sure your JDBC drivers are in the > /common/lib directory. This ensures that the > exact same classes will be shared across all web apps and let > you use them with Server level resources like Tomcat's > SingleSignOn valve and my help with Global Resource definitions. > > 2) In each WebApp, use a common ContextListener > implimentation class in the WebApp's WEB.XML file to > initialize things. Eg: add: > > > xxx.xxx.init.ContextListener > > > Torque is initialized in the > init.ContextListener.contextInitialized(...) > method. Note that because Torque should be initialized just > once and each context using this will call this method, you > should wrap your Torque init code in a check to see if it's > already been initialized. > > Here's a simplified version of the code I use: > > logger.info("Starting context: "+ arg0.getServletContext(). > getServletContextName()); > > if ( ! Torque.isInit() { > // Using getResource so real location of file can be found. > URL url = this.getClass().getClassLoader(). > getResource("Torque.properties"); // Note: > Don't use new > URI(url.toString()) - Tomcat will not resolve this!. > String path = url.getPath(); > if ( path != null && ! path.startsWith("/")) { > path = "/"+path; > } > URI uri = new URI(url.getProtocol(),"",path,null); > logger.debug("getDBConfigurationFile: Torque config url ="+ > uri.toString()); > File configFile = new File(uri); > Torque.init(configFile.toString()); > } > > 3) With the above code, the classpath (including jars) will > be searched for the "Torque.properties" file. To have a > single point of DB init, put a Torque.properties file in the > common/classes directory. > > For extra credit, you could think about using a > ServletContext init parameter in the Web.xml to allow for > alternate Torque properties file names rather than just a > hard coded default. > > Oh, and this works fine with simple shared connection > pooling. FWIW, I started using JNDI resources but found that > when apps got turned over to system admins to install on > production servers, they tended to get one or more of the XML > edits required to install it wrong.. > leading to more support time. So, I dropped the "right" way > to do things for the less support way. This way, once a > server's common code is set up, apps can be distributed by a > simple war file. > > > > -----Original Message----- > > From: Anuradha S.Athreya [mailto:anuradhasa@world2web.com] > > Sent: Friday, December 02, 2005 5:21 AM > > To: torque-user@db.apache.org > > Subject: Creating common connection pool > > > > > > I am trying to configure connection pooling using Torque for 2 web > > applications deployed in the same tomcat container but in 2 > different > > contexts,connecting to the same DB. > > > > Doubt 1: Where should the Torque.properties file be located? > > Obviously, the path of this file has to be with reference > to a servlet > > context. Since I want to create a common connection, which > one of the > > 2 servlet context will contain the properties file? > > > > I made changes to the Tomcat server.xml file : > > > > > docBase="D:/jakarta-tomcat-5.0.18/webapps/myApp1" > > > > scope="Shareable" type="javax.sql.DataSource"/> > > > > > > factory > > > > org.apache.torque.dsfactory.JndiDataSourceFactory > > > > > > > > > > url > > > > jdbc:mysql://localhost/myApp1DB > > > > > > > > driverClassNamecom.mysql.jdbc.Driver > > > > > > username > > myApp1 > > > > > > password > > myApp1 > > > > > > > > > > maxWait > > 30000 > > > > > > maxIdle > > 100 > > > > > > maxActive > > 10 > > > > > > > > > > Under normal circumstances, since i place the war files of the > > application, I dont specify the CONTEXT explicitly in the > server.xml > > file. But since. I need to place RESOURCE, here I added the CONTEXT > > tag. > > Since, I have 2 web applications deployed, will I have to > repeat the > > CONTEXT tag again for my 'myApp2'?? > > > > I have also made changes to the Tomcat web.xml file.. > > > > Added: > > > > DB Connection > > jdbc/instacoll > > javax.sql.DataSource > > Container > > > > > > > > Next comes the connection part.... > > > > Will Tomcat itself perform Torque.init()? > > > > If not, where should this be done, so that the Torque initialisation > > happens common to both the applications?? > > > > > > > > Duke CE Privacy Statement > Please be advised that this e-mail and any files transmitted > with it are confidential communication or may otherwise be > privileged or confidential and are intended solely for the > individual or entity to whom they are addressed. If you are > not the intended recipient you may not rely on the contents > of this email or any attachments, and we ask that you please > not read, copy or retransmit this communication, but reply to > the sender and destroy the email, its contents, and all > copies thereof immediately. Any unauthorized dissemination, > distribution or copying of this communication is strictly prohibited. > > > --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org