1 package org.apache.ojb.broker.query; 2 3 17 18 import java.util.List ; 19 import java.util.Map ; 20 21 34 public abstract class SelectionCriteria implements java.io.Serializable 35 { 36 static final long serialVersionUID = -5194901539702756536L; protected static final String EQUAL = " = "; 37 protected static final String NOT_EQUAL = " <> "; 38 protected static final String GREATER = " > "; 39 protected static final String NOT_GREATER = " <= "; 40 protected static final String LESS = " < "; 41 protected static final String NOT_LESS = " >= "; 42 protected static final String LIKE = " LIKE "; 43 protected static final String NOT_LIKE = " NOT LIKE "; 44 protected static final String IS_NULL = " IS NULL "; 45 protected static final String NOT_IS_NULL = " IS NOT NULL "; 46 protected static final String BETWEEN = " BETWEEN "; 47 protected static final String NOT_BETWEEN = " NOT BETWEEN "; 48 protected static final String IN = " IN "; 49 protected static final String NOT_IN = " NOT IN "; 50 51 private Object m_attribute; 52 private Object m_value; 53 54 55 private boolean m_bound = false; 57 58 private int m_numberOfExtentsToBind = 0; 60 61 private String m_alias = null; 62 private UserAlias m_userAlias = null; 63 64 private boolean m_translateAttribute = true; 66 67 private Criteria m_criteria; 68 69 77 SelectionCriteria(Object anAttribute, Object aValue, String alias) 78 { 79 if (!(anAttribute instanceof String || anAttribute instanceof Query)) 80 { 81 throw new IllegalArgumentException ("An attribute must be a String or a Query !"); 82 } 83 84 m_attribute = anAttribute; 85 m_value = aValue; 86 this.m_bound = !isBindable(); 87 this.m_alias = alias; 88 this.m_userAlias = m_alias == null ? null : new UserAlias(m_alias, (String )getAttribute(), true); 89 } 90 91 98 SelectionCriteria(Object anAttribute, Object aValue, UserAlias aUserAlias) 99 { 100 if (!(anAttribute instanceof String || anAttribute instanceof Query)) 101 { 102 throw new IllegalArgumentException ("An attribute must be a String or a Query !"); 103 } 104 105 m_attribute = anAttribute; 106 m_value = aValue; 107 this.m_bound = !isBindable(); 108 this.m_userAlias = aUserAlias; 109 this.m_alias = m_userAlias == null ? null : m_userAlias.getName(); 110 } 111 112 115 abstract public String getClause(); 116 117 120 public void bind(Object newValue) 121 { 122 setValue(newValue); 123 setBound(true); 124 } 125 126 129 public Object getValue() 130 { 131 return m_value; 132 } 133 134 137 public Object getAttribute() 138 { 139 return m_attribute; 140 } 141 142 145 public String toString() 146 { 147 return m_attribute + getClause() + m_value; 148 } 149 150 154 public boolean isBound() 155 { 156 return m_bound; 157 } 158 159 163 protected void setBound(boolean bound) 164 { 165 this.m_bound = bound; 166 } 167 168 172 protected void setValue(Object value) 173 { 174 this.m_value = value; 175 } 176 177 181 protected boolean isBindable() 182 { 183 return (getValue() == null); 184 } 185 189 public int getNumberOfExtentsToBind() 190 { 191 return m_numberOfExtentsToBind; 192 } 193 194 198 public void setNumberOfExtentsToBind(int numberOfExtentsToBind) 199 { 200 this.m_numberOfExtentsToBind = numberOfExtentsToBind; 201 } 202 203 206 public String getAlias() 207 { 208 return m_alias; 209 } 210 211 215 public void setAlias(String alias) 216 { 217 m_alias = alias; 218 String attributePath = (String )getAttribute(); 219 boolean allPathsAliased = true; 220 m_userAlias = new UserAlias(alias, attributePath, allPathsAliased); 221 222 } 223 224 228 public void setAlias(String alias, String aliasPath) 229 { 230 m_alias = alias; 231 m_userAlias = new UserAlias(alias, (String )getAttribute(), aliasPath); 232 } 233 234 238 public void setAlias(UserAlias userAlias) 239 { 240 m_alias = userAlias.getName(); 241 m_userAlias = userAlias; 242 } 243 244 public UserAlias getUserAlias() 245 { 246 return m_userAlias; 247 } 248 251 public boolean isTranslateAttribute() 252 { 253 return m_translateAttribute; 254 } 255 256 259 void setTranslateAttribute(boolean b) 260 { 261 m_translateAttribute = b; 262 } 263 264 267 public Criteria getCriteria() 268 { 269 return m_criteria; 270 } 271 272 275 void setCriteria(Criteria criteria) 276 { 277 m_criteria = criteria; 278 } 279 280 public QueryByCriteria getQuery() 281 { 282 if (getCriteria() != null) 283 { 284 return getCriteria().getQuery(); 285 } 286 else 287 { 288 return null; 289 } 290 } 291 292 297 public Map getPathClasses() 298 { 299 return getCriteria().getPathClasses(); 300 } 301 302 309 public List getClassesForPath(String aPath) 310 { 311 return getCriteria().getClassesForPath(aPath); 312 } 313 } 314 | Popular Tags |