KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > plan > OpUn


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mediator.plan ;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.xquark.mediator.decomposer.Utils;
28 import org.xquark.mediator.runtime.MediatorException;
29 import org.xquark.xquery.parser.XQueryExpression;
30
31 public abstract class OpUn extends Operator {
32     // **********************************************************************
33
// * VERSIONING
34
// **********************************************************************
35
private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
36     private static final String JavaDoc RCSName = "$Name: $";
37     // **********************************************************************
38
// * CLASS VARIABLES
39
// **********************************************************************
40
protected Operator childOperator = null ;
41     
42     // ***********************************************************************
43
// * INITIALIZATION
44
// ***********************************************************************
45
/**
46      *
47      */

48     public OpUn(ExecutionPlan plan, XQueryExpression expression, Operator childOperator) throws MediatorException {
49         super(plan, expression) ;
50         this.childOperator = childOperator ;
51         if (childOperator != null) {
52             childOperator.setParentOperator(this);
53             addPaths(childOperator.getPaths());
54         }
55     }
56     
57     // #############################################################################
58
// VISITOR STUFF
59
// #############################################################################
60

61     public void accept(OperatorVisitor visitor) throws MediatorException {
62         visitor.visit(this);
63     }
64
65     // ***********************************************************************
66
// * EXECUTE QUERY
67
// ***********************************************************************
68
/**
69      *
70      */

71     public ResultSet executeQuery(DynamicContext context) throws MediatorException {
72         if (childOperator != null) {
73             OperatorRunnable or = childOperator.getOperatorRunnable(context);
74             or.run() ;
75             return getResultSet(context, or);
76         }
77         return getResultSet(context, null);
78     }
79     
80     /**
81      * @param or
82      * @return
83      */

84     protected abstract ResultSet getResultSet(DynamicContext context, OperatorRunnable or) throws MediatorException;
85
86     // ***********************************************************************
87
// * METHODS
88
// ***********************************************************************
89
/**
90      *
91      */

92     public Operator getChildOperator() { return childOperator ; }
93     
94     // **********************************************************************
95
// * OPTIMIZE
96
// **********************************************************************
97
/**
98      * If the *exactly* same set of source is used for an operation,
99      * then the subtree can be passed entierely to the source.
100      * Beware of processing this from the leaf to the node.
101      *
102      * <p>Note: If this method is not overloaded or if it returns null,
103      * it means that _this_ node will not be optimized.</p>
104      */

105 // public Operator optimizeSource() throws MediatorException {
106
// Operator workexp = childOperator.optimizeSource() ;
107
// if (workexp != null) childOperator = workexp ;
108
//
109
// /*
110
// if (childalgebra.isSource()) {
111
// Algebra newnode = mergeWithSub() ;
112
// return newnode ;
113
// }
114
// */
115
// return null ;
116
// }
117

118     /**
119      * Add projections on attributes the soonest as possible in order to
120      * manipulate the less data as possible. As soon an attribute isn't
121      * necessary, it must be unselected (by a projection on the complementary
122      * variables).
123      *
124      * <p>Note: If this method is not overloaded or if it returns null,
125      * it means that _this_ node will not be optimized.</p>
126      */

127 // public Operator optimizeProjection() throws MediatorException {
128
// return null ;
129
// }
130

131     /**
132      *
133      *
134      * <p>Note: If this method is not overloaded or if it returns null,
135      * it means that _this_ node will not be optimized.</p>
136      */

137 // public Operator optimizeRestriction() throws MediatorException {
138
// return null ;
139
// }
140

141     
142     /**
143      * If the set of sources handled by this node are exactly the same (order
144      * not important) then return true.
145      *
146      * An AlgUnOp is alway the same value than the value of its children.
147      */

148 // protected boolean shareSameSources() {
149
// return childOperator.shareSameSources() ;
150
// }
151

152     /**
153      * Return true if the node is of type source. An AlgUnOp is not a source.
154      * @return false.
155      */

156     public boolean isSource() {
157         return false ;
158     }
159     
160     /**
161      * Return all the sources depending of this node.
162      */

163     public ArrayList JavaDoc getSources() {
164         if (sources == null)
165             sources = childOperator.getSources() ;
166         return sources ;
167     }
168     
169     public void terminate() {
170         if (childOperator != null)
171             childOperator.terminate();
172     }
173
174     public void setPrepared() throws MediatorException {
175         if (prepared) return;
176         prepared = true;
177         if (childOperator != null)
178             childOperator.setPrepared();
179     }
180     
181     public String JavaDoc toCompleteString(int indent) {
182         StringBuffer JavaDoc buf = new StringBuffer JavaDoc() ;
183         buf.append(Utils.makeIndent(indent) + "<" + getClass().getName() + " size=" + size + " id size=" + idsize + " isLet=\"" + islet + "\" valueDepends=\"" + valueDepends + "\" whereDepends=\"" + whereDepends + "\">\n") ;
184         buf.append(Utils.makeIndent(indent + 1) + "<Expression>\n") ;
185         buf.append(Utils.makeIndent(indent + 2) + expression + "\n") ;
186         buf.append(Utils.makeIndent(indent + 1) + "</Expression>\n") ;
187 // if (variables != null) {
188
// buf.append(Utils.makeIndent(indent + 1) + "<Variables>\n") ;
189
// for (int i = 0 ; i < variables.size() ; i ++) {
190
// buf.append(Utils.makeIndent(indent + 2) + "<Variable>" + variables.get(i) + "</Variable>\n") ;
191
// }
192
// buf.append(Utils.makeIndent(indent + 1) + "</Variables>\n") ;
193
// }
194
if (paths != null) {
195             buf.append(Utils.makeIndent(indent + 1) + "<Paths>\n") ;
196             for (int i = 0 ; i < paths.size() ; i ++) {
197                 buf.append(Utils.makeIndent(indent + 2) + "<Path>" + paths.get(i) + "</Path>\n") ;
198             }
199             buf.append(Utils.makeIndent(indent + 1) + "</Paths>\n") ;
200         }
201         buf.append(Utils.makeIndent(indent + 1) + "<Element>\n") ;
202         if (this.childOperator != null) buf.append(this.childOperator.toCompleteString(indent + 2)) ;
203         buf.append(Utils.makeIndent(indent + 1) + "</Element>\n") ;
204         buf.append(Utils.makeIndent(indent) + "</" + getClass().getName() + ">\n") ;
205         return buf.toString() ;
206     }
207 }
208
Popular Tags