db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1399139 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/reference/ iapi/services/compiler/ impl/services/bytecode/ impl/sql/compile/ impl/sql/execute/
Date Wed, 17 Oct 2012 07:45:15 GMT
Author: kahatlen
Date: Wed Oct 17 07:45:15 2012
New Revision: 1399139

URL: http://svn.apache.org/viewvc?rev=1399139&view=rev
Log:
DERBY-5947: Factor out common code from generated classes

Remove three generated fields and six corresponding accessor methods
with a single field (an instance of a class with three fields) and one
getter method.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/ClassName.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/ClassBuilder.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
    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/ExpressionClassBuilder.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/iapi/reference/ClassName.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/ClassName.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/ClassName.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/ClassName.java Wed Oct
17 07:45:15 2012
@@ -61,6 +61,7 @@ public interface ClassName
 
 	String BaseActivation = "org.apache.derby.impl.sql.execute.BaseActivation";
 	String BaseExpressionActivation = "org.apache.derby.impl.sql.execute.BaseExpressionActivation";
+    String RowCountStats = "org.apache.derby.impl.sql.execute.BaseActivation$RowCountStats";
 
 	String CursorActivation = "org.apache.derby.impl.sql.execute.CursorActivation";
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/ClassBuilder.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/ClassBuilder.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/ClassBuilder.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/ClassBuilder.java
Wed Oct 17 07:45:15 2012
@@ -166,6 +166,11 @@ public interface ClassBuilder {
 	 * <p>
 	 * This is used to start a constructor as well; pass in
 	 * null for the returnType when used in that manner.
+     * <p>
+     * If the modifiers include static, the returned method builder is for
+     * a class or interface initialization method. Otherwise, the builder is
+     * for an instance initialization method.
+     * <p>
 	 *
 	 * @param modifiers the | of the Modifier
 	 *	constants representing the visibility and control of this
@@ -175,18 +180,4 @@ public interface ClassBuilder {
 	 * @see java.lang.reflect.Modifier
 	 */
 	MethodBuilder newConstructorBuilder(int modifiers);
-
-	/**
-		Create a new private field and its getter and setter methods.
-
-		@param getter getter for field
-		@param setter setter for field
-		@param methodModifier modifier for method
-		@param staticField true if the field is static
-		@param type type of the field, return type of the get method and
-		parameter type of the set method.
-
-	*/
-	void newFieldWithAccessors(String getter, String setter, int methodModifier,
-		boolean staticField, String type);
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
Wed Oct 17 07:45:15 2012
@@ -161,6 +161,17 @@ public interface MethodBuilder {
 	*/
 	public void getField(LocalField field);
 
+    /**
+     * Push the contents of the static field onto the stack.
+     * <pre>
+     * Stack ... =>
+     *       ...,field_value
+     * </pre>
+     *
+     * @param field a static field
+     */
+    public void getStaticField(LocalField field);
+
 	/**
 		Push the contents of the described field onto the stack.
 		This call requires the instance (reference) to be pushed by the caller.
@@ -194,6 +205,17 @@ public interface MethodBuilder {
 	*/
 	public void setField(LocalField field);
 
+    /**
+     * Pop the top stack value and store it in the static field.
+     * <pre>
+     * Stack ...,value =>
+     *       ...
+     * </pre>
+     *
+     * @param field a static field
+     */
+    public void setStaticField(LocalField field);
+
 	/**
 		Pop the top stack value and store it in the local field. 
 		This call pushes the this instance required to access the field itself.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java Wed
Oct 17 07:45:15 2012
@@ -21,33 +21,20 @@
 
 package org.apache.derby.impl.services.bytecode;
 
-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.services.classfile.ClassHolder;
-import org.apache.derby.iapi.services.classfile.ClassMember;
-import org.apache.derby.iapi.services.classfile.ClassFormatOutput;
-import org.apache.derby.iapi.services.loader.ClassFactory;
-
-import org.apache.derby.iapi.services.monitor.Monitor;
-
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
-
-import org.apache.derby.iapi.util.ByteArray;
-import org.apache.derby.iapi.services.classfile.VMOpcode;
-
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-
+import org.apache.derby.iapi.services.classfile.ClassFormatOutput;
+import org.apache.derby.iapi.services.classfile.ClassHolder;
+import org.apache.derby.iapi.services.classfile.ClassMember;
+import org.apache.derby.iapi.services.compiler.LocalField;
+import org.apache.derby.iapi.services.compiler.MethodBuilder;
+import org.apache.derby.iapi.services.loader.ClassFactory;
 import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.services.classfile.VMDescriptor;
-
-import org.apache.derby.impl.services.bytecode.GClass;
-
-import java.io.IOException;
+import org.apache.derby.iapi.util.ByteArray;
 
 /**
  * ClassBuilder is used to construct a java class's byte array
@@ -276,6 +263,11 @@ class BCClass extends GClass {
 	 * <p>
 	 * This is used to start a constructor as well; pass in
 	 * null for the returnType when used in that manner.
+     * <p>
+     * If the modifiers include static, the returned method builder is for
+     * a class or interface initialization method. Otherwise, the builder is
+     * for an instance initialization method.
+     * <p>
 	 *
 	 * See Modifiers
 	 * @param modifiers the | of the Modifiers
@@ -285,13 +277,8 @@ class BCClass extends GClass {
 	 * @return the method builder for the constructor.
 	 */
 	public MethodBuilder newConstructorBuilder(int modifiers) {
-
-		BCMethod m = new BCMethod(this, "void", "<init>", 
-									modifiers,
-									(String []) null,
-									factory);
-
-		return m;
+        String method = Modifier.isStatic(modifiers) ? "<clinit>" : "<init>";
+        return new BCMethod(this, "void", method, modifiers, null, factory);
 	}
   	//
 	// class interface
@@ -357,70 +344,6 @@ class BCClass extends GClass {
 		return cf;
 	}
 
-	public void newFieldWithAccessors(String getter, String setter,
-		int methodModifers,
-		boolean staticField, String type) {
-
-		String vmType = factory.type(type).vmName();
-		methodModifers |= Modifier.FINAL;
-
-
-		// add a field, field has same name as get method
-		int fieldModifiers = Modifier.PRIVATE;
-		if (staticField)
-			fieldModifiers |= Modifier.STATIC;
-
-		ClassMember field = classHold.addMember(getter, vmType, fieldModifiers);
-		int cpi = classHold.addFieldReference(field);
-
-		/*
-		** add the get method
-		*/
-
-		String sig = BCMethodDescriptor.get(BCMethodDescriptor.EMPTY, vmType, factory);
-
-		ClassMember method = classHold.addMember(getter, sig, methodModifers);
-
-		CodeChunk chunk = new CodeChunk(this);
-
-		// load 'this' if required
-		if (!staticField)
-			chunk.addInstr(VMOpcode.ALOAD_0); // this
-		
-		// get the field value
-		chunk.addInstrU2((staticField ? VMOpcode.GETSTATIC : VMOpcode.GETFIELD), cpi);
-
-		// and return it
-		short vmTypeId = BCJava.vmTypeId(vmType);
-
-		chunk.addInstr(CodeChunk.RETURN_OPCODE[vmTypeId]);
-
-		int typeWidth = Type.width(vmTypeId);
-		chunk.complete(null, classHold, method, typeWidth, 1);
-
-		/*
-		** add the set method
-		*/
-		String[] pda = new String[1];
-		pda[0] = vmType;
-		sig = new BCMethodDescriptor(pda, VMDescriptor.VOID, factory).toString();
-		method = classHold.addMember(setter, sig, methodModifers);
-		chunk = new CodeChunk(this);
-
-		// load 'this' if required
-		if (!staticField)
-			chunk.addInstr(VMOpcode.ALOAD_0); // this
-		// push the only parameter
-		chunk.addInstr((short) (CodeChunk.LOAD_VARIABLE_FAST[vmTypeId] + 1));
-		
-		// and set the field
-		chunk.addInstrU2((staticField ? VMOpcode.PUTSTATIC : VMOpcode.PUTFIELD), cpi);
-
-		chunk.addInstr(VMOpcode.RETURN);
-
-		chunk.complete(null, classHold, method, typeWidth + (staticField ? 0 : 1), 1 + typeWidth);
-	}
-	
 	/**
 	 * Add the fact that some class limit was exceeded while generating
 	 * the class. We create a set of them and report at the end, this

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Wed Oct 17 07:45:15 2012
@@ -675,8 +675,7 @@ class BCMethod implements MethodBuilder 
 			growStack(rw, rt);
 		else
 		{
-			if (stackDepth == 0)
-				overflowMethodCheck();
+            overflowMethodCheck();
 		}
 		return cpi;
 	}
@@ -736,8 +735,7 @@ class BCMethod implements MethodBuilder 
 			growStack(rw, rt);
 		else
 		{
-			if (stackDepth == 0)
-				overflowMethodCheck();
+            overflowMethodCheck();
 		}
 		// Check the declared type of the method
 		if (SanityManager.DEBUG) {
@@ -887,6 +885,12 @@ class BCMethod implements MethodBuilder 
 
 	}
 
+    public void getStaticField(LocalField field) {
+        BCLocalField lf = (BCLocalField) field;
+        myCode.addInstrU2(VMOpcode.GETSTATIC, lf.cpi);
+        growStack(lf.type);
+    }
+
 	public void getField(String declaringClass, String fieldName, String fieldType) {
 		Type dt = popStack();
 
@@ -918,14 +922,17 @@ class BCMethod implements MethodBuilder 
 	 */
 	public void setField(LocalField field) {
 		BCLocalField lf = (BCLocalField) field;
-		Type lt = lf.type;
-
 		putField(lf.type, lf.cpi, false);
-
-		if (stackDepth == 0)
-			overflowMethodCheck();
+        overflowMethodCheck();
 	}
 
+    public void setStaticField(LocalField field) {
+        BCLocalField lf = (BCLocalField) field;
+        myCode.addInstrU2(VMOpcode.PUTSTATIC, lf.cpi);
+        popStack();
+        overflowMethodCheck();
+    }
+
 	/**
 		Upon entry the top word(s) on the stack is
 		the value to be put into the field. Ie.
@@ -947,8 +954,6 @@ class BCMethod implements MethodBuilder 
 	*/
 	public void putField(LocalField field) {
 		BCLocalField lf = (BCLocalField) field;
-		Type lt = lf.type;
-
 		putField(lf.type, lf.cpi, true);
 	}
 
@@ -1072,8 +1077,7 @@ class BCMethod implements MethodBuilder 
 
 		myCode.addInstr(toPop.width() == 2  ? VMOpcode.POP2 : VMOpcode.POP);
 		
-		if (stackDepth == 0)
-			overflowMethodCheck();
+        overflowMethodCheck();
 	}	
 
 	public void endStatement() {
@@ -1271,6 +1275,11 @@ class BCMethod implements MethodBuilder 
 	 */
 	private void overflowMethodCheck()
 	{
+        if (stackDepth != 0) {
+            // Can only overflow to new method if the stack is empty.
+            return;
+        }
+
 		if (handlingOverflow)
 			return;
 		

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=1399139&r1=1399138&r2=1399139&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:15 2012
@@ -282,14 +282,23 @@ class ActivationClassBuilder	extends	Exp
 		executeMethod.methodReturn();
 		executeMethod.complete();
 
-		getClassBuilder().newFieldWithAccessors("getExecutionCount", "setExecutionCount",
-			Modifier.PROTECTED, true, "int");
-
-		getClassBuilder().newFieldWithAccessors("getRowCountCheckVector", "setRowCountCheckVector",
-			Modifier.PROTECTED, true, "java.util.Vector");
-
-		getClassBuilder().newFieldWithAccessors("getStalePlanCheckInterval", "setStalePlanCheckInterval",
-			Modifier.PROTECTED, true, "int");
+        // Create and initialize a static field that holds row count statistics.
+        LocalField rowCountField = newFieldDeclaration(
+                Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL,
+                ClassName.RowCountStats);
+        MethodBuilder init = getStaticInitializer();
+        init.pushNewStart(ClassName.RowCountStats);
+        init.pushNewComplete(0);
+        init.setStaticField(rowCountField);
+
+        // Create a method that returns the row count statistics.
+        MethodBuilder getRowCountStats = cb.newMethodBuilder(
+                Modifier.PROTECTED | Modifier.FINAL,
+                ClassName.RowCountStats,
+                "getRowCountStats");
+        getRowCountStats.getStaticField(rowCountField);
+        getRowCountStats.methodReturn();
+        getRowCountStats.complete();
 
 		if (closeActivationMethod != null) {
 			closeActivationMethod.methodReturn();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java?rev=1399139&r1=1399138&r2=1399139&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
Wed Oct 17 07:45:15 2012
@@ -102,6 +102,7 @@ abstract	class ExpressionClassBuilder im
 	protected int nextNonFastExpr;
 	protected int nextFieldNum;
 	protected MethodBuilder constructor;
+    protected MethodBuilder staticInitializer;
 	CompilerContext myCompCtx;
 	MethodBuilder executeMethod; // to find it fast
 
@@ -198,6 +199,13 @@ abstract	class ExpressionClassBuilder im
 		return constructor;
 	}
 
+    MethodBuilder getStaticInitializer() {
+        if (staticInitializer == null) {
+            staticInitializer = cb.newConstructorBuilder(Modifier.STATIC);
+        }
+        return staticInitializer;
+    }
+
 	ClassBuilder getClassBuilder() {
 		return cb;
 	}
@@ -266,6 +274,17 @@ abstract	class ExpressionClassBuilder im
 		constructor.complete();
 	}
 
+    /**
+     * Finish the static initializer, if there is one, by putting a return
+     * at the end of it.
+     */
+    void finishStaticInitializer() throws StandardException {
+        if (staticInitializer != null) {
+            staticInitializer.methodReturn();
+            staticInitializer.complete();
+        }
+    }
+
 	/**
 	 * Generate the assignment for row = new ExecRow[numResultSets]
 	 *

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=1399139&r1=1399138&r2=1399139&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:15 2012
@@ -382,6 +382,9 @@ public abstract class StatementNode exte
 		// wrap up the constructor by putting a return at the end of it
 		generatingClass.finishConstructor();
 
+        // wrap up the static initializer by putting a return at the end of it
+        generatingClass.finishStaticInitializer();
+
 		try {
 			// cook the completed class into a real class
 			// and stuff it into activationClass

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=1399139&r1=1399138&r2=1399139&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:15 2012
@@ -27,6 +27,7 @@ import java.sql.SQLWarning;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Vector;
 
 import	org.apache.derby.catalog.Dependable;
@@ -870,6 +871,35 @@ public abstract class BaseActivation imp
 		}
 	}
 
+    /**
+     * This class holds row count statistics for a query.
+     */
+    protected static class RowCountStats {
+        /**
+         * Stale plan check interval tells how often the row counts should be
+         * checked. Cached here so that we don't need to query the database
+         * properties on each execution.
+         */
+        private int stalePlanCheckInterval;
+        /** The number of times this query has been executed. */
+        private int executionCount;
+        /** List with row count estimates for each table in the query. */
+        private final List rowCounts;
+
+        public RowCountStats() {
+            rowCounts = new ArrayList();
+        }
+    }
+
+    /**
+     * Get the object holding row count statistics for this activation.
+     *
+     * It may return {@code null} if row count statistics are not maintained
+     * for the activation. In that case, {@link #shouldWeCheckRowCounts()}
+     * must return {@code false}.
+     */
+    protected abstract RowCountStats getRowCountStats();
+
 	/**
 		@see Activation#informOfRowCount
 		@exception StandardException	Thrown on error
@@ -889,15 +919,10 @@ public abstract class BaseActivation imp
 			/* Check each result set only once per execution */
 			if (rowCountsCheckedThisExecution.add(rsn))
 			{
-				synchronized (getPreparedStatement())
+                final RowCountStats stats = getRowCountStats();
+                synchronized (stats)
 				{
-					Vector rowCountCheckVector = getRowCountCheckVector();
-
-					if (rowCountCheckVector == null) {
-						rowCountCheckVector = new Vector();
-						setRowCountCheckVector(rowCountCheckVector);
-					}
-
+                    final List rowCountCheckVector = stats.rowCounts;
 					Long firstRowCount = null;
 
 					/*
@@ -906,11 +931,14 @@ public abstract class BaseActivation imp
 					if (resultSetNumber < rowCountCheckVector.size())
 					{
 						firstRowCount =
-							(Long) rowCountCheckVector.elementAt(resultSetNumber);
+                            (Long) rowCountCheckVector.get(resultSetNumber);
 					}
 					else
 					{
-						rowCountCheckVector.setSize(resultSetNumber + 1);
+                        int newSize = resultSetNumber + 1;
+                        while (rowCountCheckVector.size() < newSize) {
+                            rowCountCheckVector.add(null);
+                        }
 					}
 
 					if (firstRowCount != null)
@@ -1001,11 +1029,8 @@ public abstract class BaseActivation imp
 					}
 					else
 					{
-						firstRowCount = new Long(currentRowCount);
-						rowCountCheckVector.setElementAt(
-														firstRowCount,
-														resultSetNumber
-														);
+                        rowCountCheckVector.set(
+                            resultSetNumber, new Long(currentRowCount));
 
 					}
 				}
@@ -1028,7 +1053,7 @@ public abstract class BaseActivation imp
 	public void startExecution() throws StandardException
 	{
 		// determine if we should check row counts during this execution
-		shouldWeCheckRowCounts();
+        checkRowCounts = shouldWeCheckRowCounts();
 
 		// If we are to check row counts, clear the hash table of row counts
 		// we have checked.
@@ -1160,15 +1185,22 @@ public abstract class BaseActivation imp
 		return targetVTI;
 	}
 
-	private void shouldWeCheckRowCounts() throws StandardException
+    /**
+     * Find out if it's time to check the row counts of the tables involved
+     * in this query.
+     * @return true if the row counts should be checked, false otherwise
+     */
+	protected boolean shouldWeCheckRowCounts() throws StandardException
 	{
+        final RowCountStats stats = getRowCountStats();
+
 		/*
 		** Check the row count only every N executions.  OK to check this
 		** without synchronization, since the value of this number is not
 		** critical.  The value of N is determined by the property
 		** derby.language.stalePlanCheckInterval.
 		*/
-		int executionCount = getExecutionCount() + 1;
+        int executionCount = ++stats.executionCount;
 
 		/*
 		** Always check row counts the first time, to establish the
@@ -1181,16 +1213,16 @@ public abstract class BaseActivation imp
 
 		if (executionCount == 1)
 		{
-			checkRowCounts = true;
+            return true;
 		}
 		else if (executionCount <
 								Property.MIN_LANGUAGE_STALE_PLAN_CHECK_INTERVAL)
 		{
-			checkRowCounts = false;
+            return false;
 		}
 		else
 		{
-			int stalePlanCheckInterval = getStalePlanCheckInterval();
+            int stalePlanCheckInterval = stats.stalePlanCheckInterval;
 
 			/*
 			** Only query the database property once.  We can tell because
@@ -1208,44 +1240,14 @@ public abstract class BaseActivation imp
 							Integer.MAX_VALUE,
 							Property.DEFAULT_LANGUAGE_STALE_PLAN_CHECK_INTERVAL
 							);
-				setStalePlanCheckInterval(stalePlanCheckInterval);
+                stats.stalePlanCheckInterval = stalePlanCheckInterval;
 			}
 
-			checkRowCounts = (executionCount % stalePlanCheckInterval) == 1;
-
+            return (executionCount % stalePlanCheckInterval) == 1;
 
 		}
-
-		setExecutionCount(executionCount);
 	}
 
-	/*
-	** These accessor methods are provided by the sub-class to help figure
-	** out whether to check row counts during this execution.
-	*/
-	abstract protected int getExecutionCount();
-
-	abstract protected void setExecutionCount(int newValue); 
-
-	/*
-	** These accessor methods are provided by the sub-class to help figure
-	** out whether the row count for a particular result set has changed
-	** enough to force recompilation.
-	*/
-	abstract protected Vector getRowCountCheckVector();
-
-	abstract protected void setRowCountCheckVector(Vector newValue);
-
-	/*
-	** These accessor methods are provided by the sub-class to remember the
-	** value of the stale plan check interval property, so that we only
-	** have to query the database properties once (there is heavyweight
-	** synchronization around the database properties).
-	*/
-	abstract protected int getStalePlanCheckInterval();
-
-	abstract protected void setStalePlanCheckInterval(int newValue);
-
 	public final boolean getScrollable() {
 		return scrollable;
 	}

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=1399139&r1=1399138&r2=1399139&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:15 2012
@@ -42,15 +42,20 @@ import java.util.Vector;
  */
 public final class ConstantActionActivation extends BaseActivation
 {
-
-	public int getExecutionCount() { return 0;}
-	public void setExecutionCount(int count) {}
-
-	public Vector getRowCountCheckVector() {return null;}
-	public void setRowCountCheckVector(Vector v) {}
-
-	public int getStalePlanCheckInterval() { return Integer.MAX_VALUE; }
-	public void setStalePlanCheckInterval(int count) {}
+    /**
+     * Always return false since constant actions don't need recompilation
+     * when the row counts change.
+     */
+    protected boolean shouldWeCheckRowCounts() {
+        return false;
+    }
+
+    /**
+     * Always return null since constant actions never check row counts.
+     */
+    protected RowCountStats getRowCountStats() {
+        return null;
+    }
 
 	public ResultSet execute() throws StandardException {
 



Mime
View raw message