db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralf Baumert <ralf.baum...@phlat-labs.de>
Subject Re: Getting/releasing a connection from Torque pool
Date Wed, 23 Jul 2003 16:54:16 GMT
Hi Chris,

> I would like to know the best way to aquire a connection from the Torque
> pool and how to return that connection when finished. Currently I am
> using Torque.getConnection() to aquire a connection. Is this right? How
> to I return it once I am done?

i´m doing this in my jsps:

// get connection from pool
if (! Torque.isInit()) { Torque t = new Torque(); 
t.init(getServletContext().getInitParameter("torque-path")); }
Connection con = Torque.getConnection();
if (con == null || con.isClosed())
  throw new Exception("Could not connect to db" );

// free resources
rs.close();
ps.close();

Torque.closeConnection(con);

torque-path is an absolute path to your Torque.properties file.

You can also initialize Torque at application startup with a servet. this lets 
you get rid of the first row "if(!Roque.isInit..."

here´s my init servlet:

public class TorqueInit extends HttpServlet {

Torque t;

  public void init() {

    t = new Torque();

    try {
      String path = getServletContext().getInitParameter("torque-path");
      t.init(path);
    }
    catch(Exception e) {
        System.err.println(e.toString() );
    }
  }

  public void doGet(HttpServletRequest req, HttpServletResponse res) {}
}

params in web.xml:

  <context-param>
        <param-name>torque-path</param-name>
   
<param-value>/usr/local/tomcat/webapps/application/WEB-INF/Torque.properties</param-value>
      <description>
        The absolute path to Torques config file
      </description>
    </context-param>


    <servlet>
      <servlet-name>torque-init</servlet-name>
      <servlet-class>phlatcms.TorqueInit</servlet-class>
      <init-param>
        <param-name>torque-resource-directory</param-name>
        
<param-value>/usr/local/tomcat/webapps/application/WEB-INF</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
    </servlet>

Hope this helps & regards,
Ralf

------------------------------------
phlat-labs
Applikationsentwicklung & Consulting
Ralf Baumert
ralf.baumert@phlat-labs.de
http://www.phlat-labs.de

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message