db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r354142 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/ impl/sql/ impl/sql/compile/ impl/sql/execute/
Date Mon, 05 Dec 2005 19:33:15 GMT
Author: djd
Date: Mon Dec  5 11:33:06 2005
New Revision: 354142

URL: http://svn.apache.org/viewcvs?rev=354142&view=rev
Log:
DERBY-738 Remove use of generated code per parameter for initiailizing parameters.
Previously the language compiler would generate some amount of code per paramter
in order to set up the parameter with a holder DataValueDescriptor of the correct type.
This patch changes the parameter set to be initialized when the activation is linked
to the language PreparedStatement (plan) utilizing the list of parameter types the plan has.
Thus no generated code is needed per parameter for set up.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameter.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java Mon Dec
 5 11:33:06 2005
@@ -20,11 +20,9 @@
 
 package org.apache.derby.iapi.sql;
 
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
 import org.apache.derby.iapi.error.StandardException;
 
+import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 
 /**
@@ -37,6 +35,12 @@
  */
 public interface ParameterValueSet
 {
+	/**
+	 * Initialize the parameter set by allocating DataValueDescriptor
+	 * corresponding to the passed in type for each parameter.
+	 * @param types expected to match the number of parameters.
+	 */
+	void initialize(DataTypeDescriptor[] types);
 
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameter.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameter.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameter.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameter.java Mon Dec
 5 11:33:06 2005
@@ -145,22 +145,17 @@
 	public GenericParameter getClone(GenericParameterValueSet pvs)
 	{
 		GenericParameter gpClone = new GenericParameter(pvs, isReturnOutputParameter);
-		gpClone.setStorableDataValue(this.getValue().getClone(), jdbcTypeId, declaredClassName);
+		gpClone.initialize(this.getValue().getClone(), jdbcTypeId, declaredClassName);
 		gpClone.isSet = true;
 
 		return gpClone;
 	}
 
 	/**
-	 * Set the DataValueDescriptor for this parameter.  If makrAsSet
-	 * is set, then we consider this parameter both initialized and
-	 * set.  Otherwise, it is just initialized but not yet set.
+	 * Set the DataValueDescriptor and type information for this parameter
 	 *
-	 * @param std the storable data value
-	 * @param markAsSet whether we should mark as being set or not.
-	 * 		The isSet() method will return this value.
 	 */
-	void setStorableDataValue(DataValueDescriptor value, int jdbcTypeId, String className)
+	void initialize(DataValueDescriptor value, int jdbcTypeId, String className)
 	{
 		this.value = value;
 		this.jdbcTypeId = jdbcTypeId;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
Mon Dec  5 11:33:06 2005
@@ -26,6 +26,7 @@
 
 import org.apache.derby.iapi.sql.ParameterValueSet;
 
+import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueFactory;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 
@@ -98,6 +99,21 @@
 	/*
 	** ParameterValueSet interface methods
 	*/
+	
+	/**
+	 * Initialize the set by allocating a holder DataValueDescriptor object
+	 * for each parameter.
+	 */
+	public void initialize(DataTypeDescriptor[] types)
+	{
+		for (int i = 0; i < parms.length; i++)
+		{
+			DataTypeDescriptor dtd = types[i];
+			
+			parms[i].initialize(dtd.getNull(),
+					dtd.getJDBCTypeId(), dtd.getTypeId().getCorrespondingJavaTypeName());
+		}
+	}
 
 	public void setParameterMode(int position, int mode) {
 		parms[position].parameterMode = (short) mode;
@@ -296,7 +312,7 @@
 			}
 		}
 
-		parms[position].setStorableDataValue(sdv, jdbcTypeId, className);
+		parms[position].initialize(sdv, jdbcTypeId, className);
 
 		/* NOTE: We do not deal with associated parameters here.
 		 * This method is only called from the generated code

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=354142&r1=354141&r2=354142&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
Mon Dec  5 11:33:06 2005
@@ -294,11 +294,6 @@
 		acb.pushMethodReference(mb, userExprFun); // first arg
 		acb.pushThisAsActivation(mb); // arg 2
 		mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCallStatementResultSet", ClassName.ResultSet,
2);
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		generateParameterHolders(acb);
 	}
 
 	public ResultDescription makeResultDescription()

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java Mon
Dec  5 11:33:06 2005
@@ -564,11 +564,6 @@
 			acb.rememberCursor(mb);
 			acb.addCursorPositionCode();
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		generateParameterHolders(acb);
 	}
 
 	// class interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
Mon Dec  5 11:33:06 2005
@@ -422,24 +422,6 @@
 				( acb, numberOfParameters, parameterList);
 	}
 
-	/*
-	** When all other generation is done for the statement,
-	** we need to ensure all of the parameters have been touched.
-	*
-	*	@param	acb				ActivationClassBuilder
-	*
-	*/
-	void generateParameterHolders(ActivationClassBuilder acb) 
-		throws StandardException
-	{
-		Vector pList = getCompilerContext().getParameterList();
-		if (pList.size() <= 0)
-			return;
-
-		ParameterNode.generateParameterHolders( acb,  pList);
-			
-	}
-
 	/**
 	 * A read statement is atomic (DMLMod overrides us) if there
 	 * are no work units, and no SELECT nodes, or if its SELECT nodes 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java Mon
Dec  5 11:33:06 2005
@@ -656,12 +656,6 @@
 				constructor.endStatement();
 			}
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		if(!isDependentTable)
-			generateParameterHolders(acb);
 	}
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java Mon
Dec  5 11:33:06 2005
@@ -785,11 +785,6 @@
 
 			mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertVTIResultSet", ClassName.ResultSet,
3);
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		generateParameterHolders(acb);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java Mon
Dec  5 11:33:06 2005
@@ -70,16 +70,7 @@
 	/*
 	** The parameter number for this parameter.  The numbers start at 0.
 	*/
-	int	parameterNumber;
-
-	/*
-	** We want to know if this node was generated or not.
-	** It will be skipped if it was in a predicate that
-	** was optimized out of the query.  Skipped parameters
-	** need to do some minimal generation so that we can
-	** make users pass in parameter values for us to ignore.
-	*/
-	private boolean generated;
+	private int	parameterNumber;
 
 	/*
 	** Pointer to the array in the DMLStatementNode that holds the
@@ -89,7 +80,7 @@
 	** are not filled in until their corresponding parameters are bound.
 	*/
 
-	DataTypeDescriptor[]	typeServices;
+	private DataTypeDescriptor[]	typeServices;
 
 	/*
 	** The default value for this parameter.  Currently, the only
@@ -97,14 +88,14 @@
 	** stored prepared statement, where they are supplied for
 	** optimization.
 	*/
-	DataValueDescriptor		defaultValue;
+	private DataValueDescriptor		defaultValue;
 
 	/**
 	  *	This ParameterNode may turn up as an argument to a replicated Work Unit.
 	  *	If so, the remote system will have figured out the type of this node.
 	  *	That's what this variable is for.
 	  */
-	protected	JSQLType			jsqlType;
+	private	JSQLType			jsqlType;
 
 	private int orderableVariantType = Qualifier.QUERY_INVARIANT;
 
@@ -143,7 +134,7 @@
 	 * @return	The parameter number
 	 */
 
-	public	int getParameterNumber()
+	int getParameterNumber()
 	{
 		return parameterNumber;
 	}
@@ -157,7 +148,7 @@
 	 * @return	Nothing
 	 */
 
-	public void setDescriptors(DataTypeDescriptor[] descriptors)
+	void setDescriptors(DataTypeDescriptor[] descriptors)
 	{
 
         // The following is commented out for #3546, for create publication 
@@ -391,12 +382,7 @@
 		//if (genRetval != null)
 		//	return genRetval;
 
-        /*
-        ** First, generate the holder in the constructor.
-        */
-        generateHolder(acb);
-
-        /* now do the return value */
+        /* Generate the return value */
 
         /* First, get the field that holds the ParameterValueSet */
         acb.pushPVSReference(mb);
@@ -429,38 +415,6 @@
         mb.cast(getTypeCompiler().interfaceName());
 	} // End of generateExpression
 
-	/*
-	** parameters might never be used, but still need
-	** to have space allocated for them and be assigned
-	** to, for the query to operate.
-	**
-	** This generates the minimum code needed to make
-	** the parameter exist.
-	*/
-	void generateHolder(ExpressionClassBuilder acb) throws StandardException {
-
-		MethodBuilder	constructor = acb.getConstructor();
-
-		if (generated) return;
-		generated = true;
-
-		/*
-		** First, build the statement in the constructor.
-		*/
-		acb.pushPVSReference(constructor);
-
-		acb.generateNull(constructor, getTypeCompiler()); constructor.upCast(ClassName.DataValueDescriptor);
-
-		constructor.push(parameterNumber); // second arg
-		TypeId myId = getTypeId();
-		constructor.push(myId.getJDBCTypeId()); // third arg
-		constructor.push(myId.getCorrespondingJavaTypeName()); // fouth arg
-
-		constructor.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "setStorableDataValue",
"void", 4);
-
-		/* The constructor portion is done */
-	}
-
 	public TypeId getTypeId() throws StandardException
 	{
 		return (returnOutputParameter != null) ?
@@ -553,28 +507,6 @@
 
 			executeMethod.pushThis();
 			executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfMissingParms",
"void", 0);
-		}
-	}
-
-	/*
-	** When all other generation is done for the statement,
-	** we need to ensure all of the parameters have been touched.
-	*
-	*	@param	acb				ExpressionClassBuilder
-	*	@param	parameterList	list of parameter
-	*
-	* @exception StandardException		Thrown on error
-	*/
-	static	public	void generateParameterHolders
-	( ExpressionClassBuilder acb, Vector parameterList ) 
-		throws StandardException
-	{
-		if (parameterList == null) return;
-
-		for (Enumeration paramEnum = parameterList.elements(); 
-			 paramEnum.hasMoreElements(); )
-		{
-			((ParameterNode)paramEnum.nextElement()).generateHolder(acb);
 		}
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java Mon
Dec  5 11:33:06 2005
@@ -131,9 +131,6 @@
 
 		mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getMiscResultSet",
 						ClassName.ResultSet, 1);
-
-		if (type == StatementType.SET_SCHEMA_DYNAMIC)
-			generateParameterHolders(acb);
 	}
 	/**
 	 * Generate the code to create the ParameterValueSet, if necessary,
@@ -157,22 +154,6 @@
 		ParameterNode.generateParameterValueSet ( acb, 1, parameterList);
 	}
 
-	/*
-	** When all other generation is done for the statement,
-	** we need to ensure all of the parameters have been touched.
-	*
-	*	@param	acb				ActivationClassBuilder
-	*
-	*/
-	void generateParameterHolders(ActivationClassBuilder acb) 
-		throws StandardException
-	{
-		Vector pList = getCompilerContext().getParameterList();
-		// we should have already failed if pList doesn't have at least 1 parameter
-
-		ParameterNode.generateParameterHolders( acb,  pList);
-			
-	}
 	/**
 	 * Returns the type of activation this class
 	 * generates.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java?rev=354142&r1=354141&r2=354142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java Mon
Dec  5 11:33:06 2005
@@ -803,12 +803,6 @@
                               ClassName.ResultSet, 3);
             }
         }
-		/*
-		** ensure all parameters have been generated
-		*/
-		if(!isDependentTable)
-			generateParameterHolders(acb);
-
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=354142&r1=354141&r2=354142&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
Mon Dec  5 11:33:06 2005
@@ -274,11 +274,17 @@
 	*/
 	public final void setupActivation(ExecPreparedStatement ps, boolean scrollable) {
 		preStmt = ps;
-
+				
 		if (ps != null) {
 			// get the result set description
    			resultDescription = ps.getResultDescription();
 			this.scrollable = scrollable;
+			
+			// Initialize the parameter set to have allocated
+			// DataValueDescriptor objects for each parameter.
+			if (pvs != null && pvs.getParameterCount() != 0)
+				pvs.initialize(ps.getParameterTypes());
+
 		} else {
 			resultDescription = null;
 			this.scrollable = false;
@@ -1215,7 +1221,7 @@
 		pvs = lcc.getLanguageFactory().newParameterValueSet(
 			lcc.getLanguageConnectionFactory().getClassFactory().getClassInspector(),
 			paramCount, hasReturnParam);
-	}
+		}
 
 	/**
 	 return the parameters.



Mime
View raw message