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 2005/01/10 19:51:11 UTC

svn commit: r124819 - in incubator/derby/code/trunk/java: engine engine/org/apache/derby/iapi/services/loader engine/org/apache/derby/impl engine/org/apache/derby/impl/io engine/org/apache/derby/impl/services engine/org/apache/derby/impl/sql/compile testing/org/apache/derbyTesting/functionTests/master testing/org/apache/derbyTesting/functionTests/tests/lang testing/org/apache/derbyTesting/functionTests/util

Author: djd
Date: Mon Jan 10 10:51:10 2005
New Revision: 124819

URL: http://svn.apache.org/viewcvs?view=rev&rev=124819
Log:
Initial step for Derby-89 - support of explicit Java method signature in
function and procedure defintions.

Contributed by Jeremy Boynes.


Modified:
   incubator/derby/code/trunk/java/engine/build.xml
   incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
   incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
   incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
   incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java

Modified: incubator/derby/code/trunk/java/engine/build.xml
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/build.xml?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/build.xml&r1=124818&p2=incubator/derby/code/trunk/java/engine/build.xml&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/build.xml	(original)
+++ incubator/derby/code/trunk/java/engine/build.xml	Mon Jan 10 10:51:10 2005
@@ -34,16 +34,12 @@
 
 <!--             ============ Begin Targets ==============                -->
  
-  <target name="engine"
+  <target name="engine" depends="engine_169"
           description="Build Derby engine">
 
-    <ant dir="${derby.engine.dir}/iapi/reference"/>
-    <ant dir="${derby.engine.dir}/authentication"/>
-    <ant dir="${derby.engine.dir}/io"/>
     <ant dir="${derby.engine.dir}/iapi"/>
-    <ant dir="${derby.engine.dir}/jdbc"/>
-    <ant dir="${derby.engine.dir}/database"/>
     <ant dir="${derby.engine.dir}/impl"/>
+    <ant dir="${derby.engine.dir}/jdbc"/>
     <ant dir="${derby.engine.dir}/osgi"/>
     <ant dir="${derby.engine.dir}/catalog"/>
     <ant dir="${derby.engine.dir}/diag"/>
@@ -55,6 +51,16 @@
       </fileset>
     </copy>
   </target>
+  
+  <target name="engine_169"
+          description="Build base JSR169 elements of Derby engine">
+    <ant dir="${derby.engine.dir}/iapi/reference"/>
+    <ant dir="${derby.engine.dir}/authentication"/>
+    <ant dir="${derby.engine.dir}/io"/>
+     <ant dir="${derby.engine.dir}/iapi" target="compile_iapi_error_jsr169"/>
+     <ant dir="${derby.engine.dir}/database"/>
+     <ant dir="${derby.engine.dir}/impl" target="compile_impl_169"/>
+ </target>
 
 <!--             ============= End Targets ==============                -->
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java	Mon Jan 10 10:51:10 2005
@@ -27,6 +27,11 @@
 import org.apache.derby.iapi.reference.SQLState;
 
 import java.lang.reflect.*;
+import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.NoSuchElementException;
+import java.util.Collections;
 
 /**
 	Methods to find out relationships between classes and methods within a class.
@@ -307,9 +312,45 @@
 			}
 		}
 
-		return resolveMethod(receiverClass, methodName, paramClasses, 
+		return resolveMethod(receiverClass, methodName, paramClasses,
 						primParamClasses, isParam, staticMethod, repeatLastParameter, methodList);
 	}
+
+    public Method findPublicMethod(String className, String signature, boolean isStatic) throws ClassNotFoundException {
+        Class javaClass = getClass(className);
+        StringTokenizer tokenizer = new StringTokenizer(signature, "(,)", true);
+        try {
+            String methodName = tokenizer.nextToken();
+            if (!tokenizer.nextToken().equals("(")) {
+                return null;
+            }
+            List paramTypes;
+            String token = tokenizer.nextToken();
+            if (")".equals(token)) {
+                paramTypes = Collections.EMPTY_LIST;
+            } else {
+                paramTypes = new ArrayList();
+                paramTypes.add(getClass(token));
+                while ((token = tokenizer.nextToken()).equals(",")) {
+                    token = tokenizer.nextToken();
+                    paramTypes.add(getClass(token));
+                }
+            }
+
+            Method method;
+            try {
+                method = javaClass.getMethod(methodName, (Class[])paramTypes.toArray(new Class[paramTypes.size()]));
+                if (isStatic != Modifier.isStatic(method.getModifiers())) {
+                    return null;
+                }
+            } catch (NoSuchMethodException e) {
+                return null;
+            }
+            return method;
+        } catch (NoSuchElementException e) {
+            return null;
+        }
+    }
 
 	/**
 	 * Find a public field  for a class.

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml	Mon Jan 10 10:51:10 2005
@@ -19,15 +19,18 @@
 <!-- Targets -->
   <target name="iapi" depends="compile"/>
 
-  <target name="compile">
+  <target name="compile" depends="compile_impl_169">
     <ant dir="${derby.engine.dir}/impl/services"/>
     <ant dir="${derby.engine.dir}/impl/io"/>
     <ant dir="${derby.engine.dir}/impl/store"/>
-    <ant dir="${derby.engine.dir}/impl/sql"/>
     <ant dir="${derby.engine.dir}/impl/db"/>
     <ant dir="${derby.engine.dir}/impl/jdbc"/>
     <ant dir="${derby.engine.dir}/impl/load"/>
   </target>
-
+  
+  <target name="compile_impl_169">
+    <ant dir="${derby.engine.dir}/impl/services" target="compile_impl_services_169"/>
+    <ant dir="${derby.engine.dir}/impl/io" target="compile_impl_io_169"/>
+    <ant dir="${derby.engine.dir}/impl/sql"/>
+  </target>
 </project>
-

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/io/build.xml	Mon Jan 10 10:51:10 2005
@@ -18,7 +18,7 @@
 
 <!-- Targets -->
 
-  <target name="compile_impl_io">
+  <target name="compile_impl_io_169">
     <javac
       bootclasspath="${empty}"
       nowarn="on"
@@ -38,7 +38,9 @@
       <exclude name="${derby.dir}/impl/io/DirRandomAccessFile4.java"/>
       <exclude name="${derby.dir}/impl/io/DirStorageFactory4.java"/>
     </javac>
-    <javac
+  </target>
+  <target name="compile_impl_io" depends="compile_impl_io_169">
+      <javac
       bootclasspath="${empty}"
       nowarn="on"
       debug="${debug}"

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml	Mon Jan 10 10:51:10 2005
@@ -18,7 +18,7 @@
 
 <!-- Targets -->
 
-  <target name="compile_impl_services">
+  <target name="compile_impl_services_169">
     <javac
       bootclasspath="${empty}"
       nowarn="on"
@@ -36,6 +36,9 @@
       <include name="${derby.dir}/impl/services/**"/>
       <exclude name="${derby.dir}/impl/services/jce/**"/>
     </javac>
+ </target>
+ 
+ <target name="compile_impl_services" depends="compile_impl_services_169">
     <javac
       bootclasspath="${empty}"
       nowarn="on"

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java	Mon Jan 10 10:51:10 2005
@@ -677,53 +677,60 @@
 
 		boolean hasDynamicResultSets = (routineInfo != null) && (count != 0) && (count != methodParms.length);
 
-		/*
-		** Find the matching method that is public.
-		*/
-		try
-		{
-			/* First try with built-in types and mappings */
-			method = classInspector.findPublicMethod(javaClassName,
-												methodName,
-												parmTypeNames,
-												null,
-												isParam,
-												staticMethod,
-												hasDynamicResultSets);
+        /*
+        ** Find the matching method that is public.
+        */
+        try
+        {
+            // support Java signatures by checking if the method name contains a '('
+            if (methodName.indexOf('(') != -1) {
+                method = classInspector.findPublicMethod(javaClassName, methodName, staticMethod);
+                methodName = method.getName();
+            }
+            else
+            {
+                /* First try with built-in types and mappings */
+                method = classInspector.findPublicMethod(javaClassName,
+                                                    methodName,
+                                                    parmTypeNames,
+                                                    null,
+                                                    isParam,
+                                                    staticMethod,
+                                                    hasDynamicResultSets);
 
 
-			// DB2 LUW does not support Java object types for SMALLINT, INTEGER, BIGINT, REAL, DOUBLE
-			// and these are the only types that can map to a primitive or an object type according
-			// to SQL part 13. So we never have a second chance match.
-			if (routineInfo == null) {
+                // DB2 LUW does not support Java object types for SMALLINT, INTEGER, BIGINT, REAL, DOUBLE
+                // and these are the only types that can map to a primitive or an object type according
+                // to SQL part 13. So we never have a second chance match.
+                if (routineInfo == null) {
 
-				/* If no match, then retry with combinations of object and 
-				 * primitive types.
-				 */
-				if (method == null)
-				{
-					primParmTypeNames = getPrimitiveSignature(false);
-
-					method = classInspector.findPublicMethod(javaClassName,
-												methodName,
-												parmTypeNames,
-												primParmTypeNames,
-												isParam,
-												staticMethod,
-												hasDynamicResultSets);
-				}
-			}
-		}
-		catch (ClassNotFoundException e)
-		{
-			/*
-			** If one of the classes couldn't be found, just act like the
-			** method couldn't be found.  The error lists all the class names,
-			** which should give the user enough info to diagnose the problem.
-			*/
-			method = null;
-		}
+                    /* If no match, then retry with combinations of object and
+                     * primitive types.
+                     */
+                    if (method == null)
+                    {
+                        primParmTypeNames = getPrimitiveSignature(false);
 
+                        method = classInspector.findPublicMethod(javaClassName,
+                                                    methodName,
+                                                    parmTypeNames,
+                                                    primParmTypeNames,
+                                                    isParam,
+                                                    staticMethod,
+                                                    hasDynamicResultSets);
+                    }
+                }
+            }
+        }
+        catch (ClassNotFoundException e)
+        {
+            /*
+            ** If one of the classes couldn't be found, just act like the
+            ** method couldn't be found.  The error lists all the class names,
+            ** which should give the user enough info to diagnose the problem.
+            */
+            method = null;
+        }
 		/* Throw exception if no matching signature found */
 		if (method == null)
 		{

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java&r1=124818&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java	Mon Jan 10 10:51:10 2005
@@ -603,24 +603,20 @@
 
 		nodeType = C_NodeTypes.CREATE_ALIAS_NODE;
 
-		{
-			/*
-			** Parse the class name, splitting out the class name from
-			** the method name.
-			*/
-			int lastPeriod = fullStaticMethodName.lastIndexOf(".");
-			if ((lastPeriod == -1) ||
-				fullStaticMethodName.length() == lastPeriod + 1)
-			{
-				throw StandardException.newException(SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME, 
-														fullStaticMethodName);
-			}
-			else
-			{
-				methodName = fullStaticMethodName.substring(lastPeriod + 1);
-				javaClassName = fullStaticMethodName.substring(0, lastPeriod);
-			}
-		}
+        int lastPeriod;
+        int paren = fullStaticMethodName.indexOf('(');
+        if (paren == -1) {
+            // not a Java signature - split based on last period
+            lastPeriod = fullStaticMethodName.lastIndexOf('.');
+        } else {
+            // a Java signature - split on last period before the '('
+            lastPeriod = fullStaticMethodName.substring(0, paren).lastIndexOf('.');
+        }
+        if (lastPeriod == -1 || lastPeriod == fullStaticMethodName.length()-1) {
+            throw StandardException.newException(SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME, fullStaticMethodName);
+        }
+        javaClassName = fullStaticMethodName.substring(0, lastPeriod);
+        methodName = fullStaticMethodName.substring(lastPeriod + 1);
 
 		return getNode(
 			nodeType,

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out&r1=124818&p2=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out	(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out	Mon Jan 10 10:51:10 2005
@@ -83,6 +83,10 @@
 EXPECTED SQL Exception: (42X73) Method resolution for signature org.apache.derbyTesting.functionTests.util.ProcedureTest.ambigious1(int, java.lang.String, [Ljava.sql.ResultSet;) was ambiguous. (No single maximally specific method.)
 call AMBIGIOUS02(?, ?)
 EXPECTED SQL Exception: (42X50) No method was found to be able to match method call org.apache.derbyTesting.functionTests.util.ProcedureTest.ambigious2(int, int, java.sql.ResultSet[]), even tried all combinations of object and primitive types and any possible type conversion for any parameters the method call may have.  It may be that the method exists, but it is not public and/or static, or that the parameter types are not method invocation convertible.
+ambigious2(int,Integer) called
+UPDATE COUNT 0
+ambigious2(Integer,int) called
+UPDATE COUNT 0
 zeroArgProcedures
 zeroArg() called
 UPDATE COUNT 0

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java&r1=124818&p2=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java	(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java	Mon Jan 10 10:51:10 2005
@@ -240,7 +240,15 @@
 		s.execute("create procedure ambigious02(p1 INTEGER, p2 INTEGER) dynamic result sets 1 language java parameter style java external name 'org.apache.derbyTesting.functionTests.util.ProcedureTest.ambigious2'");
 		callExceptionExpected(conn, "call AMBIGIOUS02(?, ?)");
 		s.execute("drop procedure AMBIGIOUS02");
-		s.close();
+
+        // verify we can find it with a Java signature
+        s.execute("create procedure ambigious03(p1 INTEGER, p2 INTEGER) dynamic result sets 1 language java parameter style java external name 'org.apache.derbyTesting.functionTests.util.ProcedureTest.ambigious2(int,java.lang.Integer)'");
+        executeProcedure(s, "{call ambigious03(1, NULL)}");
+        s.execute("drop procedure AMBIGIOUS03");
+        s.execute("create procedure ambigious04(p1 INTEGER, p2 INTEGER) dynamic result sets 1 language java parameter style java external name 'org.apache.derbyTesting.functionTests.util.ProcedureTest.ambigious2(java.lang.Integer,int)'");
+        executeProcedure(s, "{call ambigious04(NULL, 1)}");
+        s.execute("drop procedure AMBIGIOUS04");
+        s.close();
 	}
 
 	public static void zeroArgProcedures(Connection conn) throws SQLException {

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java?view=diff&rev=124819&p1=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java&r1=124818&p2=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java&r2=124819
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java	(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java	Mon Jan 10 10:51:10 2005
@@ -413,8 +413,12 @@
 	public static void ambigious1(int p1, String p2, ResultSet[] data1) {}
 
 
-	public static void ambigious2(int p1, Integer p2) {};
-	public static void ambigious2(Integer p1, int p2) {};
+	public static void ambigious2(int p1, Integer p2) {
+        System.out.println("ambigious2(int,Integer) called");
+    };
+	public static void ambigious2(Integer p1, int p2) {
+        System.out.println("ambigious2(Integer,int) called");
+    };
 
 	public static void missingDynamicParameter(int p1)  {}
 	public static void missingDynamicParameter(int p1, Object p2)  {}