db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r552995 - in /db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile: CastNode.java ConditionalNode.java
Date Tue, 03 Jul 2007 21:53:37 GMT
Author: djd
Date: Tue Jul  3 14:53:36 2007
New Revision: 552995

URL: http://svn.apache.org/viewvc?view=rev&rev=552995
Log:
DERBY-2775 (cleanup) Change CastNode to use type information from its parent ValueNode.
Merge of 552038 from trunk.

Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&rev=552995&r1=552994&r2=552995
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
Tue Jul  3 14:53:36 2007
@@ -70,12 +70,11 @@
 
 public class CastNode extends ValueNode
 {
-	DataTypeDescriptor	castTarget;
 	ValueNode			castOperand;
-	int					targetCharType;
-	TypeId	destCTI = null;
+	private int					targetCharType;
 	TypeId	sourceCTI = null;
-	boolean forDataTypeFunction = false;
+	private boolean forDataTypeFunction = false;
+    
 	/** This variable gets set by the parser to indiciate that this CAST node 
 	 * has been generated by the parser. This means that we should use the 
 	 * collation info of the current compilation schmea for this node's 
@@ -86,7 +85,7 @@
 	 * node. Collation info is part of the DataTypeDescriptor that's defined
 	 * on the ValueNode (the super class of this CastNode class)
 	 */ 
-	boolean externallyGeneratedCastNode = false;
+	private boolean externallyGeneratedCastNode = false;
 
 	/*
 	** Static array of valid casts.  Dimentions
@@ -107,7 +106,7 @@
 		throws StandardException
 	{
 		this.castOperand = (ValueNode) castOperand;
-		this.castTarget = (DataTypeDescriptor) castTarget;
+		setType((DataTypeDescriptor) castTarget);
 	}
 
 	/**
@@ -128,7 +127,7 @@
 		targetCharType = ((Integer) charType).intValue();
 		if (charLen < 0)	// unknown, figure out later
 			return;
-		this.castTarget = DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, charLen);
+		setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, charLen));
 	}
 
 	/**
@@ -142,8 +141,13 @@
 	{
 		if (SanityManager.DEBUG)
 		{
-			return "castTarget: " + castTarget + "\n" +
-				super.toString();
+			try {
+                return "castTarget: " + getTypeServices() + "\n" +
+                	super.toString();
+            } catch (StandardException e) {
+                // TEMP - getTypeServices() should not be throwing an exception
+                return "";
+            }
 		}
 		else
 		{
@@ -198,7 +202,7 @@
 								fromList, subqueryList,
 								aggregateVector);
 
-		if (castTarget == null)   //CHAR or VARCHAR function without specifying target length
+		if (getTypeServices() == null)   //CHAR or VARCHAR function without specifying target length
 		{
 			DataTypeDescriptor opndType = castOperand.getTypeServices();
 			int length = -1;
@@ -239,7 +243,7 @@
 			}
 			if (length < 0)
 				length = 1;  // same default as in parser
-			castTarget = DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, length);
+			setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, length));
 			
 		}
 
@@ -249,7 +253,7 @@
 		*/
 		if (castOperand instanceof UntypedNullConstantNode)
 		{
-			castOperand.setType(castTarget);
+			castOperand.setType(getTypeServices());
 		}
 
 		bindCastNodeOnly();
@@ -281,7 +285,7 @@
 			/* RESOLVE - to be filled in. */
 			ValueNode retNode = this;
 			int		  sourceJDBCTypeId = sourceCTI.getJDBCTypeId();
-			int		  destJDBCTypeId = destCTI.getJDBCTypeId();
+			int		  destJDBCTypeId = getTypeId().getJDBCTypeId();
 
 			switch (sourceJDBCTypeId)
 			{
@@ -300,7 +304,7 @@
 											C_NodeTypes.CHAR_CONSTANT_NODE,
 											booleanString,
 											ReuseFactory.getInteger(
-												castTarget.getMaximumWidth()),
+                                                    getTypeServices().getMaximumWidth()),
 											getContextManager());
 					}
 					break;
@@ -322,7 +326,7 @@
 												C_NodeTypes.CHAR_CONSTANT_NODE,
 												castValue, 
 												ReuseFactory.getInteger(
-												  castTarget.getMaximumWidth()),
+                                                        getTypeServices().getMaximumWidth()),
 												getContextManager());
 						}
 						break;
@@ -368,13 +372,11 @@
 		/*
 		** The result type is always castTarget.
 		*/
-		setType(castTarget);
-		destCTI = castTarget.getTypeId();
 		sourceCTI = castOperand.getTypeId();
 
 		//If the result type of cast is string data type, then that data type 
 		//should get it's collation type from the current schema. 
-		if (externallyGeneratedCastNode && destCTI.isStringTypeId()) {
+		if (externallyGeneratedCastNode && getTypeId().isStringTypeId()) {
 			//set the collation type to be same as the compilation schema's 
 			//collation type. Collation derivation will be set to "IMPLICIT".
 			setCollationUsingCompilationSchema(
@@ -384,17 +386,15 @@
 		** If it is a java cast, do some work to make sure
 		** the classes are ok and that they are compatible
 		*/
-		if (destCTI.userType())
+		if (getTypeId().userType())
 		{
 			String className = getTypeId().getCorrespondingJavaTypeName();
 
 			verifyClassExist(className);
 
-			castTarget = new DataTypeDescriptor(TypeId.getUserDefinedTypeId(className, false),
+			setType(new DataTypeDescriptor(TypeId.getUserDefinedTypeId(className, false),
 														true /* assume nullable for now, change it if not nullable */
-													);
-			setType(castTarget);
-			destCTI = castTarget.getTypeId();
+													));
 		}
 
 		if (castOperand.requiresTypeFromContext())
@@ -413,11 +413,11 @@
 			** Make sure we can assign the two classes
 			*/
 			TypeCompiler tc = castOperand.getTypeCompiler();
-			if (! tc.convertible(destCTI, forDataTypeFunction))
+			if (! tc.convertible(getTypeId(), forDataTypeFunction))
 			{
 				throw StandardException.newException(SQLState.LANG_INVALID_CAST, 
 						sourceCTI.getSQLTypeName(),
-						destCTI.getSQLTypeName());
+                        getTypeId().getSQLTypeName());
 			}
 		}		
 	}
@@ -567,7 +567,7 @@
 										C_NodeTypes.CHAR_CONSTANT_NODE,
 										Long.toString(longValue), 
 										ReuseFactory.getInteger(
-											castTarget.getMaximumWidth()),
+                                                getTypeServices().getMaximumWidth()),
 										getContextManager());
 			case Types.TINYINT:
 				if (longValue < Byte.MIN_VALUE ||
@@ -664,7 +664,7 @@
 										nodeType,
 										constantObject, 
 										ReuseFactory.getInteger(
-											castTarget.getMaximumWidth()),
+                                                getTypeServices().getMaximumWidth()),
 										getContextManager());
 
 			case Types.TINYINT:
@@ -811,7 +811,7 @@
 	void bindParameter()
 					throws StandardException
 	{
-		castOperand.setType(castTarget);
+		castOperand.setType(getTypeServices());
 	}
 
 	/**
@@ -839,7 +839,7 @@
 
 		// Simple if source and destination are of same type
 		if (sourceCTI.getCorrespondingJavaTypeName().equals(
-				destCTI.getCorrespondingJavaTypeName()))
+                getTypeId().getCorrespondingJavaTypeName()))
 		{
 			return sourceObject;
 		}
@@ -879,7 +879,7 @@
 		 */
 		else if (castOperand.requiresTypeFromContext())
 		{
-			sourceCTI = destCTI;
+			sourceCTI = getTypeId();
 		}
 	
 		genDataValueConversion(acb, mb);
@@ -902,8 +902,8 @@
 		** the object.
 		*/
 
-		acb.generateNull(acbConstructor, getTypeCompiler(destCTI), 
-				castTarget.getCollationType());
+		acb.generateNull(acbConstructor, getTypeCompiler(getTypeId()), 
+                getTypeServices().getCollationType());
 		acbConstructor.setField(field);
 
 
@@ -921,7 +921,7 @@
 			targetDVD.setWidth();
 		*/
 
-		if (!sourceCTI.userType() && !destCTI.userType()) {
+		if (!sourceCTI.userType() && !getTypeId().userType()) {
 			mb.getField(field); // targetDVD reference for the setValue method call
 			mb.swap();
 			mb.upCast(ClassName.DataValueDescriptor);
@@ -967,9 +967,9 @@
 		** have to make sure we have set it to the correct
 		** length.
 		*/
-		if (destCTI.variableLength()) 
+		if (getTypeId().variableLength()) 
 		{
-			boolean isNumber = destCTI.isNumericTypeId();
+			boolean isNumber = getTypeId().isNumericTypeId();
 			
 			// to leave the DataValueDescriptor value on the stack, since setWidth is void
 			mb.dup();
@@ -979,8 +979,8 @@
 			 * of VSDV.
 			 */
 			
-			mb.push(isNumber ? castTarget.getPrecision() : castTarget.getMaximumWidth());
-			mb.push(castTarget.getScale());
+			mb.push(isNumber ? getTypeServices().getPrecision() : getTypeServices().getMaximumWidth());
+			mb.push(getTypeServices().getScale());
 			mb.push(!sourceCTI.variableLength() || isNumber);
 			mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.VariableSizeDataValue,
 					"setWidth", "void", 3);
@@ -1024,7 +1024,7 @@
 	 * 
 	 * @param b true to use function conversion rules
 	 */
-	public void setForExternallyGeneratedCASTnode()
+	void setForExternallyGeneratedCASTnode()
 	{
 		externallyGeneratedCastNode = true;
 	}
@@ -1033,20 +1033,11 @@
 	 * 
 	 * @param b true to use function conversion rules
 	 */
-	public void setForDataTypeFunction(boolean b)
+	void setForDataTypeFunction(boolean b)
 	{
 		forDataTypeFunction = b;
 	}
 
-	/** is this a cast node for a data type scalar function?
-	 * @return true if this is  a function, false for regular cast node
-	 *
-	 */
-	public boolean getForDataTypeFunction()
-	{
-		return forDataTypeFunction;
-	}
-        
 	/**
 	 * {@inheritDoc}
 	 * @throws StandardException 
@@ -1056,7 +1047,7 @@
 		if (isSameNodeType(o)) 
 		{
 			CastNode other = (CastNode)o;
-			return castTarget.equals(other.castTarget)
+			return getTypeServices().equals(other.getTypeServices())
 				&& castOperand.isEquivalent(other.castOperand);
 		}
 		return false;

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java?view=diff&rev=552995&r1=552994&r2=552995
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
Tue Jul  3 14:53:36 2007
@@ -132,9 +132,10 @@
 	 * @param node	The CastNode to check.
 	 * @return		True if this CastNode's target type is CHAR,
 	 *              false otherwise.
+	 * @throws StandardException 
 	 */
-	private boolean isCastToChar(CastNode node) {
-		if (node.castTarget.getTypeName().equals(TypeId.CHAR_NAME))
+	private boolean isCastToChar(ValueNode node) throws StandardException {
+		if (node.getTypeServices().getTypeName().equals(TypeId.CHAR_NAME))
 			return true;
 		else
 			return false;
@@ -235,8 +236,8 @@
 		/* If it's not cast to CHAR it isn't a SQL parsed NULL, so
 		 * we can use it.
 		 */
-		if (isCastNode(thenNode) && !isCastToChar((CastNode)thenNode))
-			return ((CastNode)thenNode).castTarget;
+		if (isCastNode(thenNode) && !isCastToChar(thenNode))
+			return thenNode.getTypeServices();
 
 		/* If we get here, we can't use the THEN node type, so we'll
 		 * use the ELSE node type
@@ -247,8 +248,8 @@
 			return elseType;
 		}
 
-		if (isCastNode(elseNode) && !isCastToChar((CastNode)elseNode))
-			return ((CastNode)elseNode).castTarget;
+		if (isCastNode(elseNode) && !isCastToChar(elseNode))
+			return elseNode.getTypeServices();
 
 		/* If we get here, it means that we've got a conditional and a
 		 * SQL parsed NULL or two conditionals.



Mime
View raw message