001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.MaterializeResultSetNode
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.Optimizable;
027: import org.apache.derby.iapi.sql.compile.OptimizableList;
028: import org.apache.derby.iapi.sql.compile.OptimizablePredicate;
029: import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;
030: import org.apache.derby.iapi.sql.compile.Optimizer;
031: import org.apache.derby.iapi.sql.compile.Visitable;
032: import org.apache.derby.iapi.sql.compile.Visitor;
033: import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;
034:
035: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
036:
037: import org.apache.derby.iapi.sql.Activation;
038: import org.apache.derby.iapi.sql.ResultSet;
039:
040: import org.apache.derby.iapi.error.StandardException;
041:
042: import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
043:
044: import org.apache.derby.iapi.services.compiler.MethodBuilder;
045:
046: import org.apache.derby.iapi.services.sanity.SanityManager;
047: import org.apache.derby.iapi.reference.ClassName;
048:
049: import org.apache.derby.iapi.services.classfile.VMOpcode;
050:
051: import java.util.Properties;
052:
053: /**
054: * A MaterializeResultSetNode represents a materialization result set for any
055: * child result set that needs one.
056: *
057: * @author Jerry Brenner
058: */
059:
060: public class MaterializeResultSetNode extends SingleChildResultSetNode {
061: /**
062: * Initializer for a MaterializeResultSetNode.
063: *
064: * @param childResult The child ResultSetNode
065: * @param rcl The RCL for the node
066: * @param tableProperties Properties list associated with the table
067: */
068:
069: public void init(Object childResult, Object rcl,
070: Object tableProperties) {
071: super .init(childResult, tableProperties);
072: resultColumns = (ResultColumnList) rcl;
073: }
074:
075: /**
076: * Prints the sub-nodes of this object. See QueryTreeNode.java for
077: * how tree printing is supposed to work.
078: *
079: * @param depth The depth of this node in the tree
080: */
081:
082: public void printSubNodes(int depth) {
083: if (SanityManager.DEBUG) {
084: super .printSubNodes(depth);
085: }
086: }
087:
088: /**
089: *
090: *
091: * @exception StandardException Thrown on error
092: */
093: public void generate(ActivationClassBuilder acb, MethodBuilder mb)
094: throws StandardException {
095: if (SanityManager.DEBUG)
096: SanityManager.ASSERT(resultColumns != null,
097: "Tree structure bad");
098:
099: /* Get the next ResultSet #, so that we can number this ResultSetNode, its
100: * ResultColumnList and ResultSet.
101: */
102: assignResultSetNumber();
103:
104: // Get the cost estimate from the child if we don't have one yet
105: costEstimate = childResult.getFinalCostEstimate();
106:
107: // build up the tree.
108:
109: // Generate the child ResultSet
110: acb.pushGetResultSetFactoryExpression(mb);
111:
112: childResult.generate(acb, mb);
113: mb.push(resultSetNumber);
114: mb.push(costEstimate.rowCount());
115: mb.push(costEstimate.getEstimatedCost());
116:
117: mb
118: .callMethod(VMOpcode.INVOKEINTERFACE, (String) null,
119: "getMaterializedResultSet",
120: ClassName.NoPutResultSet, 4);
121: }
122: }
|