db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r589865 - in /db/derby/code/branches/10.1/java/engine/org/apache/derby: iapi/sql/ impl/services/bytecode/ impl/sql/ impl/sql/compile/ impl/sql/execute/
Date Mon, 29 Oct 2007 21:40:52 GMT
Author: kmarsden
Date: Mon Oct 29 14:40:51 2007
New Revision: 589865

URL: http://svn.apache.org/viewvc?rev=589865&view=rev
Log:
DERBY-738 DERBY-740 Initialize parameters within activation without
using generated code.
Have BCMethod.cast() optimize the case when the requested cast is to the
same Java type.
merge from trunk revision 351738, 354142


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

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/sql/ParameterValueSet.java
Mon Oct 29 14:40:51 2007
@@ -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/branches/10.1/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Mon Oct 29 14:40:51 2007
@@ -656,10 +656,33 @@
 	}
 
 	public void cast(String className) {
-		Type ct = cb.factory.type(className);
-		Type tbc = popStack();
-
+		
+		// Perform a simple optimization to not
+		// insert a checkcast when the classname
+		// of the cast exactly matches the type name
+		// currently on the stack.
+		// This can reduce the amount of generated code.
+		// This compiler/class generator does not load
+		// classes to check relationships or any other
+		// information. Thus other optimizations where a cast
+		// is not required are not implemented.
+		Type tbc = stackTypes[stackTypeOffset - 1];
+		
 		short sourceType = tbc.vmType();
+		
+		if (sourceType == BCExpr.vm_reference)
+		{
+			// Simple optimize step
+			if (className.equals(tbc.javaName()))
+			{
+				// do nothing, exact matching type
+				return;
+			}
+		}
+		
+		Type ct = cb.factory.type(className);
+		popStack();
+		
 		short targetType = ct.vmType();
 
 		if (SanityManager.DEBUG) {

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
Mon Oct 29 14:40:51 2007
@@ -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/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
Mon Oct 29 14:40:51 2007
@@ -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/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CallStatementNode.java
Mon Oct 29 14:40:51 2007
@@ -293,11 +293,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/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/CursorNode.java
Mon Oct 29 14:40:51 2007
@@ -558,11 +558,6 @@
 			acb.rememberCursor(mb);
 			acb.addCursorPositionCode();
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		generateParameterHolders(acb);
 	}
 
 	// class interface

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DMLStatementNode.java
Mon Oct 29 14:40:51 2007
@@ -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/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
Mon Oct 29 14:40:51 2007
@@ -652,12 +652,6 @@
 				constructor.endStatement();
 			}
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		if(!isDependentTable)
-			generateParameterHolders(acb);
 	}
 
 

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
Mon Oct 29 14:40:51 2007
@@ -792,11 +792,6 @@
 
 			mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertVTIResultSet", ClassName.ResultSet,
3);
 		}
-
-		/*
-		** ensure all parameters have been generated
-		*/
-		generateParameterHolders(acb);
 	}
 
 	/**

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java
Mon Oct 29 14:40:51 2007
@@ -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 
@@ -397,12 +388,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);
@@ -435,38 +421,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()
 	{
 		return (returnOutputParameter != null) ?
@@ -559,28 +513,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/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/SetSchemaNode.java
Mon Oct 29 14:40:51 2007
@@ -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/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
Mon Oct 29 14:40:51 2007
@@ -811,12 +811,6 @@
                               ClassName.ResultSet, 3);
             }
         }
-		/*
-		** ensure all parameters have been generated
-		*/
-		if(!isDependentTable)
-			generateParameterHolders(acb);
-
 	}
 
 	/**

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=589865&r1=589864&r2=589865&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
Mon Oct 29 14:40:51 2007
@@ -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