1 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 RCSRevision = "$Revision: 1.5 $"; 34 private static final String 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 clone(Map clonedExprs) throws CloneNotSupportedException 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 61 public int getJoinType() { return _joinType;} 62 63 69 public void setJoinType(int aJoinType) { _joinType = aJoinType;} 70 71 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 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 |