Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7B039D301 for ; Wed, 17 Oct 2012 07:46:21 +0000 (UTC) Received: (qmail 74185 invoked by uid 500); 17 Oct 2012 07:46:21 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 74158 invoked by uid 500); 17 Oct 2012 07:46:21 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 74150 invoked by uid 99); 17 Oct 2012 07:46:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Oct 2012 07:46:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Oct 2012 07:46:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9F7E923889BB; Wed, 17 Oct 2012 07:45:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1399140 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql: compile/ActivationClassBuilder.java compile/StatementNode.java execute/BaseActivation.java execute/ConstantActionActivation.java Date: Wed, 17 Oct 2012 07:45:36 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121017074536.9F7E923889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed Oct 17 07:45:35 2012 New Revision: 1399140 URL: http://svn.apache.org/viewvc?rev=1399140&view=rev Log: DERBY-5947: Factor out common code from generated classes - Move common code from the generated execute() method to a method in BaseActivation, and rename the generated execute() method to doExecute(), called from BaseActivation.execute(). - Simplify generated code in doExecute(). Specifically, fetch the resultSet field only once. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ActivationClassBuilder.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StatementNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ConstantActionActivation.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ActivationClassBuilder.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ActivationClassBuilder.java?rev=1399140&r1=1399139&r2=1399140&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ActivationClassBuilder.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ActivationClassBuilder.java Wed Oct 17 07:45:35 2012 @@ -21,40 +21,14 @@ package org.apache.derby.impl.sql.compile; -import org.apache.derby.iapi.services.compiler.ClassBuilder; -import org.apache.derby.iapi.services.compiler.MethodBuilder; -import org.apache.derby.iapi.services.compiler.LocalField; -import org.apache.derby.iapi.reference.ClassName; - - -import org.apache.derby.iapi.services.sanity.SanityManager; - -import org.apache.derby.iapi.sql.compile.CompilerContext; -import org.apache.derby.iapi.sql.compile.CodeGeneration; - -import org.apache.derby.iapi.sql.execute.CursorResultSet; - -import org.apache.derby.iapi.sql.ResultSet; - -import org.apache.derby.iapi.sql.execute.ExecRow; - -import org.apache.derby.iapi.types.DataTypeDescriptor; -import org.apache.derby.iapi.types.TypeId; - +import java.lang.reflect.Modifier; import org.apache.derby.iapi.error.StandardException; - -import org.apache.derby.iapi.services.loader.GeneratedMethod; +import org.apache.derby.iapi.reference.ClassName; import org.apache.derby.iapi.services.classfile.VMOpcode; - -import java.lang.reflect.Modifier; - -import java.io.PrintWriter; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Hashtable; +import org.apache.derby.iapi.services.compiler.LocalField; +import org.apache.derby.iapi.services.compiler.MethodBuilder; +import org.apache.derby.iapi.sql.compile.CodeGeneration; +import org.apache.derby.iapi.sql.compile.CompilerContext; /** * ActivationClassBuilder @@ -108,8 +82,7 @@ class ActivationClassBuilder extends Exp *
 	 *    public class #className extends #superClass {
 	 *		// public void reset() { return; }
-	 *		public ResultSet execute() throws StandardException {
-	 *			throwIfClosed("execute");
+	 *		protected ResultSet doExecute() throws StandardException {
 	 *			// statements must be added here
 	 *		}
 	 *		public #className() { super(); }
@@ -192,8 +165,7 @@ class ActivationClassBuilder	extends	Exp
 	/**
 	 * By the time this is done, it has generated the following code
 	 * 
-	 *		public ResultSet execute() throws StandardException {
-	 *			throwIfClosed("execute");
+	 *		protected ResultSet doExecute() throws StandardException {
 	 *			// statements must be added here
 	 *		}
 	 *    }
@@ -222,25 +194,14 @@ class ActivationClassBuilder	extends	Exp
 		// mb.complete(); // there is nothing else.
 
 
-		// This method is an implementation of the interface method
-		// Activation - ResultSet execute()
+		// This method is an implementation of the abstract method
+		// BaseActivation - ResultSet doExecute()
 
 		// create an empty execute method
-		MethodBuilder mb = cb.newMethodBuilder(Modifier.PUBLIC,
-			ClassName.ResultSet, "execute");
+		MethodBuilder mb = cb.newMethodBuilder(Modifier.PROTECTED,
+			ClassName.ResultSet, "doExecute");
 		mb.addThrownException(ClassName.StandardException);
 
-		// put a 'throwIfClosed("execute");' statement into the execute method.
-		mb.pushThis(); // instance
-		mb.push("execute");
-		mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfClosed", "void", 1);
-
-		// call this.startExecution(), so the parent class can know an execution
-		// has begun.
-
-		mb.pushThis(); // instance
-		mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "startExecution", "void", 0);
-
 		return	mb;
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StatementNode.java?rev=1399140&r1=1399139&r2=1399140&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StatementNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StatementNode.java Wed Oct 17 07:45:35 2012
@@ -301,10 +301,10 @@ public abstract class StatementNode exte
 
         /*
          * Generate the code to execute this statement.
-         * Two methods are generated here: execute() and
+         * Two methods are generated here: doExecute() and
          * fillResultSet().
          * 
- * execute is called for every execution of the + * doExecute() is called for every execution of the * Activation. Nodes may add code to this using * ActivationClassBuilder.getExecuteMethod(). * This code will be executed every execution. @@ -315,12 +315,8 @@ public abstract class StatementNode exte *

* The generated code is equivalent to: * - * public ResultSet execute() { + * protected ResultSet doExecute() { * - * // these two added by ActivationClassBuilder - * throwIfClosed("execute"); - * startExecution(); - * * [per-execution code added by nodes] * * if (resultSet == null) @@ -346,26 +342,33 @@ public abstract class StatementNode exte mbWorker.methodReturn(); mbWorker.complete(); + // Get the value of the resultSet field. executeMethod.pushThis(); executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet); - + + // Keep a copy of the field value on the stack so we don't need + // to look it up again if it's non-null. + executeMethod.dup(); executeMethod.conditionalIfNull(); - + + // The field was null, so we won't use the value that's on the + // stack. Forget about it. + executeMethod.pop(); + // Generate the result set tree and store the // resulting top-level result set into the resultSet // field, as well as returning it from the execute method. - + + // Push this onto the stack twice, as both callMethod() and + // putField() take the instance as first operand. executeMethod.pushThis(); + executeMethod.dup(); executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, "fillResultSet", ClassName.ResultSet, 0); - executeMethod.pushThis(); - executeMethod.swap(); executeMethod.putField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet); executeMethod.startElseCode(); // this is here as the compiler only supports ? : - executeMethod.pushThis(); - executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet); executeMethod.completeConditional(); // wrap up the activation class definition Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=1399140&r1=1399139&r2=1399140&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java Wed Oct 17 07:45:35 2012 @@ -258,6 +258,27 @@ public abstract class BaseActivation imp // Activation interface // + public final ResultSet execute() throws StandardException { + throwIfClosed("execute"); + + // Determine if we should check row counts during this execution. + checkRowCounts = shouldWeCheckRowCounts(); + + // If we are to check row counts, clear the hash table of row counts + // we have checked. + if (checkRowCounts) { + rowCountsCheckedThisExecution.clear(); + } + + return doExecute(); + } + + /** + * Abstract method overridden by generated classes, containing the + * body of the {@link #execute()} method. + */ + protected abstract ResultSet doExecute() throws StandardException; + public final ExecPreparedStatement getPreparedStatement() { return preStmt; } @@ -1046,22 +1067,6 @@ public abstract class BaseActivation imp } /** - * The subclass calls this method when it begins an execution. - * - * @exception StandardException Thrown on error - */ - public void startExecution() throws StandardException - { - // determine if we should check row counts during this execution - checkRowCounts = shouldWeCheckRowCounts(); - - // If we are to check row counts, clear the hash table of row counts - // we have checked. - if (checkRowCounts) - rowCountsCheckedThisExecution.clear(); - } - - /** * @see Activation#getHeapConglomerateController */ public ConglomerateController getHeapConglomerateController() Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ConstantActionActivation.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ConstantActionActivation.java?rev=1399140&r1=1399139&r2=1399140&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ConstantActionActivation.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ConstantActionActivation.java Wed Oct 17 07:45:35 2012 @@ -57,14 +57,11 @@ public final class ConstantActionActivat return null; } - public ResultSet execute() throws StandardException { - - throwIfClosed("execute"); - startExecution(); - + protected ResultSet doExecute() throws StandardException { if (resultSet == null) resultSet = getResultSetFactory().getDDLResultSet(this); return resultSet; } + public void postConstructor(){} }