You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/03/02 18:16:41 UTC

svn commit: r382450 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/services/reflect/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org/apache/derbyTesting/functionTests...

Author: djd
Date: Thu Mar  2 09:16:40 2006
New Revision: 382450

URL: http://svn.apache.org/viewcvs?rev=382450&view=rev
Log:
DEBRY-997 Fix ClassCastExceptions for queries containing aggregates when executing in application servers
or other class loading environments where the thread context loader provides another path to the derby engine code.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.out   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.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/AggregateClassLoading.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java?rev=382450&r1=382449&r2=382450&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java Thu Mar  2 09:16:40 2006
@@ -207,7 +207,24 @@
 
 	public final Class loadApplicationClass(String className)
 		throws ClassNotFoundException {
-
+        
+        if (className.startsWith("org.apache.derby.")) {
+            // Assume this is an engine class, if so
+            // try to load from this class loader,
+            // this ensures in strange class loader
+            // environments we do not get ClassCastExceptions
+            // when an engine class is loaded through a different
+            // class loader to the rest of the engine.
+            try {
+                return Class.forName(className);
+            } catch (ClassNotFoundException cnfe)
+            {
+                // fall through to the code below,
+                // could be client or tools class
+                // in a different loader.
+            }
+        }
+ 
 		Throwable loadError;
 		try {
 			try {

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.out?rev=382450&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.out (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.out Thu Mar  2 09:16:40 2006
@@ -0,0 +1,7 @@
+Test AggregateClassLoading starting
+19 rows inserted
+query = 2144
+query = -2
+query = 149
+query = 18
+query = 19

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/AggregateClassLoading.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=382450&r1=382449&r2=382450&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 Mar  2 09:16:40 2006
@@ -3,6 +3,7 @@
 jdbcapi/odbc_metadata.java
 junitTests/lang/LangSuite.java
 lang/AIjdbc.java
+lang/AggregateClassLoading.java
 lang/CharUTF8.java
 lang/DB2IsolationLevels.sql
 lang/LOB.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java?rev=382450&r1=382449&r2=382450&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java Thu Mar  2 09:16:40 2006
@@ -56,7 +56,6 @@
 		// Find the location of the code for the Derby connection.
 		// The rest of the engine will be at the same location!
 		URL derbyURL = conn.getClass().getProtectionDomain().getCodeSource().getLocation();
-		System.out.println("derbyURL" + derbyURL.toExternalForm());
 		
 		// Create a new loader that loads from the same location as the engine.
 		// Create it without a parent, otherwise the parent
@@ -82,6 +81,7 @@
 		testAggregate(s, "select COUNT(i) from t");
 		testAggregate(s, "select COUNT(*) from t");
 		
+        s.execute("drop table t");
 	    s.close();
 		conn.close();