Package io.ebean

Class Expr


  • public class Expr
    extends Object
    Expression factory for creating standard expressions for WHERE and HAVING clauses.

    Generally you will only need to use this object for creating OR, JUNCTION or CONJUNCTION expressions. To create simple expressions you will most likely just use the methods on the ExpressionList object that is returned via Query.where().

    This provides a convenient way to create expressions for the default database.

    See also DB.getExpressionFactory()

    Creates standard common expressions for using in a Query Where or Having clause.

    See Also:
    Query.where()
    • Method Detail

      • eq

        public static Expression eq​(String propertyName,
                                    Object value)
        Equal To - property equal to the given value.
      • ne

        public static Expression ne​(String propertyName,
                                    Object value)
        Not Equal To - property not equal to the given value.
      • ieq

        public static Expression ieq​(String propertyName,
                                     String value)
        Case Insensitive Equal To - property equal to the given value (typically using a lower() function to make it case insensitive).
      • inRange

        public static Expression inRange​(String propertyName,
                                         Object value1,
                                         Object value2)
        In Range - property >= value1 and property < value2.

        Unlike Between inRange is "half open" and usually more useful for use with dates or timestamps.

      • gt

        public static Expression gt​(String propertyName,
                                    Object value)
        Greater Than - property greater than the given value.
      • ge

        public static Expression ge​(String propertyName,
                                    Object value)
        Greater Than or Equal to - property greater than or equal to the given value.
      • lt

        public static Expression lt​(String propertyName,
                                    Object value)
        Less Than - property less than the given value.
      • le

        public static Expression le​(String propertyName,
                                    Object value)
        Less Than or Equal to - property less than or equal to the given value.
      • exampleLike

        public static ExampleExpression exampleLike​(Object example)
        Create the query by Example expression which is case sensitive and using LikeType.RAW (you need to add you own wildcards % and _).
      • like

        public static Expression like​(String propertyName,
                                      String value)
        Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).
      • ilike

        public static Expression ilike​(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.
      • istartsWith

        public static Expression istartsWith​(String propertyName,
                                             String value)
        Case insensitive Starts With - property like value%. Typically uses a lower() function to make the expression case insensitive.
      • iendsWith

        public static Expression iendsWith​(String propertyName,
                                           String value)
        Case insensitive Ends With - property like %value. Typically uses a lower() function to make the expression case insensitive.
      • icontains

        public static Expression icontains​(String propertyName,
                                           String value)
        Case insensitive Contains - property like %value%. Typically uses a lower() function to make the expression case insensitive.
      • isEmpty

        public static Expression isEmpty​(String propertyName)
        For collection properties that are empty (have not existing elements).
      • isNotEmpty

        public static Expression isNotEmpty​(String propertyName)
        For collection properties that are not empty (have existing elements).
      • in

        public static Expression in​(String propertyName,
                                    Object[] values)
        In - property has a value in the array of values.
      • inOrEmpty

        public static Expression inOrEmpty​(String propertyName,
                                           Collection<?> values)
        In where null or empty values means that no predicate is added to the query.

        That is, only add the IN predicate if the values are not null or empty.

        Without this we typically need to code an if block to only add the IN predicate if the collection is not empty like:

        Without inOrEmpty()

        
        
           query.where() // add some predicates
             .eq("status", Status.NEW);
        
           if (ids != null && !ids.isEmpty()) {
             query.where().in("customer.id", ids);
           }
        
           query.findList();
        
         

        Using inOrEmpty()

        
        
           query.where()
             .eq("status", Status.NEW)
             .inOrEmpty("customer.id", ids)
             .findList();
        
         
      • idEq

        public static Expression idEq​(Object value)
        Id Equal to - ID property is equal to the value.
      • allEq

        public static Expression allEq​(Map<String,​Object> propertyMap)
        All Equal - Map containing property names and their values.

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

        Parameters:
        propertyMap - a map keyed by property names.
      • raw

        public static Expression raw​(String raw,
                                     Object value)
        Add raw expression with a single parameter.

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

      • raw

        public static Expression raw​(String raw,
                                     Object[] values)
        Add raw expression with an array of parameters.

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

      • conjunction

        public static <T> Junction<T> conjunction​(Query<T> query)
        Return a list of expressions that will be joined by AND's.
      • disjunction

        public static <T> Junction<T> disjunction​(Query<T> query)
        Return a list of expressions that will be joined by OR's.