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 rh...@apache.org on 2012/10/19 18:47:39 UTC
svn commit: r1400161 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/services/reflect/
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: rhillegas
Date: Fri Oct 19 16:47:39 2012
New Revision: 1400161
URL: http://svn.apache.org/viewvc?rev=1400161&view=rev
Log:
DERBY-672: Add support for loading user-defined aggregates from jars stored in the database.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/median_uda.jar (with props)
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java?rev=1400161&r1=1400160&r2=1400161&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java Fri Oct 19 16:47:39 2012
@@ -176,7 +176,9 @@ final class JarLoader extends SecureClas
// number of classes it has to check for.
if (className.startsWith("org.apache.derby.")
&& !className.startsWith("org.apache.derby.jdbc.")
- && !className.startsWith("org.apache.derby.vti."))
+ && !className.startsWith("org.apache.derby.vti.")
+ && !className.startsWith("org.apache.derby.agg.")
+ )
{
ClassNotFoundException cnfe = new ClassNotFoundException(className);
//cnfe.printStackTrace(System.out);
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java?rev=1400161&r1=1400160&r2=1400161&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java Fri Oct 19 16:47:39 2012
@@ -114,8 +114,8 @@ public class UserAggregateDefinition imp
ClassFactory classFactory = cc.getClassFactory();
TypeCompilerFactory tcf = cc.getTypeCompilerFactory();
- Class userAggregatorClass = classFactory.loadApplicationClass( _alias.getJavaClassName() );
Class derbyAggregatorInterface = classFactory.loadApplicationClass( "org.apache.derby.agg.Aggregator" );
+ Class userAggregatorClass = classFactory.loadApplicationClass( _alias.getJavaClassName() );
Class[][] typeBounds = classFactory.getClassInspector().getTypeBounds
( derbyAggregatorInterface, userAggregatorClass );
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java?rev=1400161&r1=1400160&r2=1400161&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java Fri Oct 19 16:47:39 2012
@@ -108,6 +108,7 @@ public class DatabaseClassLoadingTest ex
"testLoadDerbyClassIndirectly",
"testIndirectLoading",
"testTableFunctionInJar",
+ "testUDAInJar",
"test_5352",
};
@@ -143,6 +144,7 @@ public class DatabaseClassLoadingTest ex
"functionTests/tests/lang/dcl_ot3.jar",
"functionTests/tests/lang/dcl_id.jar",
"functionTests/tests/lang/dummy_vti.jar",
+ "functionTests/tests/lang/median_uda.jar",
});
}
@@ -1089,6 +1091,83 @@ public class DatabaseClassLoadingTest ex
}
/**
+ * Test that user-defined aggregates can be invoked from inside jar files stored in
+ * the database.
+ */
+ public void testUDAInJar() throws SQLException, MalformedURLException
+ {
+ // skip this test if vm is pre Java 6. This is because the jar file was
+ // compiled by a modern compiler and the jar file won't load on
+ // old vms.
+ if ( JVMInfo.J2ME || (JVMInfo.JDK_ID < JVMInfo.J2SE_16 ) ) { return; }
+
+ String jarName = "EMC.MEDIAN_UDA";
+
+ installJar( "median_uda.jar", jarName );
+
+ setDBClasspath( jarName );
+
+ Statement s = createStatement();
+
+ // register the user-defined aggregate
+ s.executeUpdate
+ ( "create derby aggregate intMedian for int external name 'Median'\n" );
+
+ // register another user-defined aggregate in a class which doesn't exist
+ s.executeUpdate
+ (
+ "create derby aggregate missingAggregate for int external name 'MissingAggregate'\n"
+ );
+
+ // create a table with some values
+ s.execute( "create table intValues( a int, b int )" );
+ s.execute( "insert into intValues values ( 1, 1 ), ( 1, 10 ), ( 1, 100 ), ( 1, 1000 ), ( 2, 5 ), ( 2, 50 ), ( 2, 500 ), ( 2, 5000 )" );
+
+ // invoke the user-defined aggregate
+ JDBC.assertFullResultSet
+ (
+ s.executeQuery
+ (
+ "select intMedian( b ) from intValues"
+ ),
+ new String[][]
+ {
+ { "100" },
+ }
+ );
+ JDBC.assertFullResultSet
+ (
+ s.executeQuery
+ (
+ "select a, intMedian( b ) from intValues group by a"
+ ),
+ new String[][]
+ {
+ { "1", "100" },
+ { "2", "500" },
+ }
+ );
+
+ // verify that a missing class raises an exception
+ try {
+ s.executeQuery
+ (
+ "select missingAggregate( b ) from intValues"
+ );
+ fail( "Should have seen a ClassNotFoundException." );
+ } catch (SQLException e) {
+ assertSQLState("XJ001", e);
+ }
+
+ // drop the useless aggregate
+ s.executeUpdate( "drop derby aggregate missingAggregate restrict" );
+
+ setDBClasspath(null);
+
+ s.close();
+ }
+
+ /**
* Test that restricted table functions can be invoked from inside jar files stored in
* the database.
*/
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/median_uda.jar
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/median_uda.jar?rev=1400161&view=auto
==============================================================================
Binary file - no diff available.
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/median_uda.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream