1 19 package org.openharmonise.commons.dsi.dml; 20 21 22 import java.util.*; 23 24 import org.openharmonise.commons.dsi.*; 25 26 35 public class WhereCondition extends Object { 36 37 40 static private final String [] saValidOperators = { 41 "<>", ">", "<", "=", ">=", "<=", "!=", "IN", "CONTAINS", "BETWEEN", 42 "LIKE", "STARTS_WITH", "NOT IN", "NULL", "is", "is not" 43 }; 45 48 private ColumnRef m_colref = null; 49 50 53 private String m_sOp = null; 54 55 58 private List m_value = null; 59 60 63 private JoinConditions m_associated_joins = null; 64 65 72 public WhereCondition(ColumnRef colref, int val) throws DataStoreException { 73 Vector vec = new Vector(); 74 vec.add(new Integer (val)); 75 addColumnRef(colref); 76 addOperator("="); 77 addValue(vec); 78 } 79 80 88 public WhereCondition(ColumnRef colref, String sOp, int val) 89 throws DataStoreException { 90 Vector vec = new Vector(); 91 vec.add(new Integer (val)); 92 addColumnRef(colref); 93 addOperator(sOp); 94 addValue(vec); 95 } 96 97 104 public WhereCondition(ColumnRef colref, Object val) 105 throws DataStoreException { 106 107 Vector vec = new Vector(); 108 vec.add(val); 109 addColumnRef(colref); 110 addOperator("="); 111 addValue(vec); 112 } 113 114 122 public WhereCondition(ColumnRef colref, String sOp, Object val) 123 throws DataStoreException { 124 125 Vector vec = new Vector(); 126 vec.add(val); 127 addColumnRef(colref); 128 addOperator(sOp); 129 addValue(vec); 130 } 131 132 139 public WhereCondition(ColumnRef colref, Vector val) 140 throws DataStoreException { 141 addColumnRef(colref); 142 addOperator("="); 143 addValue(val); 144 } 145 146 154 public WhereCondition(ColumnRef colref, String sOp, List val) 155 throws DataStoreException { 156 boolean bfound = false; 157 158 int i = 0; 160 161 while ((i < saValidOperators.length) && !bfound) { 162 if (sOp.equalsIgnoreCase(saValidOperators[i])) { 163 bfound = true; 164 } 165 166 i++; 167 } 168 169 if (!bfound) { 170 throw new DataStoreException("Invalid Search Operator=" + i + 171 sOp + ":"); 172 } 173 174 m_colref = colref; 175 m_sOp = sOp; 176 m_value = val; 177 } 178 179 184 private void addColumnRef(ColumnRef colref) { 185 m_colref = colref; 186 } 187 188 195 private void addOperator(String sOp) throws DataStoreException { 196 boolean bfound = false; 197 198 int i = 0; 200 201 while ((i < saValidOperators.length) && !bfound) { 202 if (sOp.equalsIgnoreCase(saValidOperators[i])) { 203 bfound = true; 204 } 205 206 i++; 207 } 208 209 if (!bfound) { 210 throw new DataStoreException("Invalid Search Operator=" + i + " - " + sOp); 211 } 212 213 m_sOp = sOp; 214 } 215 216 221 private void addValue(List val) { 222 if(val == null) { 223 m_value = new Vector(); 224 m_value.add(null); 225 } else { 226 m_value = val; 227 } 228 } 229 230 235 public ColumnRef getColumnRef() { 236 return m_colref; 237 } 238 239 244 public String getOperator() { 245 return m_sOp; 246 } 247 248 253 public List getValues() { 254 return m_value; 255 } 256 257 262 public String getColumnName() { 263 return (m_colref.getColumn()); 264 } 265 266 271 public String getTableName() { 272 String sTable = m_colref.getTable(); 273 274 if(m_colref.hasTableAlias() == true) { 275 sTable = m_colref.getTableAlias(); 276 } 277 278 return sTable; 279 } 280 281 286 public String getFullColumnRef() { 287 return (m_colref.getFullRef()); 288 } 289 290 295 public void addAssociatedJoinConditions(JoinConditions joins) { 296 m_associated_joins = joins; 297 } 298 299 304 public JoinConditions getAssociatedJoinConditions() { 305 return m_associated_joins; 306 } 307 } | Popular Tags |