diff --git a/src/main/java/com/avaje/ebean/ExpressionList.java b/src/main/java/com/avaje/ebean/ExpressionList.java index 1f862c1d1..e5ab15654 100644 --- a/src/main/java/com/avaje/ebean/ExpressionList.java +++ b/src/main/java/com/avaje/ebean/ExpressionList.java @@ -889,52 +889,165 @@ public interface ExpressionList { ExpressionList not(Expression exp); /** - * Return a list of expressions that will be joined by AND's. + * Start a list of expressions that will be joined by AND's + * returning the expression list the expressions are added to. + *

* This is exactly the same as conjunction(); + *

+ *

+ * Use endJunction() to end the AND junction. + *

+ *

+ * Note that a where() clause defaults to an AND junction so + * typically you only explicitly need to use the and() junction + * when it is nested inside an or() or not() junction. + *

+ * + *
{@code
+   *
+   *  // Example: Nested and()
+   *
+   *  Ebean.find(Customer.class)
+   *    .where()
+   *    .or()
+   *      .and() // nested and
+   *        .startsWith("name", "r")
+   *        .eq("anniversary", onAfter)
+   *        .endJunction() // end AND junction
+   *      .and()
+   *        .eq("status", Customer.Status.ACTIVE)
+   *        .gt("id", 0)
+   *        .endJunction() // end AND junction
+   *      .orderBy().asc("name")
+   *      .findList();
+   * }
*/ Junction and(); /** * Return a list of expressions that will be joined by OR's. * This is exactly the same as disjunction(); + * + *

+ * Use endJunction() to end the OR junction. + *

+ * + *
{@code
+   *
+   *  // Example: Use or() to join
+   *  // two nested and() expressions
+   *
+   *  Ebean.find(Customer.class)
+   *    .where()
+   *    .or()
+   *      .and()
+   *        .startsWith("name", "r")
+   *        .eq("anniversary", onAfter)
+   *        .endJunction() // end AND junction
+   *      .and()
+   *        .eq("status", Customer.Status.ACTIVE)
+   *        .gt("id", 0)
+   *        .endJunction() // end AND junction
+   *      .orderBy().asc("name")
+   *      .findList();
+   *
+   * }
*/ Junction or(); /** * Return a list of expressions that will be wrapped by NOT. + *

+ * Use endJunction() to end expressions being added to the + * NOT expression list. + *

+ * + *
@{code
+   *
+   *    .where()
+   *      .not()
+   *        .gt("id", 1)
+   *        .eq("anniversary", onAfter)
+   *        .endJunction() // end the not expressions
+   *
+   * }
+ * + *
@{code
+   *
+   * // Example: nested not()
+   *
+   * Ebean.find(Customer.class)
+   *   .where()
+   *     .eq("status", Customer.Status.ACTIVE)
+   *     .not()
+   *       .gt("id", 1)
+   *       .eq("anniversary", onAfter)
+   *       .endJunction() // end the not expressions
+   *     .orderBy()
+   *       .asc("name")
+   *     .findList();
+   *
+   * }
*/ Junction not(); /** - * Return a list of expressions that will be joined by AND's. + * Start (and return) a list of expressions that will be joined by AND's. + *

+ * This is the same as and(). + *

*/ Junction conjunction(); /** - * Return a list of expressions that will be joined by OR's. + * Start (and return) a list of expressions that will be joined by OR's. + *

+ * This is the same as or(). + *

*/ Junction disjunction(); /** * Start a list of expressions that will be joined by MUST. + *

+ * This automatically makes the query a useDocStore(true) query that + * will execute against the document store (ElasticSearch etc). + *

+ *

+ * This is logically similar to and(). + *

*/ Junction must(); /** * Start a list of expressions that will be joined by SHOULD. + *

+ * This automatically makes the query a useDocStore(true) query that + * will execute against the document store (ElasticSearch etc). + *

+ *

+ * This is logically similar to or(). + *

*/ Junction should(); /** * Start a list of expressions that will be joined by MUST NOT. + *

+ * This automatically makes the query a useDocStore(true) query that + * will execute against the document store (ElasticSearch etc). + *

+ *

+ * This is logically similar to not(). + *

*/ Junction mustNot(); /** * End a junction returning the parent expression list. *

- * Ends a and(), or(), not(), must(), mustNot() or should() junction - * such that you get the parent expression. + * Ends a and(), or(), not(), must(), mustNot() or should() junction + * such that you get the parent expression. *

*

* Alternatively you can always use where() to return the top level expression list. diff --git a/src/main/java/com/avaje/ebean/Junction.java b/src/main/java/com/avaje/ebean/Junction.java index 06af1586b..f7b233998 100644 --- a/src/main/java/com/avaje/ebean/Junction.java +++ b/src/main/java/com/avaje/ebean/Junction.java @@ -13,12 +13,13 @@ package com.avaje.ebean; *

{@code
  * Query q =
  *     Ebean.find(Person.class)
- *         .where().disjunction()
- *         .like("name", "Rob%")
- *         .eq("status", Status.NEW)
+ *       .where()
+ *         .or()
+ *           .like("name", "Rob%")
+ *           .eq("status", Status.NEW)
  *
- *         // where() returns us to the top level expression list
- *         .where().gt("id", 10);
+ *       // where() returns us to the top level expression list
+ *       .where().gt("id", 10);
  *
  * // read as...
  * // where ( ((name like Rob%) or (status = NEW)) AND (id > 10) )
@@ -31,18 +32,19 @@ package com.avaje.ebean;
  * 
{@code
  * Query q =
  *     Ebean.find(Person.class)
- *         .where().disjunction()
- *         .like("name", "Rob%")
- *         .eq("status", Status.NEW)
- *         .endJunction()
+ *       .where()
+ *         .or()
+ *           .like("name", "Rob%")
+ *           .eq("status", Status.NEW)
+ *           .endJunction()
  *
- *         // endJunction().. takes us to the 'parent' expression list
- *         // which in this case is the top level (same as where())
+ *           // endJunction().. takes us to the 'parent' expression list
+ *           // which in this case is the top level (same as where())
  *
  *         .gt("id", 10);
  *
  * // read as...
- * // where ( ((name like Rob%) or (status = NEW)) AND (id > 10) )
+ * // where ( ((name like Rob%) or (status = NEW)) AND (id > 10) )
  * }
* *

@@ -53,22 +55,21 @@ package com.avaje.ebean; * Query q = * Ebean.find(Customer.class) * .where() - * .or() - * .and() - * .startsWith("name", "r") - * .eq("anniversary", onAfter) - * .endJunction() - * .and() - * .eq("status", Customer.Status.ACTIVE) - * .gt("id", 0) - * .endJunction() + * .or() + * .and() + * .startsWith("name", "r") + * .eq("anniversary", onAfter) + * .endJunction() + * .and() + * .eq("status", Customer.Status.ACTIVE) + * .gt("id", 0) + * .endJunction() * .order().asc("name"); * * q.findList(); * String s = q.getGeneratedSql(); * * // this produces an expression like: - * * ( name like ? and c.anniversary = ? ) or (c.status = ? and c.id > ? ) * * }