db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r759978 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 30 Mar 2009 14:15:47 GMT
Author: rhillegas
Date: Mon Mar 30 14:15:46 2009
New Revision: 759978

URL: http://svn.apache.org/viewvc?rev=759978&view=rev
Log:
DERBY-4126: Port 759360 from main to 10.4 branch.

Added:
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dummy_vti.jar
      - copied unchanged from r759360, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dummy_vti.jar
Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=759978&r1=759977&r2=759978&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
Mon Mar 30 14:15:46 2009
@@ -1638,12 +1638,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)
         {
@@ -1675,9 +1674,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 );
 
@@ -1716,4 +1716,19 @@
     }
 
    
+    /**
+     * 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/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java?rev=759978&r1=759977&r2=759978&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
Mon Mar 30 14:15: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



Mime
View raw message