001package com.avaje.ebean; 002 003import com.avaje.ebean.search.Match; 004import com.avaje.ebean.search.MultiMatch; 005import com.avaje.ebean.search.TextCommonTerms; 006import com.avaje.ebean.search.TextQueryString; 007import com.avaje.ebean.search.TextSimple; 008 009import java.util.Collection; 010import java.util.List; 011import java.util.Map; 012 013/** 014 * Expression factory for creating standard expressions. 015 * <p> 016 * Creates standard common expressions for using in a Query Where or Having 017 * clause. 018 * </p> 019 * <p> 020 * You will often not use this class directly but instead just add expressions 021 * via the methods on ExpressionList such as 022 * {@link ExpressionList#gt(String, Object)}. 023 * </p> 024 * <p> 025 * The ExpressionList is returned from {@link Query#where()}. 026 * </p> 027 * 028 * <pre class="code"> 029 * // Example: fetch orders where status equals new or orderDate > lastWeek. 030 * 031 * Expression newOrLastWeek = 032 * Expr.or(Expr.eq("status", Order.Status.NEW), 033 * Expr.gt("orderDate", lastWeek)); 034 * 035 * Query<Order> query = Ebean.createQuery(Order.class); 036 * query.where().add(newOrLastWeek); 037 * List<Order> list = query.findList(); 038 * ... 039 * </pre> 040 * 041 * @see Query#where() 042 */ 043public interface ExpressionFactory { 044 045 /** 046 * Path exists - for the given path in a JSON document. 047 */ 048 Expression jsonExists(String propertyName, String path); 049 050 /** 051 * Path does not exist - for the given path in a JSON document. 052 */ 053 Expression jsonNotExists(String propertyName, String path); 054 055 /** 056 * Equal to - for the given path in a JSON document. 057 */ 058 Expression jsonEqualTo(String propertyName, String path, Object val); 059 060 /** 061 * Not Equal to - for the given path in a JSON document. 062 */ 063 Expression jsonNotEqualTo(String propertyName, String path, Object val); 064 065 /** 066 * Greater than - for the given path in a JSON document. 067 */ 068 Expression jsonGreaterThan(String propertyName, String path, Object val); 069 070 /** 071 * Greater than or equal to - for the given path in a JSON document. 072 */ 073 Expression jsonGreaterOrEqual(String propertyName, String path, Object val); 074 075 /** 076 * Less than - for the given path in a JSON document. 077 */ 078 Expression jsonLessThan(String propertyName, String path, Object val); 079 080 /** 081 * Less than or equal to - for the given path in a JSON document. 082 */ 083 Expression jsonLessOrEqualTo(String propertyName, String path, Object val); 084 085 /** 086 * Between - for the given path in a JSON document. 087 */ 088 Expression jsonBetween(String propertyName, String path, Object lowerValue, Object upperValue); 089 090 /** 091 * Equal To - property equal to the given value. 092 */ 093 Expression eq(String propertyName, Object value); 094 095 /** 096 * Not Equal To - property not equal to the given value. 097 */ 098 Expression ne(String propertyName, Object value); 099 100 /** 101 * Case Insensitive Equal To - property equal to the given value (typically 102 * using a lower() function to make it case insensitive). 103 */ 104 Expression ieq(String propertyName, String value); 105 106 /** 107 * Between - property between the two given values. 108 */ 109 Expression between(String propertyName, Object value1, Object value2); 110 111 /** 112 * Between - value between two given properties. 113 */ 114 Expression betweenProperties(String lowProperty, String highProperty, Object value); 115 116 /** 117 * Greater Than - property greater than the given value. 118 */ 119 Expression gt(String propertyName, Object value); 120 121 /** 122 * Greater Than or Equal to - property greater than or equal to the given 123 * value. 124 */ 125 Expression ge(String propertyName, Object value); 126 127 /** 128 * Less Than - property less than the given value. 129 */ 130 Expression lt(String propertyName, Object value); 131 132 /** 133 * Less Than or Equal to - property less than or equal to the given value. 134 */ 135 Expression le(String propertyName, Object value); 136 137 /** 138 * Is Null - property is null. 139 */ 140 Expression isNull(String propertyName); 141 142 /** 143 * Is Not Null - property is not null. 144 */ 145 Expression isNotNull(String propertyName); 146 147 /** 148 * Case insensitive {@link #exampleLike(Object)} 149 */ 150 ExampleExpression iexampleLike(Object example); 151 152 /** 153 * Create the query by Example expression which is case sensitive and using 154 * LikeType.RAW (you need to add you own wildcards % and _). 155 */ 156 ExampleExpression exampleLike(Object example); 157 158 /** 159 * Create the query by Example expression specifying more options. 160 */ 161 ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType); 162 163 /** 164 * Like - property like value where the value contains the SQL wild card 165 * characters % (percentage) and _ (underscore). 166 */ 167 Expression like(String propertyName, String value); 168 169 /** 170 * Case insensitive Like - property like value where the value contains the 171 * SQL wild card characters % (percentage) and _ (underscore). Typically uses 172 * a lower() function to make the expression case insensitive. 173 */ 174 Expression ilike(String propertyName, String value); 175 176 /** 177 * Starts With - property like value%. 178 */ 179 Expression startsWith(String propertyName, String value); 180 181 /** 182 * Case insensitive Starts With - property like value%. Typically uses a 183 * lower() function to make the expression case insensitive. 184 */ 185 Expression istartsWith(String propertyName, String value); 186 187 /** 188 * Ends With - property like %value. 189 */ 190 Expression endsWith(String propertyName, String value); 191 192 /** 193 * Case insensitive Ends With - property like %value. Typically uses a lower() 194 * function to make the expression case insensitive. 195 */ 196 Expression iendsWith(String propertyName, String value); 197 198 /** 199 * Contains - property like %value%. 200 */ 201 Expression contains(String propertyName, String value); 202 203 /** 204 * Case insensitive Contains - property like %value%. Typically uses a lower() 205 * function to make the expression case insensitive. 206 */ 207 Expression icontains(String propertyName, String value); 208 209 /** 210 * In - property has a value in the array of values. 211 */ 212 Expression in(String propertyName, Object[] values); 213 214 /** 215 * In - using a subQuery. 216 */ 217 Expression in(String propertyName, Query<?> subQuery); 218 219 /** 220 * In - property has a value in the collection of values. 221 */ 222 Expression in(String propertyName, Collection<?> values); 223 224 /** 225 * Not In - property has a value in the array of values. 226 */ 227 Expression notIn(String propertyName, Object[] values); 228 229 /** 230 * Not In - property has a value in the collection of values. 231 */ 232 Expression notIn(String propertyName, Collection<?> values); 233 234 /** 235 * Not In - using a subQuery. 236 */ 237 Expression notIn(String propertyName, Query<?> subQuery); 238 239 /** 240 * Exists expression 241 */ 242 Expression exists(Query<?> subQuery); 243 244 /** 245 * Not exists expression 246 */ 247 Expression notExists(Query<?> subQuery); 248 249 /** 250 * Id Equal to - ID property is equal to the value. 251 */ 252 Expression idEq(Object value); 253 254 /** 255 * Id IN a list of Id values. 256 */ 257 Expression idIn(List<?> idList); 258 259 /** 260 * All Equal - Map containing property names and their values. 261 * <p> 262 * Expression where all the property names in the map are equal to the 263 * corresponding value. 264 * </p> 265 * 266 * @param propertyMap 267 * a map keyed by property names. 268 */ 269 Expression allEq(Map<String, Object> propertyMap); 270 271 /** 272 * Add raw expression with a single parameter. 273 * <p> 274 * The raw expression should contain a single ? at the location of the 275 * parameter. 276 * </p> 277 */ 278 Expression raw(String raw, Object value); 279 280 /** 281 * Add raw expression with an array of parameters. 282 * <p> 283 * The raw expression should contain the same number of ? as there are 284 * parameters. 285 * </p> 286 */ 287 Expression raw(String raw, Object[] values); 288 289 /** 290 * Add raw expression with no parameters. 291 */ 292 Expression raw(String raw); 293 294 /** 295 * Create a Text Match expression (currently doc store/Elastic only). 296 */ 297 Expression textMatch(String propertyName, String search, Match options); 298 299 /** 300 * Create a Text Multi match expression (currently doc store/Elastic only). 301 */ 302 Expression textMultiMatch(String query, MultiMatch options); 303 304 /** 305 * Create a text simple query expression (currently doc store/Elastic only). 306 */ 307 Expression textSimple(String search, TextSimple options); 308 309 /** 310 * Create a text query string expression (currently doc store/Elastic only). 311 */ 312 Expression textQueryString(String search, TextQueryString options); 313 314 /** 315 * Create a text common terms expression (currently doc store/Elastic only). 316 */ 317 Expression textCommonTerms(String search, TextCommonTerms options); 318 319 /** 320 * And - join two expressions with a logical and. 321 */ 322 Expression and(Expression expOne, Expression expTwo); 323 324 /** 325 * Or - join two expressions with a logical or. 326 */ 327 Expression or(Expression expOne, Expression expTwo); 328 329 /** 330 * Negate the expression (prefix it with NOT). 331 */ 332 Expression not(Expression exp); 333 334 /** 335 * Return a list of expressions that will be joined by AND's. 336 */ 337 <T> Junction<T> conjunction(Query<T> query); 338 339 /** 340 * Return a list of expressions that will be joined by OR's. 341 */ 342 <T> Junction<T> disjunction(Query<T> query); 343 344 /** 345 * Return a list of expressions that will be joined by AND's. 346 */ 347 <T> Junction<T> conjunction(Query<T> query, ExpressionList<T> parent); 348 349 /** 350 * Return a list of expressions that will be joined by OR's. 351 */ 352 <T> Junction<T> disjunction(Query<T> query, ExpressionList<T> parent); 353 354 /** 355 * Return a Text query junction for MUST, SHOULD or MUST NOT. 356 * <p> 357 * This is doc store Elastic only. 358 * </p> 359 */ 360 <T> Junction<T> junction(Junction.Type type, Query<T> query, ExpressionList<T> parent); 361 362}