001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.NormalizeResultSetNode
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import org.apache.derby.iapi.services.context.ContextManager;
025:
026: import org.apache.derby.iapi.sql.compile.CostEstimate;
027: import org.apache.derby.iapi.sql.compile.Optimizable;
028: import org.apache.derby.iapi.sql.compile.OptimizableList;
029: import org.apache.derby.iapi.sql.compile.OptimizablePredicate;
030: import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;
031: import org.apache.derby.iapi.sql.compile.Optimizer;
032: import org.apache.derby.iapi.sql.compile.Visitable;
033: import org.apache.derby.iapi.sql.compile.Visitor;
034: import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;
035:
036: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
037: import org.apache.derby.iapi.reference.ClassName;
038:
039: import org.apache.derby.iapi.sql.Activation;
040: import org.apache.derby.iapi.sql.ResultSet;
041:
042: import org.apache.derby.iapi.error.StandardException;
043:
044: import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
045:
046: import org.apache.derby.iapi.services.compiler.MethodBuilder;
047:
048: import org.apache.derby.iapi.services.sanity.SanityManager;
049:
050: import org.apache.derby.iapi.util.JBitSet;
051: import org.apache.derby.iapi.services.classfile.VMOpcode;
052:
053: import java.util.Properties;
054:
055: /**
056: * A NormalizeResultSetNode represents a normalization result set for any
057: * child result set that needs one.
058: *
059: * @author Jerry Brenner
060: */
061:
062: public class NormalizeResultSetNode extends SingleChildResultSetNode {
063: /**
064: * this indicates if the normalize is being performed for an Update
065: * statement or not. The row passed to update also has
066: * before values of the columns being updated-- we need not
067: * normalize these values.
068: */
069: private boolean forUpdate;
070:
071: /**
072: * Initializer for a NormalizeResultSetNode.
073: *
074: * @param childResult The child ResultSetNode
075: * @param rcl The RCL for the node
076: * @param tableProperties Properties list associated with the table
077: * @param forUpdate tells us if the normalize operation is being
078: * performed on behalf of an update statement.
079: */
080:
081: public void init(Object childResult, Object rcl,
082: Object tableProperties, Object forUpdate) {
083: super .init(childResult, tableProperties);
084: resultColumns = (ResultColumnList) rcl;
085: this .forUpdate = ((Boolean) forUpdate).booleanValue();
086: }
087:
088: /**
089: *
090: *
091: * @exception StandardException Thrown on error
092: */
093: public void generate(ActivationClassBuilder acb, MethodBuilder mb)
094: throws StandardException {
095: int erdNumber;
096:
097: if (SanityManager.DEBUG)
098: SanityManager.ASSERT(resultColumns != null,
099: "Tree structure bad");
100:
101: /* Get the next ResultSet #, so that we can number this ResultSetNode, its
102: * ResultColumnList and ResultSet.
103: */
104: assignResultSetNumber();
105:
106: // build up the tree.
107:
108: // Generate the child ResultSet
109:
110: // Get the cost estimate for the child
111: costEstimate = childResult.getFinalCostEstimate();
112:
113: erdNumber = acb.addItem(makeResultDescription());
114:
115: acb.pushGetResultSetFactoryExpression(mb);
116: childResult.generate(acb, mb);
117: mb.push(resultSetNumber);
118: mb.push(erdNumber);
119: mb.push(costEstimate.rowCount());
120: mb.push(costEstimate.getEstimatedCost());
121: mb.push(forUpdate);
122:
123: mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null,
124: "getNormalizeResultSet", ClassName.NoPutResultSet, 6);
125: }
126:
127: /**
128: * set the Information gathered from the parent table that is
129: * required to peform a referential action on dependent table.
130: */
131: public void setRefActionInfo(long fkIndexConglomId,
132: int[] fkColArray, String parentResultSetId,
133: boolean dependentScan) {
134: childResult.setRefActionInfo(fkIndexConglomId, fkColArray,
135: parentResultSetId, dependentScan);
136: }
137:
138: }
|