KickJava   Java API By Example, From Geeks To Geeks.

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


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.NestQueryNode;
35 import org.objectweb.medor.query.api.OperationType;
36 import org.objectweb.medor.query.api.QueryNode;
37 import org.objectweb.medor.query.api.UnnestQueryNode;
38 import org.objectweb.medor.tuple.api.TupleCollection;
39
40 public class UnaryIteratifNodeEvaluator implements NodeEvaluator {
41
42     QueryNode query;
43     NodeEvaluator subNodeEvaluator;
44     long cacheSize;
45     boolean open = false;
46     PrefetchBuffer prefetchBuffer;
47     EvaluationMetaData evaluationMetaData;
48
49     public UnaryIteratifNodeEvaluator(QueryNode query,
50                                       NodeEvaluator subNodeEvaluator,
51                                       EvaluationMetaData evaluationMetaData) {
52         this.query = query;
53         this.subNodeEvaluator = subNodeEvaluator;
54         this.evaluationMetaData = evaluationMetaData;
55     }
56
57     public boolean linkChildren() {
58         // TO DO
59
open = true;
60         return true;
61     }
62
63     public boolean unlinkChildren() {
64         // TO DO
65
open = false;
66         return true;
67     }
68
69     public TupleCollection fetchData(ParameterOperand[] parameters)
70             throws MedorException {
71         TupleCollection res = null;
72         switch (query.getType()) {
73         case OperationType.NEST:
74             res = new NestEvaluatedTC((NestQueryNode) query,
75                     subNodeEvaluator,
76                     parameters,
77                     evaluationMetaData);
78             break;
79         case OperationType.PROJECT:
80             res = new ProjectEvaluatedTC(query,
81                     subNodeEvaluator,
82                     parameters,
83                     prefetchBuffer);
84             break;
85         case OperationType.SELECT_PROJECT:
86             if (query.getQueryFilter() == null) {
87                 res = new ProjectEvaluatedTC(query,
88                         subNodeEvaluator,
89                         parameters,
90                         prefetchBuffer);
91             } else {
92                 res = new SelProjEvaluatedTC(query,
93                         subNodeEvaluator,
94                         parameters,
95                         prefetchBuffer);
96             }
97             break;
98         case OperationType.UNNEST:
99             res = new UnnestEvaluatedTC(
100                     (UnnestQueryNode) query, subNodeEvaluator, parameters);
101             break;
102         default:
103             throw new QueryNodeException("Unreconized QueryNode: " + query);
104         }
105         if (evaluationMetaData == null) {
106             // No optimization
107
return res;
108         } else if (evaluationMetaData.isCache()) {
109             return new WindowCachedTupleCollection(
110                     res, new TupleCache(cacheSize));
111         } else {
112             return res;
113         }
114     }
115
116     public void setPrefetchBuffer(PrefetchBuffer pb) throws MedorException {
117         prefetchBuffer = pb;
118     }
119
120     public long getCacheSize() {
121         return cacheSize;
122     }
123
124     public void setCacheSize(long cacheSize) {
125         this.cacheSize = cacheSize;
126     }
127
128     public QueryNode getQueryNode() {
129         return query;
130     }
131
132     public EvaluationMetaData getEvaluationMetaData() {
133         return evaluationMetaData;
134     }
135
136 }
137
Popular Tags