KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > BinOpOuterJoin


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.extractor.algebra;
24
25 import java.util.*;
26
27 import org.xquark.extractor.common.Debug;
28 import org.xquark.extractor.common.SqlWrapperException;
29 import org.xquark.extractor.sql.SqlExpression;
30
31 public final class BinOpOuterJoin extends BinaryOperator implements Relation
32 {
33     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36     protected int _joinType;
37     protected List _predicateList;
38
39     List _keys;
40
41     public BinOpOuterJoin(Expression leftOperand, Expression rightOperand, int joinType, List predicateList)
42     {
43         super ( leftOperand, rightOperand );
44         setJoinType (joinType ) ;
45         setPredicateList ( predicateList );
46     }
47
48     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc
49     {
50         BinOpOuterJoin retVal = (BinOpOuterJoin)super.clone(clonedExprs);
51         retVal.setPredicateList(AlgebraTools.clone(getPredicateList(), clonedExprs));
52         clonedExprs.put(this, retVal);
53         return retVal;
54     }
55
56     /**
57      * Access method for the _joinType property.
58      *
59      * @return the current value of the _joinType property
60      */

61     public int getJoinType() { return _joinType;}
62
63     /**
64      * Sets the value of the _joinType property.
65      *
66      * @param aJoinType
67      * the new value of the _joinType property
68      */

69     public void setJoinType(int aJoinType) { _joinType = aJoinType;}
70
71     /**
72      * Access method for the _predicate property.
73      *
74      * @return the current value of the _predicate property
75      */

76     public List getPredicateList() { return _predicateList;}
77
78     public void setPredicateList(List predicateList) {
79         _predicateList = predicateList;
80
81         if ( null != _predicateList )
82         {
83             Iterator itr ;
84             itr = _predicateList.iterator() ;
85             while ( itr.hasNext () ) {
86                 ( (Expression)itr.next() ).setFather(this) ;
87             }
88         }
89     }
90
91
92     public void addPredicate(Expression predicate)
93     {
94         if (predicate == null)
95            return;
96
97         if (null == _predicateList)
98             _predicateList = new ArrayList ();
99
100         _predicateList.add(predicate);
101         predicate.setFather(this);
102     }
103
104
105     public Set providedTableInstances(){
106         return visibleTableInstances();
107     }
108
109     public AttributeExpression findNonNullAttribute() {
110         AttributeExpression ret = ((Relation)_leftOperand).findNonNullAttribute();
111         if (ret == null)
112             ret = ((Relation)_rightOperand).findNonNullAttribute();
113         return ret;
114     }
115
116     public boolean replaceChild(Expression oldChild, Expression newChild)
117     {
118         boolean retVal = false;
119         List list = getPredicateList();
120
121         Expression expr = null ;
122         for (int i = 0; i < list.size(); i++) {
123             expr = (Expression)list.get(i);
124             if (expr.equals(oldChild)) {
125                 list.set(i, newChild);
126                 newChild.setFather(this);
127                 retVal = true;
128                 break;
129             }
130         }
131
132         if (getLeftOperand().equals(oldChild)) {
133             setLeftOperand(newChild);
134             retVal = true;
135         }
136         else if (getRightOperand().equals(oldChild)) {
137             setRightOperand(newChild);
138             retVal = true;
139         }
140         return retVal;
141     }
142
143
144     public void setKeys(List keys) {
145           _keys = keys;
146     }
147
148     public List getKeys() {
149      return _keys;
150     }
151
152     public List nameTest(String JavaDoc name)
153     {
154         Debug.nyi("BinOpOuterJoin::nameTest(String name)");
155         return ((Relation)getLeftOperand()).nameTest(name);
156     }
157
158     public Set participants() {
159         Set retVal = new HashSet();
160         BuildReferredAttributes visitor = new BuildReferredAttributes();
161         Expression predicate = null;
162         for (int i = 0; i < _predicateList.size(); i++) {
163             predicate = (Expression)_predicateList.get(i);
164             predicate.accept(visitor);
165             retVal.addAll(predicate.getReferredTableInstances());
166         }
167
168         return retVal;
169     }
170
171     public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException
172     {
173         return visitor.visit(this);
174     }
175
176     public void accept (AlgebraVisitor visitor) throws SqlWrapperException
177     {
178         visitor.visit(this);
179     }
180 }
181
182
183
184
185
186
187
188
Popular Tags