John,
FWIW, the simplest way I have found to init torque within a web app is to
write a simple servlet (InitServlet) which is set up in the web.xml as the
first servlet to run. It only provides an init method which simply invokes the
Torque.init() method. There are other ways, but an init servlet is simple and
provides a nice hook for other startup tasks as needed.
Something like:
package your.package.here;
import org.apache.torque.Torque;
import javax.servlet.*;
import javax.servlet.http.*;
public class InitServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try {
String propFileName = config.getInitParameter("propFile");
if( propFileName==null ) {
propFileName="WEB-INF/Torque.properties";
}
String propFile = getServletContext().getRealPath(propFileName);
Torque.init(propFile);
}
catch(Exception e){
throw new ServletException(e.getMessage());
}
}
}
Hope this helps.
David Hainlin
katre wrote:
> Hello all,
>
> I recently started writing a (fairly simple) webapplication using
> Struts, but I needed something to handle object persistence from my DB.
> I thought for a bit about writing my own code to do this, then realized
> that someone must have done it already. :) So I found Torque.
>
> Setting up Torque, while difficult (I tried running through the tutorial
> with no success. Is it written for the current (3.0-b3) version?),
> wasn't too bad. I managed to integrate it with my existing build
> system, to auto-generate the SQL to create the database and schema, and
> even to roll it into a WAR for easy deployment.
>
> I then wrote a small command-line test app, which worked fine. But when
> I tried to integrate Torque with my webapp, I had several problems.
> First was that I wasn't sure how to initialize Torque inside the webapp,
> given that the Torque.properties file was also inside the webapp. After
> a busy day of coding, I figured out how to load the properties file as a
> resource (via the classloader), convert that to a
> PropertiesConfiguration, and initialize Torque with that. I was on my
> way!
>
> Except. I cannot figure out what to do with the logs Torque is trying
> to open. Torque initialization is trying to open the logs, and Tomcat
> is reporting various types of AccessControlException. The odd part is
> that I updated the properties file to write all the logs to
> /var/log/webapps/, but the exception is coming from an attempt to acces
> './logs', which isn't mentioned in the properties file anywhere! I also
> noticed that whenever I run the Torque build scripts (from ant, from the
> commandline) a file named 'velocity.log' is created in the current
> directory.
>
> How can I reconfigure Torque to put the logs in the proper place? Am I
> doing something incredibly stupid? Does anyone have any advice for my
> silly little webapp?
>
> Thanks for your help,
> John Cater
> [EMAIL PROTECTED]
>
> ------------------------------------------------------------------------
> Part 1.2Type: application/pgp-signature
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>