📄 valuenodelist.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.ValueNodeList Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.compile;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.sql.compile.TypeCompiler;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.util.JBitSet;import java.util.Vector;/** * A ValueNodeList represents a list of ValueNodes within a specific predicate * (eg, IN list, NOT IN list or BETWEEN) in a DML statement. * It extends QueryTreeNodeVector. * * @author Jerry Brenner */public class ValueNodeList extends QueryTreeNodeVector{ /** * Prints the sub-nodes of this object. See QueryTreeNode.java for * how tree printing is supposed to work. * * @param depth The depth of this node in the tree * * @return Nothing */ public void printSubNodes(int depth) { if (SanityManager.DEBUG) { super.printSubNodes(depth); for (int index = 0; index < size(); index++) { ValueNode valueNode; valueNode = (ValueNode) elementAt(index); valueNode.treePrint(depth + 1); } } } /** * Set the clause that this node appears in. * * @param clause The clause that this node appears in. * * @return Nothing. */ public void setClause(int clause) { int size = size(); for (int index = 0; index < size; index++) { ValueNode valueNode; valueNode = (ValueNode) elementAt(index); valueNode.setClause(clause); } } /** * Add a ValueNode to the list. * * @param valueNode A ValueNode to add to the list * * @return Nothing * * @exception StandardException Thrown on error */ public void addValueNode(ValueNode valueNode) throws StandardException { addElement(valueNode); } /** * Bind this expression. This means binding the sub-expressions, * as well as figuring out what the return type is for this expression. * * @param fromList The FROM list for the query this * expression is in, for binding columns. * @param subqueryList The subquery list being built as we find SubqueryNodes * @param aggregateVector The aggregate vector being built as we find AggregateNodes * * @return Nothing * * @exception StandardException Thrown on error */ public void bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException { int size = size(); for (int index = 0; index < size; index++) { ValueNode vn = (ValueNode) elementAt(index); vn = vn.bindExpression(fromList, subqueryList, aggregateVector); setElementAt(vn, index); } } /** * Generate a SQL->Java->SQL conversion tree any node in the list * which is not a system built-in type. * This is useful when doing comparisons, built-in functions, etc. on * java types which have a direct mapping to system built-in types. * * @return Nothing. * * @exception StandardException Thrown on error */ public void genSQLJavaSQLTrees() throws StandardException { int size = size(); for (int index = 0; index < size; index++) { ValueNode valueNode = (ValueNode) elementAt(index); if (! valueNode.getTypeId().systemBuiltIn()) { setElementAt(valueNode.genSQLJavaSQLTree(), index); } } } /** * Get the dominant DataTypeServices from the elements in the list. * * @return DataTypeServices The dominant DataTypeServices. * * @exception StandardException Thrown on error */ public DataTypeDescriptor getDominantTypeServices() throws StandardException { DataTypeDescriptor dominantDTS = null; for (int index = 0; index < size(); index++) { ValueNode valueNode; valueNode = (ValueNode) elementAt(index); if (valueNode.isParameterNode()) continue; DataTypeDescriptor valueNodeDTS = valueNode.getTypeServices(); if (dominantDTS == null) { dominantDTS = valueNodeDTS; } else { dominantDTS = dominantDTS.getDominantType(valueNodeDTS, getClassFactory()); } } return dominantDTS; } /** * Get the first non-null DataTypeServices from the elements in the list. * * @return DataTypeServices The first non-null DataTypeServices. * * @exception StandardException Thrown on error */ public DataTypeDescriptor getTypeServices() throws StandardException { DataTypeDescriptor firstDTS = null; int size = size(); for (int index = 0; index < size; index++) { ValueNode valueNode; valueNode = (ValueNode) elementAt(index); DataTypeDescriptor valueNodeDTS = valueNode.getTypeServices(); if ((firstDTS == null) && (valueNodeDTS != null)) { firstDTS = valueNodeDTS; break; } } return firstDTS; } /** * Return whether or not all of the entries in the list have the same * type precendence as the specified value. * * @param precedence The specified precedence. * * @return Whether or not all of the entries in the list have the same * type precendence as the specified value. */ boolean allSamePrecendence(int precedence) { boolean allSame = true; int size = size(); for (int index = 0; index < size; index++) { ValueNode valueNode; valueNode = (ValueNode) elementAt(index); DataTypeDescriptor valueNodeDTS = valueNode.getTypeServices(); if (valueNodeDTS == null) { return false; } if (precedence != valueNodeDTS.getTypeId().typePrecedence()) { return false; } } return allSame; } /** * Make sure that passed ValueNode's type is compatible with the non-parameter elements in the ValueNodeList. * * @param leftOperand Check for compatibility against this parameter's type * */ public void compatible(ValueNode leftOperand) throws StandardException { int size = size(); TypeId leftType; ValueNode valueNode; TypeCompiler leftTC; leftType = leftOperand.getTypeId(); leftTC = leftOperand.getTypeCompiler(); for (int index = 0; index < size; index++) { valueNode = (ValueNode) elementAt(index); if (valueNode.isParameterNode()) continue; /* ** Are the types compatible to each other? If not, throw an exception. */ if (! leftTC.compatible(valueNode.getTypeId())) { throw StandardException.newException(SQLState.LANG_DB2_COALESCE_DATATYPE_MISMATCH, leftType.getSQLTypeName(), valueNode.getTypeId().getSQLTypeName() ); } } } /** * Determine whether or not the leftOperand is comparable() with all of * the elements in the list. Throw an exception if any of them are not * comparable. * * @param leftOperand The left side of the expression * * @return Nothing. * * @exception StandardException Thrown on error */ public void comparable(ValueNode leftOperand) throws StandardException { int size = size(); TypeId leftType; ValueNode valueNode; TypeCompiler leftTC; leftType = leftOperand.getTypeId(); leftTC = leftOperand.getTypeCompiler(); for (int index = 0; index < size; index++) { valueNode = (ValueNode) elementAt(index); /* ** Can the types be compared to each other? If not, throw an ** exception. */ if (! leftTC.comparable(valueNode.getTypeId(), false,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -