db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r290301 - in /db/derby/code/branches/10.1/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...
Date Mon, 19 Sep 2005 22:52:26 GMT
Author: djd
Date: Mon Sep 19 15:52:19 2005
New Revision: 290301

URL: http://svn.apache.org/viewcvs?rev=290301&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.

Merged from trunk revision 240111

Added:
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out
  (props changed)
      - copied unchanged from r240111, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar
  (props changed)
      - copied unchanged from r240111, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql
  (props changed)
      - copied unchanged from r240111, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java
  (props changed)
      - copied unchanged from r240111, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties
  (props changed)
      - copied unchanged from r240111, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties
Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPFile.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPFile.java?rev=290301&r1=290300&r2=290301&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPFile.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPFile.java Mon Sep 19
15:52:19 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/branches/10.1/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPStorageFactory.java?rev=290301&r1=290300&r2=290301&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/io/CPStorageFactory.java
Mon Sep 19 15:52:19 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.
      *

Propchange: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/dbjar.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?rev=290301&r1=290300&r2=290301&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
Mon Sep 19 15:52:19 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/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant?rev=290301&r1=290300&r2=290301&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
Mon Sep 19 15:52:19 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

Propchange: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Propchange: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjarUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dbjar_app.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message