1 15 package org.josql.expressions; 16 17 import java.util.List ; 18 import java.util.ArrayList ; 19 20 import org.josql.Query; 21 import org.josql.QueryExecutionException; 22 import org.josql.QueryParseException; 23 24 import org.josql.internal.Utilities; 25 26 33 public class BetweenExpression extends BinaryExpression 34 { 35 36 private ValueExpression start = null; 37 private ValueExpression end = null; 38 private boolean not = false; 39 private boolean leftFR = false; 40 private boolean startFR = false; 41 private boolean endFR = false; 42 private Object leftFRVal = null; 43 private Object startFRVal = null; 44 private Object endFRVal = null; 45 46 52 public void init (Query q) 53 throws QueryParseException 54 { 55 56 this.left.init (q); 57 58 this.start.init (q); 59 this.end.init (q); 60 61 this.leftFR = this.left.hasFixedResult (q); 62 this.startFR = this.start.hasFixedResult (q); 63 this.endFR = this.end.hasFixedResult (q); 64 65 } 66 67 72 public Expression getStart () 73 { 74 75 return this.start; 76 77 } 78 79 84 public Expression getEnd () 85 { 86 87 return this.end; 88 89 } 90 91 public void setEnd (ValueExpression e) 92 { 93 94 this.end = e; 95 96 } 97 98 public void setStart (ValueExpression s) 99 { 100 101 this.start = s; 102 103 } 104 105 public boolean isNot () 106 { 107 108 return this.not; 109 110 } 111 112 public void setNot (boolean v) 113 { 114 115 this.not = v; 116 117 } 118 119 130 public boolean isTrue (Object o, 131 Query q) 132 throws QueryExecutionException 133 { 134 135 Object l = null; 136 137 if (this.leftFR) 138 { 139 140 if (this.leftFRVal == null) 141 { 142 143 l = this.left.getValue (o, 144 q); 145 146 this.leftFRVal = l; 147 148 } else { 149 150 l = this.leftFRVal; 151 152 } 153 154 } else { 155 156 l = this.left.getValue (o, 157 q); 158 159 if (this.leftFR) 160 { 161 162 this.leftFRVal = l; 163 164 } 165 166 } 167 168 Object s = null; 169 170 if (this.startFR) 171 { 172 173 if (this.startFRVal == null) 174 { 175 176 s = this.start.getValue (o, 177 q); 178 179 this.startFRVal = s; 180 181 } else { 182 183 s = this.startFRVal; 184 185 } 186 187 } else { 188 189 s = this.start.getValue (o, 190 q); 191 192 if (this.startFR) 193 { 194 195 this.startFRVal = s; 196 197 } 198 199 } 200 201 Object e = null; 202 203 if (this.endFR) 204 { 205 206 if (this.endFRVal == null) 207 { 208 209 e = this.end.getValue (o, 210 q); 211 212 this.endFRVal = e; 213 214 } else { 215 216 e = this.endFRVal; 217 218 } 219 220 } else { 221 222 e = this.end.getValue (o, 223 q); 224 225 if (this.endFR) 226 { 227 228 this.endFRVal = e; 229 230 } 231 232 } 233 234 boolean sb = Utilities.isGTEquals (l, 236 s); 237 238 boolean eb = Utilities.isLTEquals (l, 239 e); 240 241 if (!this.not 242 && 243 sb 244 && 245 eb 246 ) 247 { 248 249 return true; 250 251 } 252 253 if (this.not 254 && 255 (!sb 256 || 257 !eb 258 ) 259 ) 260 { 261 262 return true; 263 264 } 265 266 return false; 267 268 } 269 270 280 public String toString () 281 { 282 283 StringBuffer buf = new StringBuffer (this.left.toString ()); 284 285 if (this.not) 286 { 287 288 buf.append (" NOT"); 289 290 } 291 292 buf.append (" BETWEEN "); 293 294 buf.append (this.start); 295 buf.append (" AND "); 296 buf.append (this.end); 297 298 if (this.isBracketed ()) 299 { 300 301 buf.insert (0, 302 "("); 303 304 buf.append (")"); 305 306 } 307 308 return buf.toString (); 309 310 } 311 312 } 313
| Popular Tags
|