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