You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Schuerig <mi...@schuerig.de> on 2004/10/25 00:13:48 UTC
Running HSQLDB in-process?
I'm trying to run HSQLDB in in-process mode in a web application. For
this I've added a resource definition to the context file:
<Resource name="jdbc/verzeichnisdb" auth="Container"
type="javax.sql.DataSource" username="sa" password=""
driverClassName="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:file:/WEB-INF/db/verzeichnisdb;ifexists=true"
maxActive="3" maxIdle="2"/>
No problem so far. But there is a problem, when HSQLDB tries to open the
database and can't find it:
java.sql.SQLException: Database does not exists:
file:/WEB-INF/db/verzeichnisdb
Now, what I need is some hook where I can resolve this to an absolute
path. Unfortunately, what looks like an ordinary file-URL isn't one.
That is, AFAICT, it wouldn't help to resolve this to a jndi-URL (I
think that's what Tomcat does). If my understanding is correct, I need
an absolute file-URL as HSQLDB interprets the URL scheme to decide how
to access the database (server, file in-process, in-memory).
As a last resort, I could run HSQLDB as a server and be done with it.
But as only my single web app is using the DB there's no independent
reason to do this.
Michael
--
Michael Schuerig Not only does lightning not strike
mailto:michael@schuerig.de twice, it usually doesn't strike once.
http://www.schuerig.de/michael/ --Salman Rushdie, Fury
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Running HSQLDB in-process?
Posted by Michael Schuerig <mi...@schuerig.de>.
On Monday 25 October 2004 21:59, Michael Schuerig wrote:
> Ah, good to know! I was unaware that Tomcat substitute properties in
> context.xml. I dumped the properties in my servlet (an axis-based web
> service, actually) and there doesn't seem to be a suitable property
> available. But as I'm using Spring and Log4j anyway, I noticed that
>
> org.springframework.web.util.Log4jWebConfigurer in conjunction with
> org.springframework.web.util.Log4jConfigListener
>
> sets an appropriate property.
[snip]
> It's not pretty, rather fragile, really, as it depends on the right
> order of evaluation. The url attribute must be evaluated after
> mywebservice.root is already set.
Indeed, it's not pretty and it doesn't work :-(
Tomcat keeps its Properties global, not per application instance. Thus,
when I tried this method yesterday it worked I had another instance of
my webapp running in the same Tomcat process before. Therefore the
mywebservice.root property was already set. Then, when I reloaded the
webapp, the existing property is substituted for the variable in
context.xml. Alas, when the web app is started for the first time, the
property is not set.
Michael
--
Michael Schuerig Not only does lightning not strike
mailto:michael@schuerig.de twice, it usually doesn't strike once.
http://www.schuerig.de/michael/ --Salman Rushdie, Fury
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Running HSQLDB in-process?
Posted by Michael Schuerig <mi...@schuerig.de>.
On Monday 25 October 2004 18:52, Peter Rossbach wrote:
> I think you can used ${catalina.base} or other system env variables
> inside server.xml and context.xml
> for an absolute path information. Only problem with this handling is,
> don't save your server.xml oder context.xml
> with the admin application.
Ah, good to know! I was unaware that Tomcat substitute properties in
context.xml. I dumped the properties in my servlet (an axis-based web
service, actually) and there doesn't seem to be a suitable property
available. But as I'm using Spring and Log4j anyway, I noticed that
org.springframework.web.util.Log4jWebConfigurer in conjunction with
org.springframework.web.util.Log4jConfigListener
sets an appropriate property. It needs some declarations in web.xml:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>mywebservice.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
Then, in context.xml
<Context path="/mywebservice"
docBase="/home/michael/workspace/mywebservice/build">
<Resource name="jdbc/verzeichnisdb" auth="Container"
type="javax.sql.DataSource" username="sa" password=""
driverClassName="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:file:
${mywebservice.root}/WEB-INF/db/verzeichnisdb;ifexists=true"
maxActive="3" maxIdle="2"/>
</Context>
It's not pretty, rather fragile, really, as it depends on the right
order of evaluation. The url attribute must be evaluated after
mywebservice.root is already set.
> Tipp: use a db resource path outside your application, than deployer
> can delete all
> files without you lose the data! ;-)
Thanks for reminding me. In this case it's okay to lose the data as it's
read-only reference data.
Michael
--
Michael Schuerig The usual excuse for our most unspeakable
mailto:michael@schuerig.de public acts is that they are necessary.
http://www.schuerig.de/michael/ --Judith N. Shklar
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Running HSQLDB in-process?
Posted by Peter Rossbach <pr...@objektpark.de>.
Hey Michael,
I think you can used ${catalina.base} or other system env variables
inside server.xml and context.xml
for an absolute path information. Only problem with this handling is,
don't save your server.xml oder context.xml
with the admin application.
Tipp: use a db resource path outside your application, than deployer can
delete all
files without you lose the data! ;-)
hope it works,
Peter
Michael Schuerig schrieb:
>I'm trying to run HSQLDB in in-process mode in a web application. For
>this I've added a resource definition to the context file:
>
> <Resource name="jdbc/verzeichnisdb" auth="Container"
> type="javax.sql.DataSource" username="sa" password=""
> driverClassName="org.hsqldb.jdbcDriver"
> url="jdbc:hsqldb:file:/WEB-INF/db/verzeichnisdb;ifexists=true"
> maxActive="3" maxIdle="2"/>
>
>No problem so far. But there is a problem, when HSQLDB tries to open the
>database and can't find it:
>
> java.sql.SQLException: Database does not exists:
> file:/WEB-INF/db/verzeichnisdb
>
>Now, what I need is some hook where I can resolve this to an absolute
>path. Unfortunately, what looks like an ordinary file-URL isn't one.
>That is, AFAICT, it wouldn't help to resolve this to a jndi-URL (I
>think that's what Tomcat does). If my understanding is correct, I need
>an absolute file-URL as HSQLDB interprets the URL scheme to decide how
>to access the database (server, file in-process, in-memory).
>
>As a last resort, I could run HSQLDB as a server and be done with it.
>But as only my single web app is using the DB there's no independent
>reason to do this.
>
>Michael
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org