KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > query > lib > Cartesian


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.query.lib;
25
26 import org.objectweb.medor.api.Field;
27 import org.objectweb.medor.api.MedorException;
28 import org.objectweb.medor.expression.api.Expression;
29 import org.objectweb.medor.query.api.OperationType;
30 import org.objectweb.medor.query.api.QueryTree;
31 import org.objectweb.medor.query.api.QueryTreeField;
32
33 /**
34  *
35  * @author Sebastien Chassande-Barrioz
36  */

37 public class Cartesian extends BasicQueryNode {
38     public Cartesian() {
39     }
40
41     /**
42      *
43      * @param leftQT is the left QueryTree child used in the cartesian product.
44      * @param rightQT is the rigth QueryTree child used in the cartesian product.
45      */

46     public Cartesian(QueryTree leftQT,
47                      QueryTree rightQT,
48                      String JavaDoc name) {
49         super(name);
50         //adds the Fields from the left and right QueryTrees
51
Field[] leftFields = leftQT.getTupleStructure().getFields();
52         Field[] rightFields = rightQT.getTupleStructure().getFields();
53         try {
54
55             for (int i = 0; i < leftFields.length; i++) {
56                 this.addPropagatedField(
57                     leftFields[i].getName(),
58                     leftFields[i].getType(),
59                     new QueryTreeField[]{(QueryTreeField) leftFields[i]});
60             }
61             for (int i = 0; i < rightFields.length; i++) {
62                 this.addPropagatedField(
63                     rightFields[i].getName(),
64                     rightFields[i].getType(),
65                     new QueryTreeField[]{(QueryTreeField) rightFields[i]});
66             }
67         }
68         catch (MedorException e) {
69         }
70         //computes the indexes
71
int lsize = leftQT.getTupleStructure().getSize();
72         int rsize = rightQT.getTupleStructure().getSize();
73         indexes = new int[lsize + rsize];
74
75         for (int i = 1; (i <= lsize); i++) {
76             indexes[i - 1] = i;
77         }
78         for (int i = lsize + 1; (i <= (lsize + rsize)); i++) {
79             indexes[i - 1] = i;
80         }
81     }
82
83     // IMPLEMENTATION OF THE QueryNode INTERFACE //
84
//-------------------------------------------//
85

86     public void setQueryFilter(Expression f) {
87         throw new UnsupportedOperationException JavaDoc("Cartesian products cannot be assigned a filter.");
88     }
89
90     public short getType() {
91         return OperationType.CARTESIAN;
92     }
93 }
94
Popular Tags