Setting a database read only programmaticaly

13 views
Skip to first unread message

aaime

unread,
Aug 11, 2007, 1:16:37 PM8/11/07
to H2 Database
Hi,
I'm trying to migrate a GeoTools module using the HSQL db to H2,
because I need better performance.
Now, the migration of the code is done, and the unit tests of the
module, abused as a benchmark, show a 50% speedup (22 seconds H2, 34
seconds HSQL).
So far so good, but there is a catch. This database is not something
the user sees or plays with, it is created on the file in the temp
directory the first time the module is used, and then kept there. To
allow multiple GeoTools applications to use the database at the same
time, in HSQL with add the readonly=true property in the database
property file.
I read in the FAQ that to make a database read only one has to use the
operating system. This is very inconvenient, and not fully true...
File.setReadOnly() may allow to make a file read only, but then there
is no command to make it read write, and some time this is needed. In
particular, when we ship a new release of the module, the database
contents may change, and we keep a version number around, if the
cached database in the temp directory has a lower number, it gets
wiped out and recreated. This works with HSQL because the connection
to the db is read only, but not the files...
Any change we can get a similar behaviour from H2? Maybe through a
connection parameter, I don't know, any programmatic way is good.

Cheers
Andrea Aime

Thomas Mueller

unread,
Aug 13, 2007, 4:16:13 PM8/13/07
to h2-da...@googlegroups.com
Hi,

The best solution would be if each sessions can individually be made
read-only. But there is currently no such feature. I will add a
feature request, but it will take some time until this is implemented
(unless you want to implement it yourself).

Thanks,
Thomas

Reply all
Reply to author
Forward
0 new messages