Thanks Brendan, This looks fine in principle. Will include in CVS for further tests.
Fred Toussi --------------- Brendan Ryan wrote: Hi, I have made a small change to allow a readonly hsqldb database (.script and .properties) to be stored in a JAR file so that it can be used with JWS. The feature is only active when the property "hsqldb.dbjarfile" is set to "true", and I believe the code to be quite harmless to normal operation. A sample jnlp file and the source patch (for current hsqldb-dev tree) are given below. I hope the code is useful for someone. Regards Brendan Ryan jnlp: <?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="file:///c:/ERM/internet/build/pass/"> <information> <title>Mask Builder</title> <vendor>PUI</vendor> <homepage href="http://www.pi-ag.com" /> <description>Demonstration of JNLP</description> <icon href="raptor.gif"/> </information> <offline-allowed/> <security> <all-permissions/> </security> <resources> <j2se version="1.4+" /> <jar href="pass-maskbuilder.jar"/> <jar href="jaxb-rt-1.0-ea.jar"/> <jar href="hsqldb-bry.jar"/> <jar href="testdb.jar"/> <property name="hsqldb.dbjarfile" value="true"/> <property name="jdbc.drivers" value="org.hsqldb.jdbcDriver"/> <property name="jdbc.url" value="jdbc:hsqldb:testdata/felder.hsqldb"/> <property name="jdbc.user" value="xxxx"/> <property name="jdbc.password" value="zzzz" /> </resources> <application-desc /> </jnlp> patch: Index: DatabaseScriptReader.java =================================================================== RCS file: /cvsroot/hsqldb/hsqldb-dev/src/org/hsqldb/DatabaseScriptReader.java,v retrieving revision 1.3 diff -u -r1.3 DatabaseScriptReader.java --- DatabaseScriptReader.java 11 Nov 2002 20:06:45 -0000 1.3 +++ DatabaseScriptReader.java 30 Dec 2002 14:22:00 -0000 @@ -46,7 +46,7 @@ */ class DatabaseScriptReader { - DataInputStream dataStreamIn; + InputStream dataStreamIn; Database db; int count; BufferedReader d; @@ -65,7 +65,11 @@ String file) throws SQLException, IOException { this.db = db; - dataStreamIn = new DataInputStream(new FileInputStream(file)); + if (org.hsqldb.Log.JARFILE) { + dataStreamIn = DatabaseScriptReader.class.getClassLoader().getResourceAsStream(file); + } else { + dataStreamIn = new DataInputStream(new FileInputStream(file)); + } d = new BufferedReader(new InputStreamReader(dataStreamIn)); } Index: HsqlDatabaseProperties.java =================================================================== RCS file: /cvsroot/hsqldb/hsqldb-dev/src/org/hsqldb/HsqlDatabaseProperties.java,v retrieving revision 1.8 diff -u -r1.8 HsqlDatabaseProperties.java --- HsqlDatabaseProperties.java 8 Dec 2002 01:55:19 -0000 1.8 +++ HsqlDatabaseProperties.java 30 Dec 2002 14:22:01 -0000 @@ -70,6 +70,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.sql.SQLException; /** @@ -79,7 +80,7 @@ */ class HsqlDatabaseProperties extends org.hsqldb.HsqlProperties { - private FileInputStream propsFileStream; // kept open until closed + private InputStream propsFileStream; // kept open until closed private HsqlDatabaseProperties() { super(); @@ -187,11 +188,14 @@ } try { + if (org.hsqldb.Log.JARFILE) { + propsFileStream = this.getClass().getClassLoader().getResourceAsStream(fileName + ".properties"); + } else { File f = new File(fileName + ".properties"); // the file is closed only when the database is closed propsFileStream = new FileInputStream(f); - + } stringProps.load(propsFileStream); } catch (Exception e) { throw Trace.error(Trace.FILE_IO_ERROR, Index: HsqlProperties.java =================================================================== RCS file: /cvsroot/hsqldb/hsqldb-dev/src/org/hsqldb/HsqlProperties.java,v retrieving revision 1.9 diff -u -r1.9 HsqlProperties.java --- HsqlProperties.java 30 Dec 2002 02:23:00 -0000 1.9 +++ HsqlProperties.java 30 Dec 2002 14:22:02 -0000 @@ -34,6 +34,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Method; import java.util.Enumeration; @@ -179,6 +180,9 @@ return false; } + if (org.hsqldb.Log.JARFILE) { + return (this.getClass().getClassLoader().getResource(fileName + ".properties") != null); + } return FileUtil.exists(fileName + ".properties"); } @@ -189,12 +193,16 @@ "properties name is null or empty"); } - FileInputStream fis = null; + InputStream fis = null; try { + if (org.hsqldb.Log.JARFILE) { + fis = this.getClass().getClassLoader().getResourceAsStream(fileName + ".properties"); + } else { File f = new File(fileName + ".properties"); fis = new FileInputStream(f); + } stringProps.load(fis); fis.close(); Index: Log.java =================================================================== RCS file: /cvsroot/hsqldb/hsqldb-dev/src/org/hsqldb/Log.java,v retrieving revision 1.15 diff -u -r1.15 Log.java --- Log.java 24 Dec 2002 00:33:01 -0000 1.15 +++ Log.java 30 Dec 2002 14:22:03 -0000 @@ -134,6 +134,7 @@ */ class Log implements Runnable { + public static boolean JARFILE = Boolean.getBoolean("hsqldb.dbjarfile"); // block size for copying data private static final int COPY_BLOCK_SIZE = 1 << 16; private HsqlDatabaseProperties pProperties; @@ -243,6 +244,7 @@ // save the current version pProperties.setProperty("hsqldb.version", jdbcDriver.VERSION); + if (JARFILE) pProperties.setProperty("readonly", "true"); if (pProperties.isPropertyTrue("readonly")) { bReadOnly = true; @@ -319,7 +321,11 @@ Cache getCache() throws SQLException { - if (cCache == null) { + if (JARFILE) { + return null; + } + + if (cCache == null) { cCache = new Cache(sFileCache, this.dDatabase); cCache.open(bReadOnly); Index: ScriptRunner.java =================================================================== RCS file: /cvsroot/hsqldb/hsqldb-dev/src/org/hsqldb/ScriptRunner.java,v retrieving revision 1.2 diff -u -r1.2 ScriptRunner.java --- ScriptRunner.java 16 Dec 2002 01:54:28 -0000 1.2 +++ ScriptRunner.java 30 Dec 2002 14:22:03 -0000 @@ -90,6 +90,9 @@ Trace.trace(); } + if (org.hsqldb.Log.JARFILE) { + if (ScriptRunner.class.getClassLoader().getResource(sFileScript) == null) return; + } else if (!FileUtil.exists(sFileScript)) { return; } ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hsqldb-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hsqldb-developers ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hsqldb-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hsqldb-developers