KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > eval > lib > BinaryIteratifNodeEvaluator


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2004 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.eval.lib;
25
26 import org.objectweb.medor.api.MedorException;
27 import org.objectweb.medor.api.QueryNodeException;
28 import org.objectweb.medor.eval.api.NodeEvaluator;
29 import org.objectweb.medor.eval.api.EvaluationMetaData;
30 import org.objectweb.medor.eval.cache.lib.TupleCache;
31 import org.objectweb.medor.eval.cache.lib.WindowCachedTupleCollection;
32 import org.objectweb.medor.eval.prefetch.api.PrefetchBuffer;
33 import org.objectweb.medor.expression.api.ParameterOperand;
34 import org.objectweb.medor.query.api.OperationType;
35 import org.objectweb.medor.query.api.QueryNode;
36 import org.objectweb.medor.tuple.api.TupleCollection;
37
38 public class BinaryIteratifNodeEvaluator implements NodeEvaluator {
39
40     QueryNode query;
41     NodeEvaluator leftNodeEvaluator, rightNodeEvaluator;
42     EvaluationMetaData evaluationMetaData;
43     long cacheSize;
44     boolean open = false;
45
46     public BinaryIteratifNodeEvaluator(QueryNode query,
47                                        NodeEvaluator leftNodeEvaluator,
48                                        NodeEvaluator rightNodeEvaluator,
49                                        EvaluationMetaData evaluationMetaData) {
50         this.query = query;
51         this.leftNodeEvaluator = leftNodeEvaluator;
52         this.rightNodeEvaluator = rightNodeEvaluator;
53         this.evaluationMetaData = evaluationMetaData;
54     }
55
56     public boolean linkChildren() {
57         return true;
58     }
59
60     public boolean unlinkChildren() {
61         return true;
62     }
63
64     public TupleCollection fetchData(ParameterOperand[] parameters)
65             throws MedorException {
66         switch (query.getType()) {
67         case OperationType.CARTESIAN:
68             if (evaluationMetaData == null) // There is no optimization
69
return
70                         new CartesianEvaluatedTC(query,
71                                 leftNodeEvaluator,
72                                 rightNodeEvaluator,
73                                 parameters);
74             else if (evaluationMetaData.isCache())
75                 return new WindowCachedTupleCollection(
76                         new CartesianEvaluatedTC(query,
77                                 leftNodeEvaluator,
78                                 rightNodeEvaluator,
79                                 parameters),
80                         new TupleCache(cacheSize)
81                 );
82             else
83                 return
84                         new CartesianEvaluatedTC(query, leftNodeEvaluator,
85                                 rightNodeEvaluator, parameters);
86
87         case OperationType.INTERSECTION:
88             if ((evaluationMetaData == null)) // There is no optimization
89
return
90                         new BinaryImplicitTC(query,
91                                 leftNodeEvaluator,
92                                 rightNodeEvaluator,
93                                 parameters);
94             else if (evaluationMetaData.isCache())
95                 return new WindowCachedTupleCollection(
96                         new BinaryImplicitTC(query,
97                                 leftNodeEvaluator,
98                                 rightNodeEvaluator,
99                                 parameters),
100                         new TupleCache(cacheSize)
101                 );
102             else
103                 return
104                         new BinaryImplicitTC(query,
105                                 leftNodeEvaluator,
106                                 rightNodeEvaluator,
107                                 parameters);
108
109         case OperationType.JOIN_PROJECT:
110             if ((evaluationMetaData == null)) // There is no optimization
111
return
112                         new BinaryImplicitTC(query,
113                                 leftNodeEvaluator,
114                                 rightNodeEvaluator,
115                                 parameters);
116             else if (evaluationMetaData.isCache())
117                 return
118                         new WindowCachedTupleCollection(
119                                 new BinaryImplicitTC(query,
120                                         leftNodeEvaluator,
121                                         rightNodeEvaluator,
122                                         parameters),
123                                 new TupleCache(cacheSize)
124                         );
125             else
126                 return new BinaryImplicitTC(query,
127                         leftNodeEvaluator,
128                         rightNodeEvaluator,
129                         parameters);
130
131         case OperationType.UNION:
132             if ((evaluationMetaData == null)) // There is no optimization
133
return new UnionEvaluatedTC(query,
134                         leftNodeEvaluator,
135                         rightNodeEvaluator,
136                         parameters);
137             else if (evaluationMetaData.isCache())
138                 return new WindowCachedTupleCollection(
139                         new UnionEvaluatedTC(query,
140                                 leftNodeEvaluator,
141                                 rightNodeEvaluator,
142                                 parameters),
143                         new TupleCache(cacheSize)
144                 );
145             else
146                 return
147                         new UnionEvaluatedTC(query,
148                                 leftNodeEvaluator,
149                                 rightNodeEvaluator,
150                                 parameters);
151
152         default:
153             throw new QueryNodeException("Unreconized QueryNode Type");
154         }
155     }
156
157     public long getCacheSize() {
158         return cacheSize;
159     }
160
161     public void setCacheSize(long cacheSize) {
162         this.cacheSize = cacheSize;
163     }
164
165     public QueryNode getQueryNode() {
166         return query;
167     }
168
169     public EvaluationMetaData getEvaluationMetaData() {
170         return evaluationMetaData;
171     }
172
173     public void setPrefetchBuffer(PrefetchBuffer pb) throws MedorException {
174         // No prefetching for this evaluator: ignore
175
}
176 }
177
Popular Tags