KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > algebra > AlgFunction


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.algebra;
24
25 import org.xquark.mediator.plan.*;
26 import org.xquark.mediator.plan.primitivefunctions.OpFuncDISTINCT_VALUES;
27 import org.xquark.mediator.runtime.MediatorException;
28 import org.xquark.xquery.parser.*;
29 import org.xquark.xquery.parser.primitivefunctions.fnfunctions.FunctionDISTINCT_VALUES;
30
31 /**
32  * This class represent a terminal leaf of the dependancy tree on first step
33  * of creation (before atomization).
34  *
35  */

36 public class AlgFunction extends Algebra {
37     // **********************************************************************
38
// * VERSIONING
39
// **********************************************************************
40
private static final String JavaDoc RCSRevision = "$Revision: 1.7 $";
41     private static final String JavaDoc RCSName = "$Name: $";
42     // **********************************************************************
43
// * CLASS VARIABLES
44
// **********************************************************************
45
/**
46      * references on Functions (will be filled later when called locateFunctions)
47      */

48     //private ArrayList sources ;
49
//private ArrayList depnodes ;
50

51     // ************************************************************************
52
// * INITIALIZATION
53
// ************************************************************************
54
/**
55      *
56      * @param typevisitor
57      * @param expression
58      * @param var
59      * @param parent
60      */

61     public AlgFunction(XQueryExpression expression, Variable var, AlgebraManager depmanager, boolean islet) throws MediatorException {
62         super(expression, var, depmanager, islet);
63         //paths = depmanager.getPathsfromVar(var);
64
// fill var lists
65
fillVarLists();
66     }
67
68     // ******************************************************************
69
// * METHODS
70
// ******************************************************************
71

72     public void ParentHasIdentifier() {
73         hasIdentifier = true;
74     }
75
76     // ******************************************************************
77
// * CREATE EXECUTION PLAN
78
// ******************************************************************
79
/**
80      *
81      * @param plan
82      * @return
83      */

84     public Operator createOperator(ExecutionPlan plan) throws MediatorException {
85
86         //if (true) throw new MediatorException("createAlgebra not supported in DepFunction");
87

88         Operator algebra = null;
89         if (algChildren != null) {
90             for (int i = 0; i < algChildren.size(); i++) {
91             // getting child
92
Algebra depchildi = (Algebra) algChildren.get(i);
93 // if (log.isDebugEnabled()) {
94
// log.debug("*********** DEPFUNCTION CHILD STUFF *************************");
95
// log.debug("ClassName = " + depchildi.getClass().getName());
96
// log.debug("is let = " + depchildi.isLet());
97
// log.debug("depchildiexpr = " + depchildi.getExpression());
98
// log.debug("depchildi sources = " + depchildi.getExpression().getSourceNames());
99
// log.debug("vari = " + depchildi.getVariables());
100
// log.debug("definition vars depending on = " + depchildi.getVarsDependingOn());
101
// log.debug("where vars depending on = " + depchildi.getVarsWhereOn());
102
// log.debug("vars referenced by = " + depchildi.getVarsReferencedBy());
103
// log.debug("children = " + depchildi.getChildren());
104
// }
105
if (algebra == null)
106                     algebra = (Operator) depchildi.createOperator(plan);
107                 else
108                     algebra = new OpMerge(plan, null, algebra, (Operator) depchildi.createOperator(plan));
109             }
110
111             // TODO: later add the Agregate operator here.
112

113             if (expression instanceof AggregateFunctionCall)
114                 algebra = new OpAggregateFunc(plan, expression, algebra);
115             else if (expression instanceof FunctionDISTINCT_VALUES)
116                 //algebra = new AlgAggregateFunc(plan, expression, algebra);
117
algebra = new OpFuncDISTINCT_VALUES(plan, expression, algebra);
118             else if (expression instanceof PrimitiveFunctionCall)
119                 algebra = new OpFunc(plan, expression, algebra);
120             else
121                 throw new MediatorException("Not yet implemented : create algebra for function -> " + expression.getClass().getName());
122             algebra = new OpNotSource(plan, null, (Variable) variables.get(0), algebra, this.islet);
123         }
124         else
125             algebra = new OpEval(plan,this,null,hasIdentifier);
126
127         /*
128         if (expression instanceof FunctionAVG)
129             root = new AlgFuncAVG(plan, expression, tmproot) ;
130         else if (expression instanceof FunctionCEILING)
131             root = new AlgFuncCEILING(plan, expression, tmproot) ;
132         else if (expression instanceof FunctionCOLLECTION)
133             root = new AlgFuncCOLLECTION(plan, expression, tmproot) ;
134         else if (expression instanceof FunctionCONCAT)
135             root = new AlgFuncCONCAT(plan, expression, tmproot) ;
136         else if (expression instanceof FunctionCONTAINS)
137             root = new AlgFuncCONTAINS(plan, expression, tmproot) ;
138         else if (expression instanceof FunctionCOUNT)
139             root = new AlgFuncCOUNT(plan, expression, tmproot) ;
140         else if (expression instanceof FunctionCURRENT_DATETIME)
141             root = new AlgFuncCURRENT_DATETIME(plan, expression, tmproot) ;
142         else if (expression instanceof FunctionDATA)
143             root = new AlgFuncDATA(plan, expression, tmproot) ;
144         else if (expression instanceof FunctionDATE)
145             root = new AlgFuncDATE(plan, expression, tmproot) ;
146         else if (expression instanceof FunctionDATETIME)
147             root = new AlgFuncDATETIME(plan, expression, tmproot) ;
148         else if (expression instanceof FunctionDECIMAL)
149             root = new AlgFuncDECIMAL(plan, expression, tmproot) ;
150         else if (expression instanceof FunctionDISTINCT_VALUES)
151             root = new AlgFuncDISTINCT_VALUES(plan, expression, tmproot) ;
152         else if (expression instanceof FunctionDOUBLE)
153             root = new AlgFuncDOUBLE(plan, expression, tmproot) ;
154         else if (expression instanceof FunctionEMPTY)
155             root = new AlgFuncEMPTY(plan, expression, tmproot) ;
156         else if (expression instanceof FunctionENDS_WITH)
157             root = new AlgFuncENDS_WITH(plan, expression, tmproot) ;
158         else if (expression instanceof FunctionEXISTS)
159             root = new AlgFuncEXISTS(plan, expression, tmproot) ;
160         else if (expression instanceof FunctionFALSE)
161             root = new AlgFuncFALSE(plan, expression, tmproot) ;
162         else if (expression instanceof FunctionFLOOR)
163             root = new AlgFuncFLOOR(plan, expression, tmproot) ;
164         else if (expression instanceof FunctionINTEGER)
165             root = new AlgFuncINTEGER(plan, expression, tmproot) ;
166         else if (expression instanceof FunctionLOWER_CASE)
167             root = new AlgFuncLOWER_CASE(plan, expression, tmproot) ;
168         else if (expression instanceof FunctionMATCH)
169             root = new AlgFuncMATCH(plan, expression, tmproot) ;
170         else if (expression instanceof FunctionMAX)
171             root = new AlgFuncMAX(plan, expression, tmproot) ;
172         else if (expression instanceof FunctionMIN)
173             root = new AlgFuncMIN(plan, expression, tmproot) ;
174         else if (expression instanceof FunctionNAME)
175             root = new AlgFuncNAME(plan, expression, tmproot) ;
176         else if (expression instanceof FunctionNOT)
177             root = new AlgFuncNOT(plan, expression, tmproot) ;
178         else if (expression instanceof FunctionNUMBER)
179             root = new AlgFuncNUMBER(plan, expression, tmproot) ;
180         else if (expression instanceof FunctionROUND)
181             root = new AlgFuncROUND(plan, expression, tmproot) ;
182         else if (expression instanceof FunctionSTARTS_WITH)
183             root = new AlgFuncSTARTS_WITH(plan, expression, tmproot) ;
184         else if (expression instanceof FunctionSTRING)
185             root = new AlgFuncSTRING(plan, expression, tmproot) ;
186         else if (expression instanceof FunctionSTRING_LENGTH)
187             root = new AlgFuncSTRING_LENGTH(plan, expression, tmproot) ;
188         else if (expression instanceof FunctionSUBSTRING)
189             root = new AlgFuncSUBSTRING(plan, expression, tmproot) ;
190         else if (expression instanceof FunctionSUM)
191             root = new AlgFuncSUM(plan, expression, tmproot) ;
192         else if (expression instanceof FunctionTIME)
193             root = new AlgFuncTIME(plan, expression, tmproot) ;
194         else if (expression instanceof FunctionTRUE)
195             root = new AlgFuncTRUE(plan, expression, tmproot) ;
196         else if (expression instanceof FunctionUPPER_CASE)
197             root = new AlgFuncUPPER_CASE(plan, expression, tmproot) ;
198         */

199
200         algebra.isLet(islet);
201         return algebra;
202     }
203
204     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
205         AlgFunction newobj = (AlgFunction) super.clone();
206         return newobj;
207     }
208
209     public void execute(ExecutionPlan plan) throws MediatorException {}
210
211     // ******************************************************************
212
// * DEBUGGING
213
// ******************************************************************
214
}
215
Popular Tags