1 19 package org.openharmonise.commons.dsi.dml; 20 21 22 import java.util.*; 23 24 import org.openharmonise.commons.dsi.*; 25 26 41 public class WhereConditionGroup { 42 43 46 private List m_wheres = null; 47 48 51 private String m_sOperator = "and"; 52 53 56 public WhereConditionGroup() { 57 m_wheres = new Vector(16); 58 } 59 60 66 public void setStringingOperator(String sOp) throws DataStoreException { 67 if (sOp.equalsIgnoreCase("and") || sOp.equalsIgnoreCase("or")) { 68 m_sOperator = sOp; 69 } else { 70 throw new DataStoreException("Invalid operator"); 71 } 72 } 73 74 79 public String getStringingOperator() { 80 return m_sOperator; 81 } 82 83 88 public void addCondition(WhereConditionGroup where) { 89 m_wheres.add(where); 90 } 91 92 97 public void addCondition(WhereCondition where) { 98 m_wheres.add(where); 99 } 100 101 108 public Object getCondition(int index) { 109 return (m_wheres.get(index)); 110 } 111 112 120 public boolean isWhereConditionsLeaf(int index) { 121 return (m_wheres.get(index) instanceof WhereCondition); 122 } 123 124 132 public void addCondition(ColumnRef Col1, int i) throws DataStoreException { 133 m_wheres.add(new WhereCondition(Col1, i)); 135 } 136 137 146 public void addCondition(ColumnRef Col1, String sOperator, int i) 147 throws DataStoreException { 148 m_wheres.add(new WhereCondition(Col1, sOperator, i)); 150 } 151 152 160 public void addCondition(ColumnRef Col1, Object obj) 161 throws DataStoreException { 162 m_wheres.add(new WhereCondition(Col1, obj)); 164 } 165 166 175 public void addCondition(ColumnRef Col1, String sOperator, Object obj) 176 throws DataStoreException { 177 m_wheres.add(new WhereCondition(Col1, sOperator, obj)); 179 } 180 181 189 public void addCondition(ColumnRef Col1, List vals) 190 throws DataStoreException { 191 m_wheres.add(new WhereCondition(Col1, vals)); 193 } 194 195 204 public void addCondition(ColumnRef Col1, String sOperator, List vals) 205 throws DataStoreException { 206 m_wheres.add(new WhereCondition(Col1, sOperator, vals)); 208 } 209 210 219 public String getColumnName(int index) throws DataStoreException { 220 if (m_wheres.get(index) instanceof WhereCondition) { 221 return (((WhereCondition) m_wheres.get(index)).getColumnName()); 222 } else { 223 throw new DataStoreException("Invalid Class: " + 224 m_wheres.get(index).getClass() 225 .getName()); 226 } 227 } 228 229 238 public String getTableName(int index) throws DataStoreException { 239 if (m_wheres.get(index) instanceof WhereCondition) { 240 return (((WhereCondition) m_wheres.get(index)).getTableName()); 241 } else { 242 throw new DataStoreException("Invalid Class: " + 243 m_wheres.get(index).getClass() 244 .getName()); 245 } 246 } 247 248 257 public String getFullColumnRef(int index) throws DataStoreException { 258 if (m_wheres.get(index) instanceof WhereCondition) { 259 return (((WhereCondition) m_wheres.get(index)).getFullColumnRef()); 260 } else { 261 throw new DataStoreException("Invalid Class: " + 262 m_wheres.get(index).getClass() 263 .getName()); 264 } 265 } 266 267 276 public String getOperator(int index) throws DataStoreException { 277 if (m_wheres.get(index) instanceof WhereCondition) { 278 return (((WhereCondition) m_wheres.get(index)).getOperator()); 279 } else { 280 throw new DataStoreException("Invalid Class: " + 281 m_wheres.get(index).getClass() 282 .getName()); 283 } 284 } 285 286 295 public List getValues(int index) throws DataStoreException { 296 if (m_wheres.get(index) instanceof WhereCondition) { 297 return ((WhereCondition) m_wheres.get(index)).getValues(); 298 } else { 299 throw new DataStoreException("Invalid Class: " + 300 m_wheres.get(index).getClass() 301 .getName()); 302 } 303 } 304 305 312 public List getTableList() throws DataStoreException { 313 Vector vecr = new Vector(); 314 315 if ((m_wheres == null) || (m_wheres.size() == 0)) { 316 return vecr; 317 } 318 319 for (int i = 0; i < m_wheres.size(); i++) { 320 if (m_wheres.get(i) instanceof WhereCondition) { 321 WhereCondition where = (WhereCondition) m_wheres.get(i); 322 323 if (vecr.contains(where.getTableName()) == false) { 324 vecr.add(where.getTableName()); 325 } 326 } else if (m_wheres.get(i) instanceof WhereConditionGroup) { 327 WhereConditionGroup wheres = (WhereConditionGroup) m_wheres.get(i); 328 List tables = wheres.getTableList(); 329 330 Iterator iter = tables.iterator(); 331 332 while (iter.hasNext()) { 333 String sTableName = (String ) iter.next(); 334 vecr.add(sTableName); 335 } 336 } 337 } 338 339 return vecr; 340 } 341 342 349 public int size() { 350 return (m_wheres.size()); 351 } 352 353 357 public void empty() { 358 if (m_wheres != null) { 359 m_wheres.clear(); 360 } 361 } 362 363 369 public List getColumnRefs() { 370 Vector cols = new Vector(); 371 372 Iterator iter = m_wheres.iterator(); 373 374 while(iter.hasNext()) { 375 Object where = iter.next(); 376 377 if(where instanceof WhereCondition) { 378 cols.add(((WhereCondition)where).getColumnRef()); 379 } else if(where instanceof WhereConditionGroup) { 380 cols.addAll(((WhereConditionGroup)where).getColumnRefs()); 381 } 382 } 383 384 return cols; 385 } 386 } | Popular Tags |