Package io.ebean

Interface ExpressionFactory


  • public interface ExpressionFactory
    Expression factory for creating standard expressions.

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

    You will often not use this class directly but instead just add expressions via the methods on ExpressionList such as ExpressionList.gt(String, Object).

    The ExpressionList is returned from Query.where().

    
     // Example: fetch orders where status equals new or orderDate > lastWeek.
    
     Expression newOrLastWeek =
         Expr.or(Expr.eq("status", Order.Status.NEW),
                 Expr.gt("orderDate", lastWeek));
    
     List<Order> list = DB.find(Order.class)
       .where().add(newOrLastWeek)
       .findList();
     ...
     
    See Also:
    Query.where()
    • Method Detail

      • arrayContains

        Expression arrayContains​(String propertyName,
                                 Object... values)
        Array contains all the given values.

        Array support is effectively limited to Postgres at this time.

      • arrayNotContains

        Expression arrayNotContains​(String propertyName,
                                    Object... values)
        Array does not contain the given values.

        Array support is effectively limited to Postgres at this time.

      • arrayIsEmpty

        Expression arrayIsEmpty​(String propertyName)
        Array is empty - for the given array property.

        Array support is effectively limited to Postgres at this time.

      • arrayIsNotEmpty

        Expression arrayIsNotEmpty​(String propertyName)
        Array is not empty - for the given array property.

        Array support is effectively limited to Postgres at this time.

      • ieq

        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).
      • ine

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

        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.

      • inRangeWith

        Expression inRangeWith​(String lowProperty,
                               String highProperty,
                               Object value)
        Value in Range between 2 properties.
        
        
            .startDate.inRangeWith(endDate, now)
        
            // which equates to
            startDate <= now and (endDate > now or endDate is null)
        
         

        This is a convenience expression combining a number of simple expressions. The most common use of this could be called "effective dating" where 2 date or timestamp columns represent the date range in which

      • gtOrNull

        Expression gtOrNull​(String propertyName,
                            Object value)
        Greater Than Or Null - property greater than the given value or null.

        A convenient expression combining GT and Is Null. Most often useful for range expressions where the top range value is nullable.

      • geOrNull

        Expression geOrNull​(String propertyName,
                            Object value)
        Greater than or Equal to OR Null (>= or null )

        A convenient expression combining GE and Is Null. Most often useful for range expressions where the top range value is nullable.

      • ge

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

        Expression ltOrNull​(String propertyName,
                            Object value)
        Less Than or Null - property less than the given value or null.

        A convenient expression combining LT and Is Null. Most often useful for range expressions where the bottom range value is nullable.

      • leOrNull

        Expression leOrNull​(String propertyName,
                            Object value)
        Less Than or Equal to OR Null (<= or null )

        A convenient expression combining LE and Is Null. Most often useful for range expressions where the bottom range value is nullable.

      • le

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

        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

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

        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

        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

        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

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

        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();
        
         
      • allEq

        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.
      • bitwiseAny

        Expression bitwiseAny​(String propertyName,
                              long flags)
        Add expression for ANY of the given bit flags to be set.
        Parameters:
        propertyName - The property that holds the flags value
        flags - The flags we are looking for
      • bitwiseAll

        Expression bitwiseAll​(String propertyName,
                              long flags)
        Add expression for ALL of the given bit flags to be set.
        Parameters:
        propertyName - The property that holds the flags value
        flags - The flags we are looking for
      • bitwiseAnd

        Expression bitwiseAnd​(String propertyName,
                              long flags,
                              long match)
        Add bitwise AND expression of the given bit flags to compare with the match/mask.
        Parameters:
        propertyName - The property that holds the flags value
        flags - The flags we are looking for
      • raw

        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

        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

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

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

        <T> void where​(ExpressionList<T> where,
                       String expressions,
                       Object[] params)
        Add the expressions to the given expression list.
        Parameters:
        where - The expression list to add the expressions to
        expressions - The expressions that are parsed
        params - Bind parameters to match ? or ?1 bind positions.