ColumnReference.java

Index Score
org.apache.derby.impl.sql.compile
Apache Derby

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
COMMENTSComment lines
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
EXEC_COMMENTSComments in executable code
SIZESize of the file in bytes
LINESNumber of lines in the source file
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0034JAVA0034 Missing braces in if statement
RETURNSNumber of return points from functions
CYCLOMATICCyclomatic complexity
FUNCTIONSNumber of function declarations
LOCLines of code
BLOCK_COMMENTNumber of block comment lines
INTERFACE_COMPLEXITYInterface complexity
BLOCKSNumber of blocks
EXITSProcedure exits
ELOCEffective lines of code
JAVA0145JAVA0145 Tab character used in source file
JAVA0177JAVA0177 Variable declaration missing initializer
COMPARISONSNumber of comparison operators
OPERATORSNumber of operators
JAVA0075JAVA0075 Method parameter hides field
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
OPERANDSNumber of operands
JAVA0096JAVA0096 Field in nested class hides outer field
WHITESPACENumber of whitespace lines
PARAMSNumber of formal parameter declarations
LINE_COMMENTNumber of line comments
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0119JAVA0119 Control variable changed within body of for loop
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0174JAVA0174 Assigned local variable never used
JAVA0106JAVA0106 Unnecessary import from current package
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0043JAVA0043 Inner class does not use outer class
UNIQUE_OPERATORSNumber of unique operators
JAVA0123JAVA0123 Use all three components of for loop
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
/* Derby - Class org.apache.derby.impl.sql.compile.ColumnReference Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.sql.compile.C_NodeTypes; import org.apache.derby.iapi.sql.compile.NodeFactory; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; import org.apache.derby.iapi.services.compiler.MethodBuilder; import org.apache.derby.iapi.services.sanity.SanityManager; import org.apache.derby.iapi.store.access.Qualifier; import org.apache.derby.iapi.util.JBitSet; import java.util.Vector; /** * A ColumnReference represents a column in the query tree. The parser generates a * ColumnReference for each column reference. A column refercence could be a column in * a base table, a column in a view (which could expand into a complex * expression), or a column in a subquery in the FROM clause. * */ public class ColumnReference extends ValueNode { String columnName; /* ** This is the user-specified table name. It will be null if the ** user specifies a column without a table name. Leave it null even ** when the column is bound as it is only used in binding. */ TableName tableName; /* The table this column reference is bound to */ private int tableNumber; /* The column number in the underlying base table */ private int columnNumber; /* This is where the value for this column reference will be coming from */ private ResultColumn source; /* For unRemapping */ ResultColumn origSource; private String origName; int origTableNumber = -1; int origColumnNumber = -1; /* Reuse generated code where possible */ //Expression genResult; private boolean replacesAggregate; private int nestingLevel = -1; private int sourceLevel = -1; /* Whether or not this column reference been scoped for the sake of predicate pushdown. */ private boolean scoped; /* List of saved remap data if this ColumnReference is scoped and has been remapped multiple times. */ private java.util.ArrayList remaps; /** * Initializer. * This one is called by the parser where we could * be dealing with delimited identifiers. * * @param columnName The name of the column being referenced * @param tableName The qualification for the column * @param tokBeginOffset begin position of token for the column name * identifier from parser. * @param tokEndOffset end position of token for the column name * identifier from parser. */ public void init(Object columnName, Object tableName, Object tokBeginOffset, Object tokEndOffset ) { this.columnName = (String) columnName; this.tableName = (TableName) tableName; this.setBeginOffset(((Integer) tokBeginOffset).intValue()); this.setEndOffset(((Integer) tokEndOffset).intValue()); tableNumber = -1; remaps = null; } /** * Initializer. * * @param columnName The name of the column being referenced * @param tableName The qualification for the column */ public void init(Object columnName, Object tableName) { this.columnName = (String) columnName; this.tableName = (TableName) tableName; tableNumber = -1; remaps = null; } /** * Convert this object to a String. See comments in QueryTreeNode.java * for how this should be done for tree printing. * * @return This object as a String */ public String toString() { if (SanityManager.DEBUG) { return "columnName: " + columnName + "\n" + "tableNumber: " + tableNumber + "\n" + "columnNumber: " + columnNumber + "\n" + "replacesAggregate: " + replacesAggregate + "\n" + "tableName: " + ( ( tableName != null) ? tableName.toString() : "null") + "\n" + "nestingLevel: " + nestingLevel + "\n" + "sourceLevel: " + sourceLevel + "\n" + super.toString(); } else { return ""; } } /** * 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 */ public void printSubNodes(int depth) { if (SanityManager.DEBUG) { super.printSubNodes(depth); if (source != null) { printLabel(depth, "source: "); source.treePrint(depth + 1); } } } /** * Return whether or not this CR is correlated. * * @return Whether or not this CR is correlated. */ boolean getCorrelated() { if (SanityManager.DEBUG) { SanityManager.ASSERT(nestingLevel != -1, "nestingLevel on "+columnName+" is not expected to be -1"); SanityManager.ASSERT(sourceLevel != -1, "sourceLevel on "+columnName+" is not expected to be -1"); } return sourceLevel != nestingLevel; } /** * Set the nesting level for this CR. (The nesting level * at which the CR appears.) * * @param nestingLevel The Nesting level at which the CR appears. */ void setNestingLevel(int nestingLevel) { if (SanityManager.DEBUG) { SanityManager.ASSERT(nestingLevel != -1, "nestingLevel is not expected to be -1"); } this.nestingLevel = nestingLevel; } /** * Get the nesting level for this CR. * * @return The nesting level for this CR. */ private int getNestingLevel() { return nestingLevel; } /** * Set the source level for this CR. (The nesting level * of the source of the CR.) * * @param sourceLevel The Nesting level of the source of the CR. */ void setSourceLevel(int sourceLevel) { if (SanityManager.DEBUG) { SanityManager.ASSERT(sourceLevel != -1, "sourceLevel is not expected to be -1"); } this.sourceLevel = sourceLevel; } /** * Get the source level for this CR. * * @return The source level for this CR. */ int getSourceLevel() { return sourceLevel; } /** * Mark this node as being generated to replace an aggregate. * (Useful for replacing aggregates in the HAVING clause with * column references to the matching aggregate in the * user's SELECT. */ public void markGeneratedToReplaceAggregate() { replacesAggregate = true; } /** * Determine whether or not this node was generated to * replace an aggregate in the user's SELECT. * * @return boolean Whether or not this node was generated to replace * an aggregate in the user's SELECT. */ public boolean getGeneratedToReplaceAggregate() { return replacesAggregate; } /** * Return a clone of this node. * * @return ValueNode A clone of this node. * * @exception StandardException Thrown on error */ public ValueNode getClone() throws StandardException { ColumnReference newCR = (ColumnReference) getNodeFactory().getNode( C_NodeTypes.COLUMN_REFERENCE, columnName, tableName, getContextManager()); newCR.copyFields(this); return newCR; } /** * Copy all of the "appropriate fields" for a shallow copy. * * @param oldCR The ColumnReference to copy from. * * @exception StandardException Thrown on error */ public void copyFields(ColumnReference oldCR) throws StandardException { super.copyFields(oldCR); tableName = oldCR.getTableNameNode(); tableNumber = oldCR.getTableNumber(); columnNumber = oldCR.getColumnNumber(); source = oldCR.getSource(); nestingLevel = oldCR.getNestingLevel(); sourceLevel = oldCR.getSourceLevel(); replacesAggregate = oldCR.getGeneratedToReplaceAggregate(); scoped = oldCR.isScoped(); } /** * Bind this expression. This means binding the sub-expressions, * as well as figuring out what the return type is for this expression. * * NOTE: We must explicitly check for a null FromList here, column reference * without a FROM list, as the grammar allows the following: * insert into t1 values(c1) * * @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 The new top of the expression tree. * * @exception StandardException Thrown on error */ public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException { ResultColumn matchingRC; if (SanityManager.DEBUG) { SanityManager.ASSERT(fromList != null, "fromList is expected to be non-null"); } if (fromList.size() == 0) { throw StandardException.newException(SQLState.LANG_ILLEGAL_COLUMN_REFERENCE, columnName); } matchingRC = fromList.bindColumnReference(this); /* Error if no match found in fromList */ if (matchingRC == null) { throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND, getSQLColumnName()); } /* Set the columnNumber from the base table. * Useful for optimizer and generation. */ columnNumber = matchingRC.getColumnPosition(); return this; } /** * Get the column name for purposes of error * messages or debugging. This returns the column * name as used in the SQL statement. Thus if it was qualified * with a table, alias name that will be included. * * @return The column name in the form [[schema.]table.]column */ public String getSQLColumnName() { if (tableName == null) return columnName; return tableName.toString() + "." + columnName; } /** * Get the name of this column * * @return The name of this column */ public String getColumnName() { return columnName; } /** * Get the table number for this ColumnReference. * * @return int The table number for this ColumnReference */ public int getTableNumber() { return tableNumber; } /** * Set this ColumnReference to refer to the given table number. * * @param tableNumber The table number this ColumnReference will refer to */ public void setTableNumber(int tableNumber) { if (SanityManager.DEBUG) { SanityManager.ASSERT(tableNumber != -1, "tableNumber not expected to be -1"); } this.tableNumber = tableNumber; } /** * Get the user-supplied table name of this column. This will be null * if the user did not supply a name (for example, select a from t). * The method will return B for this example, select b.a from t as b * The method will return T for this example, select t.a from t * * @return The user-supplied name of this column. Null if no user- * supplied name. */ public String getTableName() { return ( ( tableName != null) ? tableName.getTableName() : null ); } /** * Get the name of the underlying(base) table this column comes from, if any. * Following example queries will all return T * select a from t * select b.a from t as b * select t.a from t * * @return The name of the base table that this column comes from. * Null if not a ColumnReference. */ public String getSourceTableName() { return ((source != null) ? source.getTableName() : null); } /** * Get the name of the schema for the Column's base table, if any. * Following example queries will all return APP (assuming user is in schema APP) * select t.a from t * select b.a from t as b * select app.t.a from t * * @return The name of the schema for Column's base table. If the column * is not in a schema (i.e. is a derived column), it returns NULL. */ public String getSourceSchemaName() throws StandardException { return ((source != null) ? source.getSchemaName() : null); } /** * Is the column wirtable by the cursor or not. (ie, is it in the list of FOR UPDATE columns list) * * @return TRUE, if the column is a base column of a table and is * writable by cursor. */ public boolean updatableByCursor() { return ((source != null) ? source.updatableByCursor() : false); } /** Return the table name as the node it is. @return the column's table name. */ public TableName getTableNameNode() { return tableName; } public void setTableNameNode(TableName tableName) { this.tableName = tableName; } /** * Get the column number for this ColumnReference. * * @return int The column number for this ColumnReference */ public int getColumnNumber() { return columnNumber; } /** * Set the column number for this ColumnReference. This is * used when scoping predicates for pushdown. * * @param colNum The new column number. */ public void setColumnNumber(int colNum) { this.columnNumber = colNum; } /** * Get the source this columnReference * * @return The source of this columnReference */ public ResultColumn getSource() { return source; } /** * Set the source this columnReference * * @param source The source of this columnReference */ public void setSource(ResultColumn source) { this.source = source; } /** * Do the 1st step in putting an expression into conjunctive normal * form. This step ensures that the top level of the expression is * a chain of AndNodes. * * @return The modified expression * * @exception StandardException Thrown on error */ public ValueNode putAndsOnTop() throws StandardException { BinaryComparisonOperatorNode equalsNode; BooleanConstantNode trueNode; NodeFactory nodeFactory = getNodeFactory(); ValueNode andNode; trueNode = (BooleanConstantNode) nodeFactory.getNode( C_NodeTypes.BOOLEAN_CONSTANT_NODE, Boolean.TRUE, getContextManager()); equalsNode = (BinaryComparisonOperatorNode) nodeFactory.getNode( C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE, this, trueNode, getContextManager()); /* Set type info for the operator node */ equalsNode.bindComparisonOperator(); andNode = (ValueNode) nodeFactory.getNode( C_NodeTypes.AND_NODE, equalsNode, trueNode, getContextManager()); ((AndNode) andNode).postBindFixup(); return andNode; } /** * Categorize this predicate. Initially, this means * building a bit map of the referenced tables for each predicate. * If the source of this ColumnReference (at the next underlying level) * is not a ColumnReference or a VirtualColumnNode then this predicate * will not be pushed down. * * For example, in: * select * from (select 1 from s) a (x) where x = 1 * we will not push down x = 1. * NOTE: It would be easy to handle the case of a constant, but if the * inner SELECT returns an arbitrary expression, then we would have to copy * that tree into the pushed predicate, and that tree could contain * subqueries and method calls. * * Also, don't allow a predicate to be pushed down if it contains a * ColumnReference that replaces an aggregate. This can happen if * the aggregate is in the HAVING clause. In this case, we would be * pushing the predicate into the SelectNode that evaluates the aggregate, * which doesn't make sense, since the having clause is supposed to be * applied to the result of the SelectNode. * * RESOLVE - revisit this issue once we have views. * * @param referencedTabs JBitSet with bit map of referenced FromTables * @param simplePredsOnly Whether or not to consider method * calls, field references and conditional nodes * when building bit map * * @return boolean Whether or not source.expression is a ColumnReference * or a VirtualColumnNode or a ConstantNode. */ public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) { if (SanityManager.DEBUG) SanityManager.ASSERT(tableNumber >= 0, "tableNumber is expected to be non-negative"); referencedTabs.set(tableNumber); return ( ! replacesAggregate ) && ( ! source.isWindowFunction() ) && ( (source.getExpression() instanceof ColumnReference) || (source.getExpression() instanceof VirtualColumnNode) || (source.getExpression() instanceof ConstantNode)); } /** * Remap all of the ColumnReferences in this expression tree * to point to the ResultColumn that is 1 level under their * current source ResultColumn. * This is useful for pushing down single table predicates. * * RESOLVE: Once we start pushing join clauses, we will need to walk the * ResultColumn/VirtualColumnNode chain for them to remap the references. */ public void remapColumnReferences() { ValueNode expression = source.getExpression(); if (SanityManager.DEBUG) { // SanityManager.ASSERT(origSource == null, // "Trying to remap ColumnReference twice without unremapping it."); } if ( ! ( (expression instanceof VirtualColumnNode) || (expression instanceof ColumnReference) ) ) { return; } /* Scoped column references are a special case: they can be * remapped several times (once for every ProjectRestrictNode * through which the scoped ColumnReference is pushed before * reaching its target result set) and will be un-remapped * several times, as well (as the scoped predicate is "pulled" * back up the query tree to it's original location). So we * have to keep track of the "orig" info for every remap * operation, not just for the most recent one. */ if (scoped && (origSource != null)) { if (remaps == null) remaps = new java.util.ArrayList(); remaps.add(new RemapInfo( columnNumber, tableNumber, columnName, source)); } else { origSource = source; origName = columnName; origColumnNumber = columnNumber; origTableNumber = tableNumber; } /* Find the matching ResultColumn */ source = getSourceResultColumn(); columnName = source.getName(); columnNumber = source.getColumnPosition(); if (source.getExpression() instanceof ColumnReference) { ColumnReference cr = (ColumnReference) source.getExpression(); tableNumber = cr.getTableNumber(); if (SanityManager.DEBUG) { // if dummy cr generated to replace aggregate, it may not have table number // because underneath can be more than 1 table. if (tableNumber == -1 && ! cr.getGeneratedToReplaceAggregate()) { SanityManager.THROWASSERT( "tableNumber not expected to be -1, origName = " + origName); } } } } public void unRemapColumnReferences() { if (origSource == null) return; if (SanityManager.DEBUG) { // SanityManager.ASSERT(origSource != null, // "Trying to unremap a ColumnReference that was not remapped."); } if ((remaps == null) || (remaps.size() == 0)) { source = origSource; origSource = null; columnName = origName; origName = null; tableNumber = origTableNumber; columnNumber = origColumnNumber; } else { // This CR is multiply-remapped, so undo the most // recent (and only the most recent) remap operation. RemapInfo rI = (RemapInfo)remaps.remove(remaps.size() - 1); source = rI.getSource(); columnName = rI.getColumnName(); tableNumber = rI.getTableNumber(); columnNumber = rI.getColumnNumber(); rI = null; if (remaps.size() == 0) remaps = null; } } /** * Returns true if this ColumnReference has been remapped; false * otherwise. * * @return Whether or not this ColumnReference has been remapped. */ protected boolean hasBeenRemapped() { return (origSource != null); } /* * Get the ResultColumn that the source points to. This is useful for * getting what the source will be after this ColumnReference is remapped. */ public ResultColumn getSourceResultColumn() { /* RESOLVE - If expression is a ColumnReference, then we are hitting * the top of a query block (derived table or view.) * In order to be able to push the expression down into the next * query block, it looks like we should reset the contents of the * current ColumnReference to be the same as expression. (This probably * only means names and tableNumber.) We would then "rebind" the top * level predicate somewhere up the call stack and see if we could push * the predicate through. */ return source.getExpression().getSourceResultColumn(); } /** * Remap all ColumnReferences in this tree to be clones of the * underlying expression. * * @return ValueNode The remapped expression tree. * * @exception StandardException Thrown on error */ public ValueNode remapColumnReferencesToExpressions() throws StandardException { ResultColumn rc; ResultColumn sourceRC = source; /* Nothing to do if we are not pointing to a redundant RC */ if (! source.isRedundant()) { return this; } /* Find the last redundant RC in the chain. We * want to clone its expression. */ for (rc = source; rc != null && rc.isRedundant(); ) { /* Find the matching ResultColumn */ ResultColumn nextRC = rc.getExpression().getSourceResultColumn(); if (nextRC != null && nextRC.isRedundant()) { sourceRC = nextRC; } rc = nextRC; } if (SanityManager.DEBUG) { if (sourceRC == null) { SanityManager.THROWASSERT( "sourceRC is expected to be non-null for " + columnName); } if ( ! sourceRC.isRedundant()) { SanityManager.THROWASSERT( "sourceRC is expected to be redundant for " + columnName); } } /* If last expression is a VCN, then we can't clone it. * Instead, we just reset our source to point to the * source of the VCN, those chopping out the layers. * Otherwise, we return a clone of the underlying expression. */ if (sourceRC.getExpression() instanceof VirtualColumnNode) { VirtualColumnNode vcn = (VirtualColumnNode) (sourceRC.getExpression()); ResultSetNode rsn = vcn.getSourceResultSet(); if (rsn instanceof FromTable) { FromTable ft = (FromTable)rsn; tableNumber = ft.getTableNumber(); if (SanityManager.DEBUG) { SanityManager.ASSERT(tableNumber != -1, "tableNumber not expected to be -1"); } /* It's not enough to just set the table number. Depending * on the original query specified and on whether or not * subquery flattening has occurred, it's possible that * the expression to which we're remapping has a different * RCL ordering than the one to which we were mapped before * we got here. In that case we also need to update the * columnNumber to point to the correct column in "ft". * See DERBY-2526 for details. */ ResultColumn ftRC = ft.getResultColumns().getResultColumn(columnName); if (SanityManager.DEBUG) { SanityManager.ASSERT(ftRC != null, "Failed to find column '" + columnName + "' in the " + "RCL for '" + ft.getTableName() + "'."); } /* Use the virtual column id if the ResultColumn's expression * is a virtual column (DERBY-3023). */ columnNumber = (ftRC.getExpression() instanceof VirtualColumnNode) ? ftRC.getVirtualColumnId() : ftRC.getColumnPosition(); } else { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("rsn expected to be a FromTable, but is a " + rsn.getClass().getName()); } } source = sourceRC.getExpression().getSourceResultColumn(); return this; } else { return sourceRC.getExpression().getClone(); } } /** * Update the table map to reflect the source * of this CR. * * @param refs The table map. */ void getTablesReferenced(JBitSet refs) { if (refs.size() < tableNumber) refs.grow(tableNumber); if (tableNumber != -1) // it may not be set if replacesAggregate is true refs.set(tableNumber); } /** * Return whether or not this expression tree is cloneable. * * @return boolean Whether or not this expression tree is cloneable. */ public boolean isCloneable() { return true; } /** @see ValueNode#constantExpression */ public boolean constantExpression(PredicateList whereClause) { return whereClause.constantColumn(this); } /** * ColumnReference's are to the current row in the system. * This lets us generate * a faster get that simply returns the column from the * current row, rather than getting the value out and * returning that, only to have the caller (in the situations * needed) stuffing it back into a new column holder object. * We will assume the general generate() path is for getting * the value out, and use generateColumn() when we want to * keep the column wrapped. * * @exception StandardException Thrown on error */ public void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException { int sourceResultSetNumber = source.getResultSetNumber(); //PUSHCOMPILE /* Reuse generated code, where possible */ /* ** If the source is redundant, return the generation of its source. ** Most redundant nodes will be flattened out by this point, but ** in at least one case (elimination of redundant ProjectRestricts ** during generation) we don't do this. */ if (source.isRedundant()) { source.generateExpression(acb, mb); return; } if (SanityManager.DEBUG) { if (sourceResultSetNumber < 0) { SanityManager.THROWASSERT("sourceResultSetNumber expected to be >= 0 for " + getTableName() + "." + getColumnName()); } } /* The ColumnReference is from an immediately underlying ResultSet. * The Row for that ResultSet is Activation.row[sourceResultSetNumber], * where sourceResultSetNumber is the resultSetNumber for that ResultSet. * * The generated java is the expression: * (<interface>) this.row[sourceResultSetNumber].getColumn(#columnId); * * where <interface> is the appropriate Datatype protocol interface * for the type of the column. */ acb.pushColumnReference(mb, sourceResultSetNumber, source.getVirtualColumnId()); mb.cast(getTypeCompiler().interfaceName()); /* Remember generated code for possible resuse */ } /** * Get the user-supplied schema name of this column. This will be null * if the user did not supply a name (for example, select t.a from t). * Another example for null return value (for example, select b.a from t as b). * But for following query select app.t.a from t, this will return APP * Code generation of aggregate functions relies on this method * * @return The user-supplied schema name of this column. Null if no user- * supplied name. */ public String getSchemaName() { return ( ( tableName != null) ? tableName.getSchemaName() : null ); } /** * Return the variant type for the underlying expression. * The variant type can be: * VARIANT - variant within a scan * (method calls and non-static field access) * SCAN_INVARIANT - invariant within a scan * (column references from outer tables) * QUERY_INVARIANT - invariant within the life of a query * (constant expressions) * * @return The variant type for the underlying expression. */ protected int getOrderableVariantType() { // ColumnReferences are invariant for the life of the scan return Qualifier.SCAN_INVARIANT; } /** * Return whether or not the source of this ColumnReference is itself a ColumnReference. * * @return Whether or not the source of this ColumnReference is itself a ColumnReference. */ boolean pointsToColumnReference() { return (source.getExpression() instanceof ColumnReference); } /** * The type of a ColumnReference is the type of its * source unless the source is null then it is * the type that has been set on this node. */ public DataTypeDescriptor getTypeServices() { if (source == null) return super.getTypeServices(); return source.getTypeServices(); } /** * Find the source result set for this ColumnReference and * return it. Also, when the source result set is found, * return the position (within the source result set's RCL) * of the column referenced by this ColumnReference. The * position is returned vai the colNum parameter. * * @param colNum Place to store the position of the column * to which this ColumnReference points (position is w.r.t * the source result set). * @return The source result set for this ColumnReference; * null if there is no source result set. */ protected ResultSetNode getSourceResultSet(int [] colNum) throws StandardException { if (source == null) { /* this can happen if column reference is pointing to a column * that is not from a base table. For example, if we have a * VALUES clause like * * (values (1, 2), (3, 4)) V1 (i, j) * * and then a column reference to VI.i, the column reference * won't have a source. */ return null; } ValueNode rcExpr = null; ResultColumn rc = getSource(); // Walk the ResultColumn->ColumnReference chain until we // find a ResultColumn whose expression is a VirtualColumnNode. rcExpr = rc.getExpression(); colNum[0] = getColumnNumber(); /* We have to make sure we enter this loop if rc is redundant, * so that we can navigate down to the actual source result * set (DERBY-1777). If rc *is* redundant, then rcExpr is not * guaranteed to be a ColumnReference, so we have to check * for that case inside the loop. */ while ((rcExpr != null) && (rc.isRedundant() || (rcExpr instanceof ColumnReference))) { if (rcExpr instanceof ColumnReference) { colNum[0] = ((ColumnReference)rcExpr).getColumnNumber(); rc = ((ColumnReference)rcExpr).getSource(); } /* If "rc" is redundant then that means it points to another * ResultColumn that in turn points to the source expression. * This can happen in cases where "rc" points to a subquery * that has been flattened into the query above it (flattening * of subqueries occurs during preprocessing). In that case * we want to skip over the redundant rc and find the * ResultColumn that actually holds the source expression. */ while (rc.isRedundant()) { rcExpr = rc.getExpression(); if (rcExpr instanceof VirtualColumnNode) rc = rcExpr.getSourceResultColumn(); else if (rcExpr instanceof ColumnReference) { colNum[0] = ((ColumnReference)rcExpr).getColumnNumber(); rc = ((ColumnReference)rcExpr).getSource(); } else { /* If rc isn't pointing to a VirtualColumnNode nor * to a ColumnReference, then it's not pointing to * a result set. It could, for example, be pointing * to a constant node or to the result of an aggregate * or function. Break out of both loops and return * null since there is no source result set. */ rcExpr = null; break; } } rcExpr = rc.getExpression(); } // If we found a VirtualColumnNode, return the VirtualColumnNode's // sourceResultSet. The column within that sourceResultSet that // is referenced by this ColumnReference is also returned, via // the colNum parameter, and was set above. if ((rcExpr != null) && (rcExpr instanceof VirtualColumnNode)) return ((VirtualColumnNode)rcExpr).getSourceResultSet(); // If we get here then the ColumnReference doesn't reference // a result set, so return null. colNum[0] = -1; return null; } protected boolean isEquivalent(ValueNode o) throws StandardException { if (!isSameNodeType(o)) { return false; } ColumnReference other = (ColumnReference)o; return (tableNumber == other.tableNumber && columnName.equals(other.getColumnName())); } /** * Mark this column reference as "scoped", which means that it * was created (as a clone of another ColumnReference) to serve * as the left or right operand of a scoped predicate. */ protected void markAsScoped() { scoped = true; } /** * Return whether or not this ColumnReference is scoped. */ protected boolean isScoped() { return scoped; } /** * Helper class to keep track of remap data when a ColumnReference * is remapped multiple times. This allows the CR to be UN- * remapped multiple times, as well. */ private class RemapInfo { int colNum; int tableNum; String colName; ResultColumn source; RemapInfo(int cNum, int tNum, String cName, ResultColumn rc) { colNum = cNum; tableNum = tNum; colName = cName; source = rc; } int getColumnNumber() { return colNum; } int getTableNumber() { return tableNum; } String getColumnName() { return colName; } ResultColumn getSource() { return source; } void setColNumber(int cNum) { colNum = cNum; } void setTableNumber(int tNum) { tableNum = tNum; } void setColName(String cName) { colName = cName; } void setSource(ResultColumn rc) { source = rc; } } }

The table below shows all metrics for ColumnReference.java.

MetricValueDescription
BLOCKS100.00Number of blocks
BLOCK_COMMENT134.00Number of block comment lines
COMMENTS491.00Comment lines
COMMENT_DENSITY 1.33Comment density
COMPARISONS64.00Number of comparison operators
CYCLOMATIC123.00Cyclomatic complexity
DECL_COMMENTS56.00Comments in declarations
DOC_COMMENT338.00Number of javadoc comment lines
ELOC370.00Effective lines of code
EXEC_COMMENTS29.00Comments in executable code
EXITS70.00Procedure exits
FUNCTIONS56.00Number of function declarations
HALSTEAD_DIFFICULTY73.83Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY115.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003410.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 1.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 4.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 1.00JAVA0096 Field in nested class hides outer field
JAVA0098 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 1.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 2.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 2.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 1.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 1.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 1.00JAVA0144 Line exceeds maximum M characters
JAVA01452170.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 1.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 1.00JAVA0174 Assigned local variable never used
JAVA0175 1.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 5.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA028510.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1179.00Number of lines in the source file
LINE_COMMENT19.00Number of line comments
LOC559.00Lines of code
LOGICAL_LINES205.00Number of statements
LOOPS 3.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS886.00Number of operands
OPERATORS1837.00Number of operators
PARAMS33.00Number of formal parameter declarations
PROGRAM_LENGTH2723.00Halstead program length
PROGRAM_VOCAB322.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS82.00Number of return points from functions
SIZE33601.00Size of the file in bytes
UNIQUE_OPERANDS276.00Number of unique operands
UNIQUE_OPERATORS46.00Number of unique operators
WHITESPACE129.00Number of whitespace lines