1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.*; 26 27 import org.xquark.extractor.common.SqlWrapperException; 28 import org.xquark.extractor.sql.SqlExpression; 29 30 public final class UnOpRestrict extends UnaryAlgebra implements PredicateHolder 31 { 32 private static final String RCSRevision = "$Revision: 1.6 $"; 33 private static final String RCSName = "$Name: $"; 34 35 36 protected List _predicateList; 37 38 43 protected boolean _postResult = false; 44 45 public UnOpRestrict(Expression operand) { super(operand);} 46 47 public UnOpRestrict(Expression operand, Expression predicate) 48 { 49 super ( operand ) ; 50 addPredicate ( predicate ) ; 51 } 52 53 public UnOpRestrict(Expression operand, List predicateList) 54 { 55 super ( operand ) ; 56 setPredicateList ( predicateList ) ; 57 } 58 59 public UnOpRestrict(Expression operand, List predicateList, boolean postResult) 60 { 61 this(operand, predicateList) ; 62 setPostResult(postResult) ; 63 } 64 65 synchronized Object clone(Map clonedExprs) throws CloneNotSupportedException 66 { 67 UnOpRestrict retVal = (UnOpRestrict)super.clone(clonedExprs); 68 retVal.setPredicateList(AlgebraTools.clone(_predicateList, clonedExprs)); 69 70 clonedExprs.put(this, retVal); 71 return retVal; 72 } 73 74 public List getPredicateList() 75 { 76 return _predicateList; 77 } 78 79 public List getParameterList() 80 { 81 return getPredicateList(); 82 } 83 84 public void setPredicateList(List predicateList) 85 { 86 _predicateList = predicateList; 87 88 if ( null != _predicateList ) 89 { 90 Iterator itr ; 91 itr = _predicateList.iterator() ; 92 while ( itr.hasNext () ) { 93 ( (Expression)itr.next() ).setFather(this) ; 94 } 95 } 96 } 97 98 99 public void addPredicate(Expression predicate) 100 { 101 if ( null == predicate ) 102 { 103 return ; 104 } 105 106 if (null == _predicateList) { 107 _predicateList = new ArrayList (); 108 } 109 110 _predicateList.add(predicate); 111 predicate.setFather(this); 112 } 113 114 115 public void removePredicate(Expression predicate) 116 { 117 _predicateList.remove(predicate); 118 } 119 120 121 public List getKeys() { 122 return ((Relation)getOperand()).getKeys(); 123 } 124 125 private void splitPredicate(Expression predicate, List predicateList) 126 { 127 Expression p1 , p2 ; 128 BinOpBoolean binOpBoolean ; 129 130 p1 = predicate ; 131 132 if ( p1 instanceof BinOpBoolean ) 133 { 134 binOpBoolean = (BinOpBoolean) p1 ; 135 if ( AND == binOpBoolean.getOperator() ) 136 { 137 splitPredicate (binOpBoolean.getLeftOperand() , predicateList) ; 138 splitPredicate (binOpBoolean.getRightOperand() , predicateList) ; 139 } 140 else 141 { 142 predicateList .add( predicate ) ; 143 } 144 } 145 else 146 { 147 predicateList .add( predicate ) ; 148 } 149 } 150 151 public boolean replaceChild(Expression oldChild, Expression newChild) 152 { 153 boolean retVal = false; 154 List list = getPredicateList(); 155 156 Expression expr = null ; 157 for (int i = 0; i < list.size(); i++) { 158 expr = (Expression)list.get(i); 159 if (expr.equals(oldChild)) { 160 list.set(i, newChild); 161 newChild.setFather(this); 162 retVal = true; 163 break; 164 } 165 } 166 167 if (getOperand().equals(oldChild)) { 168 setOperand(newChild); 169 retVal = true; 170 } 171 172 return retVal; 173 } 174 175 176 public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException 177 { 178 return visitor.visit(this); 179 } 180 181 public void accept (AlgebraVisitor visitor) throws SqlWrapperException 182 { 183 visitor.visit(this); 184 } 185 186 189 public boolean deepEquals(Object o) 190 { 191 if (o instanceof UnOpRestrict) 192 { 193 UnOpRestrict cast = (UnOpRestrict)o; 194 return super.deepEquals(o) 195 && AlgebraTools.areExprListEquivalent(_predicateList, cast.getPredicateList()); 196 } 197 return false; 198 } 199 200 public boolean isPostResult() { 201 return _postResult; 202 } 203 204 public void setPostResult(boolean b) { 205 _postResult = b; 206 } 207 208 } 209 | Popular Tags |