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(&quot;status&quot;, Order.Status.NEW), 
033 *           Expr.gt(&quot;orderDate&quot;, lastWeek));
034 * 
035 * Query&lt;Order&gt; query = Ebean.createQuery(Order.class);
036 * query.where().add(newOrLastWeek);
037 * List&lt;Order&gt; 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   * Array contains all the given values.
092   * <p>
093   * Array support is effectively limited to Postgres at this time.
094   * </p>
095   */
096  Expression arrayContains(String propertyName, Object... values);
097
098  /**
099   * Array does not contain the given values.
100   * <p>
101   * Array support is effectively limited to Postgres at this time.
102   * </p>
103   */
104  Expression arrayNotContains(String propertyName, Object... values);
105
106  /**
107   * Array is empty - for the given array property.
108   * <p>
109   * Array support is effectively limited to Postgres at this time.
110   * </p>
111   */
112  Expression arrayIsEmpty(String propertyName);
113
114  /**
115   * Array is not empty - for the given array property.
116   * <p>
117   * Array support is effectively limited to Postgres at this time.
118   * </p>
119   */
120  Expression arrayIsNotEmpty(String propertyName);
121
122  /**
123   * Equal To - property equal to the given value.
124   */
125  Expression eq(String propertyName, Object value);
126
127  /**
128   * Not Equal To - property not equal to the given value.
129   */
130  Expression ne(String propertyName, Object value);
131
132  /**
133   * Case Insensitive Equal To - property equal to the given value (typically
134   * using a lower() function to make it case insensitive).
135   */
136  Expression ieq(String propertyName, String value);
137
138  /**
139   * Case Insensitive Equal To that allows for named parameter use.
140   */
141  Expression ieqObject(String propertyName, Object value);
142
143  /**
144   * Between - property between the two given values.
145   */
146  Expression between(String propertyName, Object value1, Object value2);
147
148  /**
149   * Between - value between two given properties.
150   */
151  Expression betweenProperties(String lowProperty, String highProperty, Object value);
152
153  /**
154   * Greater Than - property greater than the given value.
155   */
156  Expression gt(String propertyName, Object value);
157
158  /**
159   * Greater Than or Equal to - property greater than or equal to the given
160   * value.
161   */
162  Expression ge(String propertyName, Object value);
163
164  /**
165   * Less Than - property less than the given value.
166   */
167  Expression lt(String propertyName, Object value);
168
169  /**
170   * Less Than or Equal to - property less than or equal to the given value.
171   */
172  Expression le(String propertyName, Object value);
173
174  /**
175   * Is Null - property is null.
176   */
177  Expression isNull(String propertyName);
178
179  /**
180   * Is Not Null - property is not null.
181   */
182  Expression isNotNull(String propertyName);
183
184  /**
185   * Case insensitive {@link #exampleLike(Object)}
186   */
187  ExampleExpression iexampleLike(Object example);
188
189  /**
190   * Create the query by Example expression which is case sensitive and using
191   * LikeType.RAW (you need to add you own wildcards % and _).
192   */
193  ExampleExpression exampleLike(Object example);
194
195  /**
196   * Create the query by Example expression specifying more options.
197   */
198  ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType);
199
200  /**
201   * Like with support for named parameters.
202   */
203  Expression like(String propertyName, Object value, boolean caseInsensitive, LikeType likeType);
204
205  /**
206   * Like - property like value where the value contains the SQL wild card
207   * characters % (percentage) and _ (underscore).
208   */
209  Expression like(String propertyName, String value);
210
211  /**
212   * Case insensitive Like - property like value where the value contains the
213   * SQL wild card characters % (percentage) and _ (underscore). Typically uses
214   * a lower() function to make the expression case insensitive.
215   */
216  Expression ilike(String propertyName, String value);
217
218  /**
219   * Starts With - property like value%.
220   */
221  Expression startsWith(String propertyName, String value);
222
223  /**
224   * Case insensitive Starts With - property like value%. Typically uses a
225   * lower() function to make the expression case insensitive.
226   */
227  Expression istartsWith(String propertyName, String value);
228
229  /**
230   * Ends With - property like %value.
231   */
232  Expression endsWith(String propertyName, String value);
233
234  /**
235   * Case insensitive Ends With - property like %value. Typically uses a lower()
236   * function to make the expression case insensitive.
237   */
238  Expression iendsWith(String propertyName, String value);
239
240  /**
241   * Contains - property like %value%.
242   */
243  Expression contains(String propertyName, String value);
244
245  /**
246   * Case insensitive Contains - property like %value%. Typically uses a lower()
247   * function to make the expression case insensitive.
248   */
249  Expression icontains(String propertyName, String value);
250
251  /**
252   * In - property has a value in the array of values.
253   */
254  Expression in(String propertyName, Object[] values);
255
256  /**
257   * In - using a subQuery.
258   */
259  Expression in(String propertyName, Query<?> subQuery);
260
261  /**
262   * In - property has a value in the collection of values.
263   */
264  Expression in(String propertyName, Collection<?> values);
265
266  /**
267   * Not In - property has a value in the array of values.
268   */
269  Expression notIn(String propertyName, Object[] values);
270
271  /**
272   * Not In - property has a value in the collection of values.
273   */
274  Expression notIn(String propertyName, Collection<?> values);
275
276  /**
277   * Not In - using a subQuery.
278   */
279  Expression notIn(String propertyName, Query<?> subQuery);
280
281  /**
282   * Exists expression
283   */
284  Expression exists(Query<?> subQuery);
285  
286  /**
287   * Not exists expression
288   */
289  Expression notExists(Query<?> subQuery);
290
291  /**
292   * Is empty expression for collection properties.
293   */
294  Expression isEmpty(String propertyName);
295
296  /**
297   * Is not empty expression for collection properties.
298   */
299  Expression isNotEmpty(String propertyName);
300
301  /**
302   * Id Equal to - ID property is equal to the value.
303   */
304  Expression idEq(Object value);
305
306  /**
307   * Id IN a list of Id values.
308   */
309  Expression idIn(Object... idValues);
310
311  /**
312   * Id IN a list of Id values.
313   */
314  Expression idIn(List<?> idList);
315
316  /**
317   * All Equal - Map containing property names and their values.
318   * <p>
319   * Expression where all the property names in the map are equal to the
320   * corresponding value.
321   * </p>
322   * 
323   * @param propertyMap
324   *          a map keyed by property names.
325   */
326  Expression allEq(Map<String, Object> propertyMap);
327
328  /**
329   * Add raw expression with a single parameter.
330   * <p>
331   * The raw expression should contain a single ? at the location of the
332   * parameter.
333   * </p>
334   */
335  Expression raw(String raw, Object value);
336
337  /**
338   * Add raw expression with an array of parameters.
339   * <p>
340   * The raw expression should contain the same number of ? as there are
341   * parameters.
342   * </p>
343   */
344  Expression raw(String raw, Object[] values);
345
346  /**
347   * Add raw expression with no parameters.
348   */
349  Expression raw(String raw);
350
351  /**
352   * Create a Text Match expression (currently doc store/Elastic only).
353   */
354  Expression textMatch(String propertyName, String search, Match options);
355
356  /**
357   * Create a Text Multi match expression (currently doc store/Elastic only).
358   */
359  Expression textMultiMatch(String query, MultiMatch options);
360
361  /**
362   * Create a text simple query expression (currently doc store/Elastic only).
363   */
364  Expression textSimple(String search, TextSimple options);
365
366  /**
367   * Create a text query string expression (currently doc store/Elastic only).
368   */
369  Expression textQueryString(String search, TextQueryString options);
370
371  /**
372   * Create a text common terms expression (currently doc store/Elastic only).
373   */
374  Expression textCommonTerms(String search, TextCommonTerms options);
375
376  /**
377   * And - join two expressions with a logical and.
378   */
379  Expression and(Expression expOne, Expression expTwo);
380
381  /**
382   * Or - join two expressions with a logical or.
383   */
384  Expression or(Expression expOne, Expression expTwo);
385
386  /**
387   * Negate the expression (prefix it with NOT).
388   */
389  Expression not(Expression exp);
390
391  /**
392   * Return a list of expressions that will be joined by AND's.
393   */
394  <T> Junction<T> conjunction(Query<T> query);
395
396  /**
397   * Return a list of expressions that will be joined by OR's.
398   */
399  <T> Junction<T> disjunction(Query<T> query);
400
401  /**
402   * Return a list of expressions that will be joined by AND's.
403   */
404  <T> Junction<T> conjunction(Query<T> query, ExpressionList<T> parent);
405
406  /**
407   * Return a list of expressions that will be joined by OR's.
408   */
409  <T> Junction<T> disjunction(Query<T> query, ExpressionList<T> parent);
410
411  /**
412   * Return a Text query junction for MUST, SHOULD or MUST NOT.
413   * <p>
414   * This is doc store Elastic only.
415   * </p>
416   */
417  <T> Junction<T> junction(Junction.Type type, Query<T> query, ExpressionList<T> parent);
418
419}