📄 resultcolumnlist.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.ResultColumnList 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.context.ContextManager;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.services.compiler.LocalField;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.loader.ClassFactory;import org.apache.derby.iapi.services.io.Storable;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.NodeFactory;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.services.classfile.VMOpcode;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ResultColumnDescriptor;import org.apache.derby.iapi.sql.Row;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.ExecIndexRow;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.catalog.types.DefaultInfoImpl;import java.lang.reflect.Modifier;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.services.classfile.VMOpcode;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Types;import java.util.Hashtable;import java.util.Vector;/** * A ResultColumnList is the target list of a SELECT, INSERT, or UPDATE. * * @see ResultColumn */public class ResultColumnList extends QueryTreeNodeVector{ /* Is this the ResultColumnList for an index row? */ protected boolean indexRow; protected long conglomerateId; int orderBySelect = 0; // the number of result columns pulled up // from ORDERBY list /* ** Is this ResultColumnList for a FromBaseTable for an index ** that is to be updated? */ protected boolean forUpdate; // Is a count mismatch allowed - see set/get methods for details. private boolean countMismatchAllowed; // Number of RCs in this RCL at "init" time, before additional // ones were added internally. private int initialListSize = 0; public ResultColumnList() { } /** * Add a ResultColumn (at this point, ResultColumn or * AllResultColumn) to the list * * @param resultColumn The ResultColumn to add to the list * * @return Nothing */ public void addResultColumn(ResultColumn resultColumn) { /* Vectors are 0-based, ResultColumns are 1-based */ resultColumn.setVirtualColumnId(size() + 1); addElement(resultColumn); } /** * Append a given ResultColumnList to this one, resetting the virtual * column ids in the appended portion. * * @param resultColumns The ResultColumnList to be appended * @param destructiveCopy Whether or not this is a descructive copy * from resultColumns * * @return Nothing */ public void appendResultColumns(ResultColumnList resultColumns, boolean destructiveCopy) { int oldSize = size(); int newID = oldSize + 1; /* ** Set the virtual column ids in the list being appended. ** Vectors are zero-based, and virtual column ids are one-based, ** so the new virtual column ids start at the original size ** of this list, plus one. */ int otherSize = resultColumns.size(); for (int index = 0; index < otherSize; index++) { /* ResultColumns are 1-based */ ((ResultColumn) resultColumns.elementAt(index)).setVirtualColumnId(newID); newID++; } if (destructiveCopy) { destructiveAppend(resultColumns); } else { nondestructiveAppend(resultColumns); } } /** * Get a ResultColumn from a column position (1-based) in the list * * @param position The ResultColumn to get from the list (1-based) * * @return the column at that position. */ public ResultColumn getResultColumn(int position) { /* ** First see if it falls in position x. If not, ** search the whole shebang */ if (position <= size()) { // this wraps the cast needed, // and the 0-based nature of the Vectors. ResultColumn rc = (ResultColumn)elementAt(position-1); if (rc.getColumnPosition() == position) { return rc; } } /* ** Check each column */ int size = size(); for (int index = 0; index < size; index++) { ResultColumn rc = (ResultColumn) elementAt(index); if (rc.getColumnPosition() == position) { return rc; } } return null; } /** * Get a ResultColumn from a column position (1-based) in the list, * null if out of range (for order by). * * @param position The ResultColumn to get from the list (1-based) * * @return the column at that position, null if out of range */ public ResultColumn getOrderByColumn(int position) { // this wraps the cast needed, and the 0-based nature of the Vectors. if (position == 0) return null; return getResultColumn(position); } /** * Get a ResultColumn that matches the specified columnName and * mark the ResultColumn as being referenced. * * @param columnName The ResultColumn to get from the list * * @return the column that matches that name. */ public ResultColumn getResultColumn(String columnName) { int size = size(); for (int index = 0; index < size; index++) { ResultColumn resultColumn = (ResultColumn) elementAt(index); if (columnName.equals( resultColumn.getName()) ) { /* Mark ResultColumn as referenced and return it */ resultColumn.setReferenced(); return resultColumn; } } return null; } /** * Get a ResultColumn that matches the specified columnName and * mark the ResultColumn as being referenced. * * @param columnsTableName Qualifying name for the column * @param columnName The ResultColumn to get from the list * * @return the column that matches that name. */ public ResultColumn getResultColumn(String columnsTableName, String columnName) { int size = size(); for (int index = 0; index < size; index++) { ResultColumn resultColumn = (ResultColumn) elementAt(index); /* If the column's table name is non-null, then we have found a match * only if the RC's table name is non-null and the same as the * the CR's table name. */ if (columnsTableName != null) { if (resultColumn.getTableName() == null) { continue; } if (! columnsTableName.equals(resultColumn.getTableName())) { continue; } } if (columnName.equals( resultColumn.getName()) ) { /* Mark ResultColumn as referenced and return it */ resultColumn.setReferenced(); return resultColumn; } } return null; } /** * Get a ResultColumn that matches the specified columnName and * mark the ResultColumn as being referenced. * NOTE - this flavor enforces no ambiguity (at most 1 match) * Only FromSubquery needs to call this flavor since * it can have ambiguous references in its own list. * * @param cr The ColumnReference to resolve * @param exposedTableName Exposed table name for FromTable * * @return the column that matches that name. * * @exception StandardException Thrown on error */ public ResultColumn getAtMostOneResultColumn( ColumnReference cr, String exposedTableName) throws StandardException { int size = size(); ResultColumn retRC = null; String columnName = cr.getColumnName(); for (int index = 0; index < size; index++) { ResultColumn resultColumn = (ResultColumn) elementAt(index); if (columnName.equals( resultColumn.getName()) ) { /* We should get at most 1 match */ if (retRC != null) { throw StandardException.newException(SQLState.LANG_AMBIGUOUS_COLUMN_NAME_IN_TABLE, columnName, exposedTableName); } /* Mark ResultColumn as referenced and return it */ resultColumn.setReferenced(); retRC = resultColumn; } } return retRC; } /** * For order by, get a ResultColumn that matches the specified * columnName and ensure that there is only one match. * * @param columnName The ResultColumn to get from the list * @param tableName The table name on the OrderByColumn, if any * @param tableNumber The tableNumber corresponding to the FromTable with the * exposed name of tableName, if tableName != null. * * @return the column that matches that name. * @exception StandardException thrown on duplicate */ public ResultColumn getOrderByColumn(String columnName, TableName tableName, int tableNumber) throws StandardException { int size = size(); ResultColumn retVal = null, resultColumn; for (int index = 0; index < size; index++) { resultColumn = (ResultColumn) elementAt(index); /* The order by column is qualified, then it is okay to consider * this RC if: * o The RC is qualified and the qualifiers on the order by column * and the RC are equal(). * o The RC is not qualified, but its expression is a ColumnReference * from the same table (as determined by the tableNumbers). */ if (tableName != null) { ValueNode rcExpr = resultColumn.getExpression(); if (! (rcExpr instanceof ColumnReference)) continue; ColumnReference cr = (ColumnReference) rcExpr; if( (! tableName.equals( cr.getTableNameNode())) && tableNumber != cr.getTableNumber()) continue; } /* We finally got past the qualifiers, now see if the column * names are equal. */ if (columnName.equals( resultColumn.getName()) ) { if (retVal == null) { retVal = resultColumn; } else if (index < size - orderBySelect) { throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_FOR_ORDER_BY, columnName); } else {// remove the column due to pullup of orderby item removeElement(resultColumn); decOrderBySelect(); break; } } } return retVal; } /** * For order by, get a ResultColumn that matches the specified * columnName and ensure that there is only one match before the bind process. * * @param columnName The ResultColumn to get from the list * @param tableName The table name on the OrderByColumn, if any * * @return the column that matches that name. * @exception StandardException thrown on duplicate */ public ResultColumn getOrderByColumn(String columnName, TableName tableName) throws StandardException { int size = size(); ResultColumn retVal = null, resultColumn; for (int index = 0; index < size; index++) { resultColumn = (ResultColumn) elementAt(index); // We may be checking on "ORDER BY T.A" against "SELECT *". // exposedName will not be null and "*" will not have an expression // or tablename. // We may be checking on "ORDER BY T.A" against "SELECT T.B, T.A". if (tableName != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -