You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Satheesh Bandaram <sa...@Sourcery.Org> on 2005/08/25 20:57:37 UTC
Re: svn commit: r240111 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/
testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Dan, good catch. There was a post about 2 weeks back that said soft
upgrade doesn't work for read-only databases (including database in a
JAR) It raises the error "ERROR 40XD1: Container was opened in read-only
mode." I reproduced the problem and analysed it a little. It seems
problem shows up in DD_Version.upgradeIfNeeded(). We seem to set a
property value and since the container is read-only, it throws the
error. If I avoid DD_Version.applySafeChanges(), since no changes can be
applied in read-only mode, I was able to boot the database.
The question is do you see any problems in supporting soft-upgrade for
read-only databases?
Satheesh
djd@apache.org wrote:
>Author: djd
>Date: Thu Aug 25 11:02:57 2005
>New Revision: 240111
>
>URL: http://svn.apache.org/viewcvs?rev=240111&view=rev
>Log:
>DERBY-540 Do not prepend database name for classpath databases with leading slash.This causes
>databases to be not found when in jar files on the database. Correct the lookup of resources
>in the class path storage factory to not use the methods that prepend the current class name,
>instead use methods from ClassLoader directly. The leading slash was incorrectly added to avoid
>the automatic package prepending performed by Class.getResource.
>Removed code that tried to optimise not using the thread context class loader, simply have a
>fixed lookup for resources of thread context class loader followed by class loader for Derby/system classloader.
>Add lang/dbjar.sql to test databases within a jar and within a jar on the classpath and class loading from such databases.
>
>Added:
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out (with props)
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar (with props)
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql (with props)
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java (with props)
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties (with props)
>Modified:
> db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java
> db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
>
>Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java?rev=240111&r1=240110&r2=240111&view=diff
>==============================================================================
>--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java (original)
>+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java Thu Aug 25 11:02:57 2005
>@@ -21,13 +21,9 @@
> package org.apache.derby.impl.io;
>
> import org.apache.derby.io.StorageFile;
>-import org.apache.derby.io.StorageRandomAccessFile;
>-
>-import org.apache.derby.iapi.services.sanity.SanityManager;
>
> import java.io.InputStream;
>-import java.io.OutputStream;
>-import java.io.IOException;
>+
> import java.io.FileNotFoundException;
>
> /**
>@@ -38,9 +34,7 @@
> {
>
> private final CPStorageFactory storageFactory;
>- private int actionCode;
>- private static final int EXISTS_ACTION = 1;
>-
>+
> CPFile( CPStorageFactory storageFactory, String path)
> {
> super( storageFactory, path);
>@@ -72,19 +66,24 @@
> */
> public boolean exists()
> {
>- if( storageFactory.useContextLoader)
>- {
>- ClassLoader cl = Thread.currentThread().getContextClassLoader();
>- if( cl != null && cl.getResource( path) != null)
>- return true;
>- }
>- if( getClass().getResource( path) != null)
>- {
>- if( storageFactory.useContextLoader)
>- storageFactory.useContextLoader = false;
>- return true;
>- }
>- return false;
>+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
>+ if (cl != null)
>+ if (cl.getResource(path) != null)
>+ return true;
>+ // don't assume the context class loader is tied
>+ // into the class loader that loaded this class.
>+ cl = getClass().getClassLoader();
>+ // Javadoc indicates implementations can use
>+ // null as a return from Class.getClassLoader()
>+ // to indicate the system/bootstrap classloader.
>+ if (cl != null)
>+ {
>+ return (cl.getResource(path) != null);
>+ }
>+ else
>+ {
>+ return ClassLoader.getSystemResource(path) != null;
>+ }
> } // end of exists
>
> /**
>@@ -106,19 +105,29 @@
> */
> public InputStream getInputStream( ) throws FileNotFoundException
> {
>- InputStream is = null;
>- if( storageFactory.useContextLoader)
>- {
>- ClassLoader cl = Thread.currentThread().getContextClassLoader();
>- is = cl.getResourceAsStream( path);
>- if( is != null)
>- return is;
>- }
>- is = getClass().getResourceAsStream( path);
>- if( is != null && storageFactory.useContextLoader)
>- storageFactory.useContextLoader = false;
>- if( is == null)
>- throw new FileNotFoundException( "Not in class path: " + path);
>- return is;
>+ //System.out.println("HERE FOR " + toString());
>+ InputStream is = null;
>+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
>+ if (cl != null)
>+ is = cl.getResourceAsStream(path);
>+
>+ // don't assume the context class loader is tied
>+ // into the class loader that loaded this class.
>+ if (is == null)
>+ {
>+ cl = getClass().getClassLoader();
>+ // Javadoc indicates implementations can use
>+ // null as a return from Class.getClassLoader()
>+ // to indicate the system/bootstrap classloader.
>+ if (cl != null)
>+ is = cl.getResourceAsStream(path);
>+ else
>+ is = ClassLoader.getSystemResourceAsStream(path);
>+ }
>+
>+ if (is == null)
>+ throw new FileNotFoundException(toString());
>+ return is;
>+
> } // end of getInputStream
> }
>
>Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPStorageFactory.java?rev=240111&r1=240110&r2=240111&view=diff
>==============================================================================
>--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPStorageFactory.java (original)
>+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPStorageFactory.java Thu Aug 25 11:02:57 2005
>@@ -38,45 +38,7 @@
> */
>
> public class CPStorageFactory extends BaseStorageFactory
>-{
>- boolean useContextLoader = true;
>-
>- /**
>- * Classes implementing the StorageFactory interface must have a null
>- * constructor. This method is called when the database is booted up to
>- * initialize the class. It should perform all actions necessary to start the
>- * basic storage, such as creating a temporary file directory.
>- *
>- * The init method will be called once, before any other method is called, and will not
>- * be called again.
>- *
>- * @param home The name of the directory containing the database. It comes from the system.home system property.
>- * It may be null. A storage factory may decide to ignore this parameter. (For instance the classpath
>- * storage factory ignores it.
>- * @param databaseName The name of the database (directory). All relative pathnames are relative to this directory.
>- * If null then the storage factory will only be used to deal with the directory containing
>- * the databases.
>- * @param create If true then the database is being created.
>- * @param tempDirName The name of the temporary file directory set in properties. If null then a default
>- * directory should be used. Each database should get a separate temporary file
>- * directory within this one to avoid collisions.
>- * @param uniqueName A unique name that can be used to create the temporary file directory for this database.
>- *
>- * @exception IOException on an error (unexpected).
>- */
>- public void init( String home, String databaseName, String tempDirName, String uniqueName)
>- throws IOException
>- {
>- // Prefix the database name with a '/' so that the class loader will not use a Cloudscape
>- // internal package.
>- if( databaseName == null
>- || ( databaseName.length() > 0
>- && (databaseName.charAt( 0) == '/' || databaseName.charAt( 0) == getSeparator())))
>- super.init( home, databaseName, tempDirName, uniqueName);
>- else
>- super.init( home, "/" + databaseName, tempDirName, uniqueName);
>- }
>-
>+{
> /**
> * Construct a persistent StorageFile from a path name.
> *
>
>Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out?rev=240111&view=auto
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out (added)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out Thu Aug 25 11:02:57 2005
>@@ -0,0 +1,129 @@
>+ij> --
>+-- This tests database in a jar
>+-- and a jar in a database in a jar!
>+--
>+;
>+ij> connect 'jdbc:derby:db1;create=true' AS DB1;
>+ij(DB1)> create table t ( i int not null primary key, c char(20));
>+0 rows inserted/updated/deleted
>+ij(DB1)> insert into t values (1, 'hello');
>+1 row inserted/updated/deleted
>+ij(DB1)> insert into t values (2, 'goodbye');
>+1 row inserted/updated/deleted
>+ij(DB1)> create function APP.D2ME(VAL INT) RETURNS INT
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'InAJar.doubleMe';
>+0 rows inserted/updated/deleted
>+ij(DB1)> -- should not be found;
>+values APP.D2ME(2);
>+ERROR 42X51: The class 'InAJar' does not exist or is inaccessible. This can happen if the class is not public.
>+ERROR XJ001: Java exception: 'InAJar: java.lang.ClassNotFoundException'.
>+ij(DB1)> CALL sqlj.install_jar('file:extin/dbjar.jar', 'APP.DMJ', 0);
>+0 rows inserted/updated/deleted
>+ij(DB1)> call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath', 'APP.DMJ');
>+0 rows inserted/updated/deleted
>+ij(DB1)> -- check the class loading is working;
>+values APP.D2ME(2);
>+1
>+-----------
>+4
>+ij(DB1)> -- shutdown to allow jarring of database
>+disconnect;
>+ij> connect 'jdbc:derby:db1;shutdown=true';
>+ERROR 08006: Database 'db1' shutdown.
>+ij> -- jar up the database
>+set connection CONNECTION0;
>+ij> create procedure CREATEARCHIVE(jarName VARCHAR(20), path VARCHAR(20), dbName VARCHAR(20))
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.createArchive';
>+0 rows inserted/updated/deleted
>+ij> call CREATEARCHIVE('ina.jar', 'db1', 'db7');
>+0 rows inserted/updated/deleted
>+ij> -- reconnect back to db1 to modify table to ensure we are not seeing db1 unjarred
>+connect 'jdbc:derby:db1' AS DB1;
>+ij(DB1)> insert into t values (4, 'directory version');
>+1 row inserted/updated/deleted
>+ij(DB1)> disconnect;
>+ij> connect 'jdbc:derby:jar:(ina.jar)db7' AS DB7;
>+ij(DB7)> select * from t;
>+I |C
>+--------------------------------
>+1 |hello
>+2 |goodbye
>+ij(DB7)> insert into t values(3, 'is read only');
>+ERROR 25502: An SQL data change is not permitted for a read-only connection, user or database.
>+ij(DB7)> values APP.D2ME(2);
>+1
>+-----------
>+4
>+ij(DB7)> autocommit off;
>+ij(DB7)> select * from t WITH RR;
>+I |C
>+--------------------------------
>+1 |hello
>+2 |goodbye
>+ij(DB7)> select TYPE, MODE, TABLENAME from new org.apache.derby.diag.LockTable() AS L ORDER BY 1,2,3;
>+TYPE |MODE|TABLENAME
>+-------------------------------------------------------------------------------------------------------------------------------------------
>+TABLE|S |T
>+ij(DB7)> disconnect;
>+ij> -- connect to database in jar file via classpath
>+-- should fail as it is not on the classpath yet.
>+connect 'jdbc:derby:classpath:db7' AS DB7CLF;
>+ERROR XJ004: Database 'classpath:db7' not found.
>+ij> -- create a class loader for this current thread
>+set connection CONNECTION0;
>+ij> create procedure setDBContextClassLoader(JARNAME VARCHAR(20))
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.setDBContextClassLoader';
>+0 rows inserted/updated/deleted
>+ij> call setDBContextClassLoader('ina.jar');
>+0 rows inserted/updated/deleted
>+ij> connect 'jdbc:derby:classpath:db7' AS DB7CL;
>+ij(DB7CL)> select * from t;
>+I |C
>+--------------------------------
>+1 |hello
>+2 |goodbye
>+ij(DB7CL)> insert into t values(3, 'is read only');
>+ERROR 25502: An SQL data change is not permitted for a read-only connection, user or database.
>+ij(DB7CL)> values APP.D2ME(2);
>+1
>+-----------
>+4
>+ij(DB7CL)> autocommit off;
>+ij(DB7CL)> select * from t WITH RR;
>+I |C
>+--------------------------------
>+1 |hello
>+2 |goodbye
>+ij(DB7CL)> select TYPE, MODE, TABLENAME from new org.apache.derby.diag.LockTable() AS L ORDER BY 1,2,3;
>+TYPE |MODE|TABLENAME
>+-------------------------------------------------------------------------------------------------------------------------------------------
>+TABLE|S |T
>+ij(DB7CL)> disconnect;
>+ij> -- Beetle 5171. Don't crash if the contextClassLoader is null
>+set connection CONNECTION0;
>+ij> create procedure setNullContextClassLoader()
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.setNullContextClassLoader';
>+0 rows inserted/updated/deleted
>+ij> call setNullContextClassLoader();
>+0 rows inserted/updated/deleted
>+ij> create table t2 (i int);
>+0 rows inserted/updated/deleted
>+ij> insert into t2 values(1);
>+1 row inserted/updated/deleted
>+ij> insert into t2 values(2);
>+1 row inserted/updated/deleted
>+ij> select count(*) from t2;
>+1
>+-----------
>+2
>+ij> drop table t2;
>+0 rows inserted/updated/deleted
>+ij>
>
>Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out
>------------------------------------------------------------------------------
> svn:eol-style = native
>
>Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?rev=240111&r1=240110&r2=240111&view=diff
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall (original)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall Thu Aug 25 11:02:57 2005
>@@ -39,6 +39,7 @@
> lang/datetime.sql
> lang/db2Compatibility.sql
> lang/dbManagerLimits.java
>+lang/dbjar.sql
> lang/dcl.sql
> lang/ddlTableLockMode.sql
> lang/deadlockMode.java
>
>Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant?rev=240111&r1=240110&r2=240111&view=diff
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant (original)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant Thu Aug 25 11:02:57 2005
>@@ -49,6 +49,9 @@
> datetime.sql
> db2Compatibility.sql
> dbManagerLimits_app.properties
>+dbjar.jar
>+dbjar.sql
>+dbjar_app.properties
> dcl.sql
> dcl_app.properties
> dcl_emc1.jar
>
>Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar?rev=240111&view=auto
>==============================================================================
>Binary file - no diff available.
>
>Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar
>------------------------------------------------------------------------------
> svn:mime-type = application/octet-stream
>
>Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql?rev=240111&view=auto
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql (added)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql Thu Aug 25 11:02:57 2005
>@@ -0,0 +1,90 @@
>+--
>+-- This tests database in a jar
>+-- and a jar in a database in a jar!
>+--
>+;
>+
>+connect 'jdbc:derby:db1;create=true' AS DB1;
>+create table t ( i int not null primary key, c char(20));
>+insert into t values (1, 'hello');
>+insert into t values (2, 'goodbye');
>+
>+create function APP.D2ME(VAL INT) RETURNS INT
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'InAJar.doubleMe';
>+
>+-- should not be found;
>+values APP.D2ME(2);
>+
>+CALL sqlj.install_jar('file:extin/dbjar.jar', 'APP.DMJ', 0);
>+call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath', 'APP.DMJ');
>+
>+-- check the class loading is working;
>+values APP.D2ME(2);
>+
>+-- shutdown to allow jarring of database
>+disconnect;
>+connect 'jdbc:derby:db1;shutdown=true';
>+
>+
>+-- jar up the database
>+set connection CONNECTION0;
>+create procedure CREATEARCHIVE(jarName VARCHAR(20), path VARCHAR(20), dbName VARCHAR(20))
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.createArchive';
>+
>+call CREATEARCHIVE('ina.jar', 'db1', 'db7');
>+
>+-- reconnect back to db1 to modify table to ensure we are not seeing db1 unjarred
>+connect 'jdbc:derby:db1' AS DB1;
>+insert into t values (4, 'directory version');
>+disconnect;
>+
>+connect 'jdbc:derby:jar:(ina.jar)db7' AS DB7;
>+select * from t;
>+insert into t values(3, 'is read only');
>+values APP.D2ME(2);
>+
>+autocommit off;
>+select * from t WITH RR;
>+select TYPE, MODE, TABLENAME from new org.apache.derby.diag.LockTable() AS L ORDER BY 1,2,3;
>+disconnect;
>+
>+-- connect to database in jar file via classpath
>+-- should fail as it is not on the classpath yet.
>+connect 'jdbc:derby:classpath:db7' AS DB7CLF;
>+
>+-- create a class loader for this current thread
>+set connection CONNECTION0;
>+create procedure setDBContextClassLoader(JARNAME VARCHAR(20))
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.setDBContextClassLoader';
>+
>+call setDBContextClassLoader('ina.jar');
>+
>+connect 'jdbc:derby:classpath:db7' AS DB7CL;
>+select * from t;
>+insert into t values(3, 'is read only');
>+values APP.D2ME(2);
>+autocommit off;
>+select * from t WITH RR;
>+select TYPE, MODE, TABLENAME from new org.apache.derby.diag.LockTable() AS L ORDER BY 1,2,3;
>+disconnect;
>+
>+-- Beetle 5171. Don't crash if the contextClassLoader is null
>+set connection CONNECTION0;
>+create procedure setNullContextClassLoader()
>+LANGUAGE JAVA PARAMETER STYLE JAVA
>+NO SQL
>+EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.setNullContextClassLoader';
>+
>+call setNullContextClassLoader();
>+
>+create table t2 (i int);
>+insert into t2 values(1);
>+insert into t2 values(2);
>+select count(*) from t2;
>+drop table t2;
>
>Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql
>------------------------------------------------------------------------------
> svn:eol-style = native
>
>Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java?rev=240111&view=auto
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java (added)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java Thu Aug 25 11:02:57 2005
>@@ -0,0 +1,135 @@
>+/*
>+
>+Derby - Class org.apache.derbyTesting.functionTests.tests.lang.cursor
>+
>+Copyright 1999, 2005 The Apache Software Foundation or its licensors, as applicable.
>+
>+Licensed under the Apache License, Version 2.0 (the "License");
>+you may not use this file except in compliance with the License.
>+You may obtain a copy of the License at
>+
>+ http://www.apache.org/licenses/LICENSE-2.0
>+
>+Unless required by applicable law or agreed to in writing, software
>+distributed under the License is distributed on an "AS IS" BASIS,
>+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>+See the License for the specific language governing permissions and
>+limitations under the License.
>+
>+*/
>+
>+package org.apache.derbyTesting.functionTests.tests.lang;
>+
>+import java.io.BufferedInputStream;
>+import java.io.File;
>+import java.io.FileInputStream;
>+import java.io.FileOutputStream;
>+import java.io.IOException;
>+import java.net.MalformedURLException;
>+import java.net.URL;
>+import java.net.URLClassLoader;
>+import java.util.zip.ZipEntry;
>+import java.util.zip.ZipOutputStream;
>+
>+/**
>+ Simple program to archive a database up in a jar file
>+ within the test harness.
>+*/
>+
>+public class dbjarUtil
>+{
>+ /**
>+ jarname - jarname to use
>+ path - path to database
>+ dbname - database name in archive
>+ */
>+ public static void createArchive(String jarName, String path, String dbName) throws Exception {
>+
>+ String root = System.getProperty("derby.system.home", System.getProperty("user.dir"));
>+
>+ // get list of files
>+ File top = new File(root, path);
>+
>+ if (!top.isDirectory())
>+ throw new Exception(top.toString() + " is not a directory");
>+
>+ // jar file paths in the JDB CURL are relative to the root
>+ // derby.system.home or user.dir, so need to create the jar there.
>+ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(root, jarName)));
>+
>+ addEntries(zos, top, dbName, top.getPath().length());
>+
>+ zos.close();
>+ }
>+
>+
>+ static void addEntries(ZipOutputStream zos, File dir, String dbName, int old) throws Exception {
>+
>+ String[] list = dir.list();
>+
>+ for (int i = 0; i < list.length; i++) {
>+
>+ File f = new File(dir, list[i]);
>+ if (f.isDirectory()) {
>+ addEntries(zos, f, dbName, old);
>+ } else {
>+ addFile(zos, f, dbName, old);
>+ }
>+
>+ }
>+ }
>+
>+
>+
>+
>+ static void addFile(
>+ ZipOutputStream zos,
>+ File f, String dbName, int old) throws IOException
>+ {
>+
>+ String s = f.getPath().replace(File.separatorChar, '/');
>+
>+ s = s.substring(old);
>+
>+ s = dbName.concat(s);
>+
>+ // jar has forward slashes!
>+ ZipEntry ze= new ZipEntry(s);
>+ ze.setTime(f.lastModified());
>+
>+ zos.putNextEntry(ze);
>+
>+ byte[] byte8= new byte[1024];
>+ BufferedInputStream bufferedInputStream10= new BufferedInputStream((new FileInputStream(f)));
>+ while (true)
>+ {
>+ int int9= bufferedInputStream10.read(byte8, 0, byte8.length);
>+ if (int9 == -1)
>+ {
>+ break;
>+ }
>+ zos.write(byte8, 0, int9);
>+ }
>+
>+ bufferedInputStream10.close();
>+ zos.closeEntry();
>+ }
>+
>+ public static void setDBContextClassLoader(String jarName) throws MalformedURLException
>+ {
>+ String root = System.getProperty("derby.system.home", System.getProperty("user.dir"));
>+
>+ File jar = new File(root, jarName);
>+
>+ URLClassLoader cl = new URLClassLoader(new URL[] {jar.toURL()});
>+ java.lang.Thread.currentThread().setContextClassLoader(cl);
>+
>+ }
>+
>+ public static void setNullContextClassLoader()
>+ {
>+ java.lang.Thread.currentThread().setContextClassLoader(null);
>+ }
>+
>+}
>+
>
>Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java
>------------------------------------------------------------------------------
> svn:eol-style = native
>
>Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties
>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties?rev=240111&view=auto
>==============================================================================
>--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties (added)
>+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties Thu Aug 25 11:02:57 2005
>@@ -0,0 +1,3 @@
>+supportfiles=tests/lang/dbjar.jar
>+usedefaults=true
>+useextdirs=true
>
>Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties
>------------------------------------------------------------------------------
> svn:eol-style = native
>
>
>
>
>
>
Re: svn commit: r240111 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/
testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Posted by Daniel John Debrunner <dj...@debrunners.com>.
Satheesh Bandaram wrote:
> Wonderful. One more happy customer, if they still need the fix! I will
> file a bug in Jira.
Regardless of is someone needs a fix, it is still a bug and should be
entered.
Dan.
Re: svn commit: r240111 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/
testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Posted by Daniel John Debrunner <dj...@debrunners.com>.
Satheesh Bandaram wrote:
> Dan, good catch. There was a post about 2 weeks back that said soft
> upgrade doesn't work for read-only databases (including database in a
> JAR) It raises the error "ERROR 40XD1: Container was opened in read-only
> mode." I reproduced the problem and analysed it a little. It seems
> problem shows up in DD_Version.upgradeIfNeeded(). We seem to set a
> property value and since the container is read-only, it throws the
> error. If I avoid DD_Version.applySafeChanges(), since no changes can be
> applied in read-only mode, I was able to boot the database.
>
> The question is do you see any problems in supporting soft-upgrade for
> read-only databases?
No problems, I thought I had addressed this, at least in Cloudscape 5.1
it was. I guess somehow the change was lost, if you enter a bug I can
look at it.
Dan.