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/02/01 16:21:18 UTC

svn commit: r374085 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java

Author: djd
Date: Wed Feb  1 07:21:15 2006
New Revision: 374085

URL: http://svn.apache.org/viewcvs?rev=374085&view=rev
Log:
Cleanup of CallStatementNode.java, since CALL statements are simple, taking
only parameters or constants as arguments, the node cna be simplified not
to create and handle lists for subqueries and aggregates that will always be empty.
Improved some of the comments in the file.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java?rev=374085&r1=374084&r2=374085&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java Wed Feb  1 07:21:15 2006
@@ -2,7 +2,7 @@
 
    Derby - Class org.apache.derby.impl.sql.compile.CallStatementNode
 
-   Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.
+   Copyright 1997, 2006 The Apache Software Foundation or its licensors, as applicable.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -55,37 +55,41 @@
 import java.util.Vector;
 
 /**
- * An CallStatementNode represents a CALL statement.  It is the top node of the
- * query tree for that statement. There are 2 flavors, class and object, of call
- * statements.  A class call statement is a static method call off of a class
- * expression (class classnameandpath), while an object call statement is a
- * method call off of an object expression.  The return value, if any,
- * from the underlying method call is ignored.
+ * An CallStatementNode represents a CALL <procedure> statement.
+ * It is the top node of the query tree for that statement.
+ * A procedure call is very simple.
+ * 
+ * CALL [<schema>.]<procedure>(<args>)
+ * 
+ * <args> are either constants or parameter markers.
+ * This implementation assumes that no subqueries or aggregates
+ * can be in the argument list.
+ * 
+ * A procedure is always represented by a MethodCallNode.
  *
  * @author Jerry Brenner
  */
 public class CallStatementNode extends DMLStatementNode
-{
-	private ValueNode	methodCall;
-
-	/* Need to track any subqueries under the methodCall */
-	private SubqueryList subqueries;
+{	
+	/**
+	 * The method call for the Java procedure. Guaranteed to be
+	 * a JavaToSQLValueNode wrapping a MethodCallNode by checks
+	 * in the parser.
+	 */
+	private JavaToSQLValueNode	methodCall;
 
-	/* JRESOLVE?? Need to track any aggregates under the methodCall */
-	private Vector aggregateVector;
 
 	/**
 	 * Initializer for a CallStatementNode.
 	 *
 	 * @param methodCall		The expression to "call"
-	 * @exception StandardException		Thrown on error
 	 */
 
 	public void init(Object methodCall)
 	{
 		super.init(null);
-		this.methodCall = (ValueNode) methodCall;
-		((JavaToSQLValueNode)methodCall).getJavaValueNode().markForCallStatement();
+		this.methodCall = (JavaToSQLValueNode) methodCall;
+		this.methodCall.getJavaValueNode().markForCallStatement();
 	}
 
 	/**
@@ -133,12 +137,6 @@
 				printLabel(depth, "methodCall: ");
 				methodCall.treePrint(depth + 1);
 			}
-
-			if (subqueries != null && subqueries.size() >= 1)
-			{
-				printLabel(depth, "subqueries: ");
-				subqueries.treePrint(depth + 1);
-			}
 		}
 	}
 
@@ -158,25 +156,18 @@
 
 	public QueryTreeNode bind() throws StandardException
 	{
-		DataDictionary				dd;
-
-		subqueries = (SubqueryList) getNodeFactory().getNode(
-											C_NodeTypes.SUBQUERY_LIST,
-											getContextManager());
-		aggregateVector = new Vector();
-
-		dd = getDataDictionary();
+		DataDictionary dd = getDataDictionary();
 
 		if (SanityManager.DEBUG)
 		SanityManager.ASSERT((dd != null), "Failed to get data dictionary");
 
-		methodCall = methodCall.bindExpression(
+		methodCall = (JavaToSQLValueNode) methodCall.bindExpression(
 							(FromList) getNodeFactory().getNode(
 								C_NodeTypes.FROM_LIST,
 								getNodeFactory().doJoinOrderOptimization(),
 								getContextManager()), 
-							subqueries,
-							aggregateVector);
+							null,
+							null);
 
 		return this;
 	}
@@ -200,35 +191,21 @@
 
 	public QueryTreeNode optimize() throws StandardException
 	{
-		DataDictionary				dd;
-
-		dd = getDataDictionary();
+		DataDictionary dd = getDataDictionary();
 
 		if (SanityManager.DEBUG)
 		SanityManager.ASSERT((dd != null), "Failed to get data dictionary");
 
 		/* Preprocess the method call tree */
-		methodCall = methodCall.preprocess(
+		methodCall = (JavaToSQLValueNode) methodCall.preprocess(
 								getCompilerContext().getNumTables(),
 								(FromList) getNodeFactory().getNode(
 									C_NodeTypes.FROM_LIST,
 									getNodeFactory().doJoinOrderOptimization(),
 									getContextManager()),
-								(SubqueryList) getNodeFactory().getNode(
-													C_NodeTypes.SUBQUERY_LIST,
-													getContextManager()),
-								(PredicateList) getNodeFactory().getNode(
-													C_NodeTypes.PREDICATE_LIST,
-													getContextManager()));
+								(SubqueryList) null,
+								(PredicateList) null);
 
-		/* Optimize any subqueries in the method call tree */
-		if (subqueries.size() >= 1)
-		{
-			subqueries.optimize(dd, 1.0);
-			subqueries.modifyAccessPaths();
-		}
-
-		// JRESOLVE: no need to optimize aggregates, right?
 		return this;
 	}
 
@@ -261,10 +238,7 @@
 		 *     <methodCall.generate(acb)>;
 		 * and adds it to userExprFun
 		 */
-		if (SanityManager.DEBUG)
-		SanityManager.ASSERT(methodCall instanceof JavaToSQLValueNode,
-					"methodCall is expected to be instanceof JavaToSQLValueNode");
-		methodCallBody = ((JavaToSQLValueNode)methodCall).getJavaValueNode();
+		methodCallBody = methodCall.getJavaValueNode();
 
 		/*
 		** Tell the method call that its return value (if any) will be
@@ -276,14 +250,19 @@
 
 		// this sets up the method
 		// generates:
-		// 	void userExprFun { }
+		// 	void userExprFun {
+		//     method_call(<args>);
+		//  }
+		//
+		//  An expression function is used to avoid reflection.
+		//  Since the arguments to a procedure are simple, this
+		// will be the only expression function and so it will
+		// be executed directly as e0.
 		MethodBuilder userExprFun = acb.newGeneratedFun("void", Modifier.PUBLIC);
 		userExprFun.addThrownException("java.lang.Exception");
 		methodCallBody.generate(acb, userExprFun);
 		userExprFun.endStatement();
 		userExprFun.methodReturn();
-
-		// we are done modifying userExprFun, complete it.
 		userExprFun.complete();
 
 		acb.pushGetResultSetFactoryExpression(mb);
@@ -315,9 +294,9 @@
 
 		Visitable returnNode = super.accept(v);
 
-		if (methodCall != null && !v.stopTraversal())
+		if (!v.stopTraversal())
 		{
-			methodCall = (ValueNode)methodCall.accept(v);
+			methodCall = (JavaToSQLValueNode) methodCall.accept(v);
 		}
 
 		return returnNode;