All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avaje.ebean.ExpressionList Maven / Gradle / Ivy

The newest version!
package com.avaje.ebean;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * List of Expressions that make up a where or having clause.
 * 

* An ExpressionList is returned from {@link Query#where()}. *

*

* The ExpressionList has a list of convenience methods that create the standard * expressions and add them to this list. *

*

* The ExpressionList also duplicates methods that are found on the Query such * as findList() and orderBy(). The purpose of these methods is provide a fluid * API. The upside of this approach is that you can build and execute a query * via chained methods. The down side is that this ExpressionList object has * more methods than you would initially expect (the ones duplicated from * Query). *

* * @see Query#where() */ public interface ExpressionList extends Serializable { /** * Return the query that owns this expression list. *

* This is a convenience method solely to support a fluid API where the * methods are chained together. Adding expressions returns this expression * list and this method can be used after that to return back the original * query so that further things can be added to it. *

*/ public Query query(); /** * Set the order by clause replacing the existing order by clause if there is * one. *

* This follows SQL syntax using commas between each property with the * optional asc and desc keywords representing ascending and descending order * respectively. *

*

* This is EXACTLY the same as {@link #orderBy(String)}. *

*/ public Query order(String orderByClause); /** * Return the OrderBy so that you can append an ascending or descending * property to the order by clause. *

* This will never return a null. If no order by clause exists then an 'empty' * OrderBy object is returned. *

*/ public OrderBy order(); /** * Return the OrderBy so that you can append an ascending or descending * property to the order by clause. *

* This will never return a null. If no order by clause exists then an 'empty' * OrderBy object is returned. *

*/ public OrderBy orderBy(); /** * Add an orderBy clause to the query. * * @see Query#orderBy(String) */ public Query orderBy(String orderBy); /** * Add an orderBy clause to the query. * * @see Query#orderBy(String) */ public Query setOrderBy(String orderBy); /** * Execute the query iterating over the results. * * @see Query#findIterate() */ public QueryIterator findIterate(); /** * Execute the query visiting the results. * * @see Query#findVisit(QueryResultVisitor) */ public void findVisit(QueryResultVisitor visitor); /** * Execute the query returning a list. * * @see Query#findList() */ public List findList(); /** * Execute the query returning the list of Id's. * * @see Query#findIds() */ public List findIds(); /** * Return the count of entities this query should return. *

* This is the number of 'top level' or 'root level' entities. *

*/ public int findRowCount(); /** * Execute the query returning a set. * * @see Query#findSet() */ public Set findSet(); /** * Execute the query returning a map. * * @see Query#findMap() */ public Map findMap(); /** * Return a typed map specifying the key property and type. */ public Map findMap(String keyProperty, Class keyType); /** * Execute the query returning a single bean. * * @see Query#findUnique() */ public T findUnique(); /** * Execute find row count query in a background thread. *

* This returns a Future object which can be used to cancel, check the * execution status (isDone etc) and get the value (with or without a * timeout). *

* * @return a Future object for the row count query */ public FutureRowCount findFutureRowCount(); /** * Execute find Id's query in a background thread. *

* This returns a Future object which can be used to cancel, check the * execution status (isDone etc) and get the value (with or without a * timeout). *

* * @return a Future object for the list of Id's */ public FutureIds findFutureIds(); /** * Execute find list query in a background thread. *

* This returns a Future object which can be used to cancel, check the * execution status (isDone etc) and get the value (with or without a * timeout). *

* * @return a Future object for the list result of the query */ public FutureList findFutureList(); /** * Return a PagingList for this query. *

* This can be used to break up a query into multiple queries to fetch the * data a page at a time. *

*

* This typically works by using a query per page and setting * {@link Query#setFirstRow(int)} and and {@link Query#setMaxRows(int)} on the * query. This usually would translate into SQL that uses limit offset, rownum * or row_number function to limit the result set. *

* * @param pageSize * the number of beans fetched per Page * */ public PagingList findPagingList(int pageSize); public ExpressionList filterMany(String prop); /** * Specify specific properties to fetch on the main/root bean (aka partial * object). * * @see Query#select(String) */ public Query select(String properties); /** * Specify a property (associated bean) to join and fetch including * all its properties. * * @see Query#join(String) */ public Query join(String assocProperties); /** * Specify a property (associated bean) to join and fetch with its * specific properties to include (aka partial object). * * @see Query#join(String,String) */ public Query join(String assocProperty, String assocProperties); /** * Set the first row to fetch. * * @see Query#setFirstRow(int) */ public Query setFirstRow(int firstRow); /** * Set the maximum number of rows to fetch. * * @see Query#setMaxRows(int) */ public Query setMaxRows(int maxRows); /** * Set the number of rows after which the fetching should continue in a * background thread. * * @see Query#setBackgroundFetchAfter(int) */ public Query setBackgroundFetchAfter(int backgroundFetchAfter); /** * Set the name of the property which values become the key of a map. * * @see Query#setMapKey(String) */ public Query setMapKey(String mapKey); /** * Set a QueryListener for bean by bean processing. * * @see Query#setListener(QueryListener) */ public Query setListener(QueryListener queryListener); /** * Set to true to use the query for executing this query. * * @see Query#setUseCache(boolean) */ public Query setUseCache(boolean useCache); /** * Add expressions to the having clause. *

* The having clause is only used for queries based on raw sql (via SqlSelect * annotation etc). *

*/ public ExpressionList having(); /** * Add another expression to the where clause. */ public ExpressionList where(); /** * Add an Expression to the list. *

* This returns the list so that add() can be chained. *

* *
   * Query<Customer> query = Ebean.createQuery(Customer.class);
   * query.where()
   *     .like("name","Rob%")
   *     .eq("status", Customer.ACTIVE);
   * List<Customer> list = query.findList();
   * ...
   * 
*/ public ExpressionList add(Expression expr); /** * Add a list of Expressions to this ExpressionList.s */ public ExpressionList addAll(ExpressionList exprList); /** * Equal To - property is equal to a given value. */ public ExpressionList eq(String propertyName, Object value); /** * Not Equal To - property not equal to the given value. */ public ExpressionList ne(String propertyName, Object value); /** * Case Insensitive Equal To - property equal to the given value (typically * using a lower() function to make it case insensitive). */ public ExpressionList ieq(String propertyName, String value); /** * Between - property between the two given values. */ public ExpressionList between(String propertyName, Object value1, Object value2); /** * Between - value between the two properties. */ public ExpressionList betweenProperties(String lowProperty, String highProperty, Object value); /** * Greater Than - property greater than the given value. */ public ExpressionList gt(String propertyName, Object value); /** * Greater Than or Equal to - property greater than or equal to the given * value. */ public ExpressionList ge(String propertyName, Object value); /** * Less Than - property less than the given value. */ public ExpressionList lt(String propertyName, Object value); /** * Less Than or Equal to - property less than or equal to the given value. */ public ExpressionList le(String propertyName, Object value); /** * Is Null - property is null. */ public ExpressionList isNull(String propertyName); /** * Is Not Null - property is not null. */ public ExpressionList isNotNull(String propertyName); /** * A "Query By Example" type of expression. *

* Pass in an example entity and for each non-null scalar properties an * expression is added. *

*

* By Default this case sensitive, will ignore numeric zero values and will * use a Like for string values (you must put in your own wildcards). *

*

* To get control over the options you can create an ExampleExpression and set * those options such as case insensitive etc. *

* *
   * // create an example bean and set the properties
   * // with the query parameters you want
   * Customer example = new Customer();
   * example.setName("Rob%");
   * example.setNotes("%something%");
   * 
   * List<Customer> list = Ebean.find(Customer.class).where()
   *     // pass the bean into the where() clause
   *     .exampleLike(example)
   *     // you can add other expressions to the same query
   *     .gt("id", 2).findList();
   * 
   * 
* * Similarly you can create an ExampleExpression * *
   * Customer example = new Customer();
   * example.setName("Rob%");
   * example.setNotes("%something%");
   * 
   * // create a ExampleExpression with more control
   * ExampleExpression qbe = new ExampleExpression(example, true, LikeType.EQUAL_TO).includeZeros();
   * 
   * List<Customer> list = Ebean.find(Customer.class).where().add(qbe).findList();
   * 
*/ public ExpressionList exampleLike(Object example); /** * Case insensitive version of {@link #exampleLike(Object)} */ public ExpressionList iexampleLike(Object example); /** * Like - property like value where the value contains the SQL wild card * characters % (percentage) and _ (underscore). */ public ExpressionList like(String propertyName, String value); /** * Case insensitive Like - property like value where the value contains the * SQL wild card characters % (percentage) and _ (underscore). Typically uses * a lower() function to make the expression case insensitive. */ public ExpressionList ilike(String propertyName, String value); /** * Starts With - property like value%. */ public ExpressionList startsWith(String propertyName, String value); /** * Case insensitive Starts With - property like value%. Typically uses a * lower() function to make the expression case insensitive. */ public ExpressionList istartsWith(String propertyName, String value); /** * Ends With - property like %value. */ public ExpressionList endsWith(String propertyName, String value); /** * Case insensitive Ends With - property like %value. Typically uses a lower() * function to make the expression case insensitive. */ public ExpressionList iendsWith(String propertyName, String value); /** * Contains - property like %value%. */ public ExpressionList contains(String propertyName, String value); /** * Case insensitive Contains - property like %value%. Typically uses a lower() * function to make the expression case insensitive. */ public ExpressionList icontains(String propertyName, String value); /** * In - using a subQuery. */ public ExpressionList in(String propertyName, Query subQuery); /** * In - property has a value in the array of values. */ public ExpressionList in(String propertyName, Object... values); /** * In - property has a value in the collection of values. */ public ExpressionList in(String propertyName, Collection values); /** * Id IN a list of id values. */ public ExpressionList idIn(List idValues); /** * Id Equal to - ID property is equal to the value. */ public ExpressionList idEq(Object value); /** * All Equal - Map containing property names and their values. *

* Expression where all the property names in the map are equal to the * corresponding value. *

* * @param propertyMap * a map keyed by property names. */ public ExpressionList allEq(Map propertyMap); /** * Add raw expression with a single parameter. *

* The raw expression should contain a single ? at the location of the * parameter. *

*

* When properties in the clause are fully qualified as table-column names * then they are not translated. logical property name names (not fully * qualified) will still be translated to their physical name. *

*/ public ExpressionList raw(String raw, Object value); /** * Add raw expression with an array of parameters. *

* The raw expression should contain the same number of ? as there are * parameters. *

*

* When properties in the clause are fully qualified as table-column names * then they are not translated. logical property name names (not fully * qualified) will still be translated to their physical name. *

*/ public ExpressionList raw(String raw, Object[] values); /** * Add raw expression with no parameters. *

* When properties in the clause are fully qualified as table-column names * then they are not translated. logical property name names (not fully * qualified) will still be translated to their physical name. *

*/ public ExpressionList raw(String raw); /** * And - join two expressions with a logical and. */ public ExpressionList and(Expression expOne, Expression expTwo); /** * Or - join two expressions with a logical or. */ public ExpressionList or(Expression expOne, Expression expTwo); /** * Negate the expression (prefix it with NOT). */ public ExpressionList not(Expression exp); /** * Return a list of expressions that will be joined by AND's. */ public Junction conjunction(); /** * Return a list of expressions that will be joined by OR's. */ public Junction disjunction(); /** * End a Conjunction or Disjunction returning the parent expression list. *

* Alternatively you can always use where() to return the top level expression * list. *

*/ public ExpressionList endJunction(); }