Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 49339 invoked from network); 29 Jun 2007 21:19:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jun 2007 21:19:58 -0000 Received: (qmail 82169 invoked by uid 500); 29 Jun 2007 21:20:01 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 82147 invoked by uid 500); 29 Jun 2007 21:20:01 -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 82136 invoked by uid 99); 29 Jun 2007 21:20:01 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jun 2007 14:20:01 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jun 2007 14:19:57 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 556531A981A; Fri, 29 Jun 2007 14:19:37 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r552038 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: CastNode.java ConditionalNode.java Date: Fri, 29 Jun 2007 21:19:37 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070629211937.556531A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: djd Date: Fri Jun 29 14:19:36 2007 New Revision: 552038 URL: http://svn.apache.org/viewvc?view=rev&rev=552038 Log: DERBY-2775 (cleanup) Change CastNode to store the type in the facility provided by its super-class ValueNode, and not store the type twice. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&rev=552038&r1=552037&r2=552038 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java Fri Jun 29 14:19:36 2007 @@ -69,12 +69,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 @@ -85,7 +84,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 @@ -106,7 +105,7 @@ throws StandardException { this.castOperand = (ValueNode) castOperand; - this.castTarget = (DataTypeDescriptor) castTarget; + setType((DataTypeDescriptor) castTarget); } /** @@ -127,7 +126,7 @@ targetCharType = ((Integer) charType).intValue(); if (charLen < 0) // unknown, figure out later return; - this.castTarget = DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, charLen); + setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, charLen)); } /** @@ -141,8 +140,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 { @@ -197,7 +201,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; @@ -238,7 +242,7 @@ } if (length < 0) length = 1; // same default as in parser - castTarget = DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, length); + setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(targetCharType, length)); } @@ -248,7 +252,7 @@ */ if (castOperand instanceof UntypedNullConstantNode) { - castOperand.setType(castTarget); + castOperand.setType(getTypeServices()); } bindCastNodeOnly(); @@ -280,7 +284,7 @@ /* RESOLVE - to be filled in. */ ValueNode retNode = this; int sourceJDBCTypeId = sourceCTI.getJDBCTypeId(); - int destJDBCTypeId = destCTI.getJDBCTypeId(); + int destJDBCTypeId = getTypeId().getJDBCTypeId(); switch (sourceJDBCTypeId) { @@ -299,7 +303,7 @@ C_NodeTypes.CHAR_CONSTANT_NODE, booleanString, ReuseFactory.getInteger( - castTarget.getMaximumWidth()), + getTypeServices().getMaximumWidth()), getContextManager()); } break; @@ -321,7 +325,7 @@ C_NodeTypes.CHAR_CONSTANT_NODE, castValue, ReuseFactory.getInteger( - castTarget.getMaximumWidth()), + getTypeServices().getMaximumWidth()), getContextManager()); } break; @@ -367,13 +371,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 current schema's //collation type. Collation derivation is already initialized //to correct value by default which is "IMPLICIT" @@ -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); @@ -1022,7 +1022,7 @@ * not touch the collation of this CAST node because it has been already * set correctly by the class that generated this CAST node. */ - public void setForExternallyGeneratedCASTnode() + void setForExternallyGeneratedCASTnode() { externallyGeneratedCastNode = true; } @@ -1031,20 +1031,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 @@ -1054,7 +1045,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/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java?view=diff&rev=552038&r1=552037&r2=552038 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java Fri Jun 29 14:19: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.