db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r759360 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 27 Mar 2009 21:41:46 GMT
Author: rhillegas
Date: Fri Mar 27 21:41:46 2009
New Revision: 759360

URL: http://svn.apache.org/viewvc?rev=759360&view=rev
Log:
DERBY-4126: Find table functions even when they are in jar files in the database.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dummy_vti.jar
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.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/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=759360&r1=759359&r2=759360&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Fri Mar
27 21:41:46 2009
@@ -1632,12 +1632,11 @@
         throws StandardException
     {
         Constructor     constructor = null;
-        Class           vtiClass = null;
-        
-        try {
-            vtiClass = Class.forName( className );
+        Class           vtiClass = lookupClass( className );
+        Class           vtiCostingClass = lookupClass( VTICosting.class.getName() );
 
-            if ( !VTICosting.class.isAssignableFrom( vtiClass ) ) { return false; }
+        try {
+            if ( !vtiCostingClass.isAssignableFrom( vtiClass ) ) { return false; }
         }
         catch (Throwable t)
         {
@@ -1669,9 +1668,10 @@
     {
         if ( !isDerbyStyleTableFunction ) { return (version2) ? (VTICosting) ps : (VTICosting)
rs; }
         
+        String              className = methodCall.getJavaClassName();
+        Class               vtiClass = lookupClass( className );
+        
         try {
-            String              className = methodCall.getJavaClassName();
-            Class               vtiClass = Class.forName( className );
             Constructor         constructor = vtiClass.getConstructor( new Class[] {} );
             VTICosting          result = (VTICosting) constructor.newInstance( null );
 
@@ -1682,4 +1682,20 @@
             throw StandardException.unexpectedUserException( t );
         }
     }
+
+    /**
+     * Lookup the class that holds the VTI.
+     */
+    private Class lookupClass( String className )
+        throws StandardException
+    {
+        try {
+            return getClassFactory().getClassInspector().getClass( className );
+        }
+        catch (ClassNotFoundException t)
+        {
+            throw StandardException.unexpectedUserException( t );
+        }
+    }
+
 }

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=759360&r1=759359&r2=759360&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 Mar 27 21:41:46 2009
@@ -105,6 +105,7 @@
                 "testLoadJavaClassDirectly3",
                 "testLoadDerbyClassIndirectly",
                 "testIndirectLoading",
+                "testTableFunctionInJar",
             };
             
             for (int i = 0; i < orderedTests.length; i++)
@@ -138,6 +139,7 @@
                    "functionTests/tests/lang/dcl_ot2.jar",
                    "functionTests/tests/lang/dcl_ot3.jar",
                    "functionTests/tests/lang/dcl_id.jar",
+                   "functionTests/tests/lang/dummy_vti.jar",
                    });
            
            }
@@ -992,6 +994,90 @@
         
     }
 
+    /**
+     * Test that table functions can be invoked from inside jar files stored in
+     * the database.
+     */
+    public void testTableFunctionInJar() throws SQLException, MalformedURLException
+    {
+        
+        String jarName = "EMC.DUMMY_VTI";
+
+        installJar("dummy_vti.jar", jarName );
+
+        setDBClasspath( jarName );
+
+        Statement s = createStatement();
+
+        // register a scalar function
+        s.executeUpdate
+            (
+             "create function reciprocal( original double ) returns double\n" +
+             "language java\n" +
+             "parameter style java\n" +
+             "no sql\n" +
+             "external name 'DummyVTI.reciprocal'"
+             );
+
+        // register the table function
+        s.executeUpdate
+            (
+             "create function dummyVTI()\n" +
+             "returns table( tablename varchar( 128 ) )\n" +
+             "language java\n" +
+             "parameter style DERBY_JDBC_RESULT_SET\n" +
+             "reads sql data\n" +
+             "external name 'DummyVTI.dummyVTI'\n"
+             );
+
+        // register another table function in a class which doesn't exist
+        s.executeUpdate
+            (
+             "create function dummyVTI2()\n" +
+             "returns table( tablename varchar( 128 ) )\n" +
+             "language java\n" +
+             "parameter style DERBY_JDBC_RESULT_SET\n" +
+             "reads sql data\n" +
+             "external name 'DummyVTI2.dummyVTI'\n"
+             );
+
+        // invoke the scalar function
+        JDBC.assertFullResultSet(
+                s.executeQuery
+                (
+                 "values ( reciprocal( 2.0 ) )"
+                 ),
+                new String[][] {
+                    {"0.5"},
+                    });
+
+        
+        // invoke the table function
+        JDBC.assertFullResultSet(
+                s.executeQuery
+                (
+                 "select * from table( dummyVTI() ) s where tablename='SYSTABLES'"
+                 ),
+                new String[][] {
+                    {"SYSTABLES"},
+                    });
+
+        // verify that a missing class raises an exception
+        try {
+            s.executeQuery
+                (
+                 "select * from table( dummyVTI2() ) s where tablename='SYSTABLES'"
+                 );
+            fail( "Should have seen a ClassNotFoundException." );
+        } catch (SQLException e) {
+            assertSQLState("XJ001", e);
+        }
+        
+        setDBClasspath(null);
+        
+        s.close();
+    }
+    
             
   
     private void installJar(String resource, String jarName) throws SQLException, MalformedURLException

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dummy_vti.jar
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dummy_vti.jar?rev=759360&view=auto
==============================================================================
Binary file - no diff available.

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



Mime
View raw message