Class Restrictions

  • Direct Known Subclasses:
    Expression

    public class Restrictions
    extends java.lang.Object
    The criterion package may be used by applications as a framework for building new kinds of Criterion. However, it is intended that most applications will simply use the built-in criterion types via the static factory methods of this class. See also the Projections factory methods for generating Projection instances
    See Also:
    Criteria
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Restrictions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Criterion allEq​(java.util.Map<java.lang.String,​?> propertyNameValues)
      Apply an "equals" constraint to each property in the key set of a Map
      static Conjunction and​(Criterion... predicates)
      Return the conjunction of multiple expressions
      static LogicalExpression and​(Criterion lhs, Criterion rhs)
      Return the conjunction of two expressions
      static Criterion between​(java.lang.String propertyName, java.lang.Object low, java.lang.Object high)
      Apply a "between" constraint to the named property
      static Conjunction conjunction()
      Group expressions together in a single conjunction (A and B and C...).
      static Conjunction conjunction​(Criterion... conditions)
      Group expressions together in a single conjunction (A and B and C...).
      static Disjunction disjunction()
      Group expressions together in a single disjunction (A or B or C...).
      static Disjunction disjunction​(Criterion... conditions)
      Group expressions together in a single disjunction (A or B or C...).
      static SimpleExpression eq​(java.lang.String propertyName, java.lang.Object value)
      Apply an "equal" constraint to the named property
      static Criterion eqOrIsNull​(java.lang.String propertyName, java.lang.Object value)
      Apply an "equal" constraint to the named property.
      static PropertyExpression eqProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply an "equal" constraint to two properties
      static Criterion fkEq​(java.lang.String associationPropertyName, java.lang.Object value)  
      static Criterion fkIsNotNull​(java.lang.String associationPropertyName)  
      static Criterion fkIsNull​(java.lang.String associationPropertyName)  
      static Criterion fkNe​(java.lang.String associationPropertyName, java.lang.Object value)  
      static SimpleExpression ge​(java.lang.String propertyName, java.lang.Object value)
      Apply a "greater than or equal" constraint to the named property
      static PropertyExpression geProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply a "greater than or equal" constraint to two properties
      static SimpleExpression gt​(java.lang.String propertyName, java.lang.Object value)
      Apply a "greater than" constraint to the named property
      static PropertyExpression gtProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply a "greater than" constraint to two properties
      static Criterion idEq​(java.lang.Object value)
      Apply an "equal" constraint to the identifier property
      static Criterion ilike​(java.lang.String propertyName, java.lang.Object value)
      A case-insensitive "like" (similar to Postgres ilike operator)
      static Criterion ilike​(java.lang.String propertyName, java.lang.String value, MatchMode matchMode)
      A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode
      static Criterion in​(java.lang.String propertyName, java.lang.Object... values)
      Apply an "in" constraint to the named property.
      static Criterion in​(java.lang.String propertyName, java.util.Collection values)
      Apply an "in" constraint to the named property.
      static Criterion isEmpty​(java.lang.String propertyName)
      Constrain a collection valued property to be empty
      static Criterion isNotEmpty​(java.lang.String propertyName)
      Constrain a collection valued property to be non-empty
      static Criterion isNotNull​(java.lang.String propertyName)
      Apply an "is not null" constraint to the named property
      static Criterion isNull​(java.lang.String propertyName)
      Apply an "is null" constraint to the named property
      static SimpleExpression le​(java.lang.String propertyName, java.lang.Object value)
      Apply a "less than or equal" constraint to the named property
      static PropertyExpression leProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply a "less than or equal" constraint to two properties
      static SimpleExpression like​(java.lang.String propertyName, java.lang.Object value)
      Apply a "like" constraint to the named property
      static SimpleExpression like​(java.lang.String propertyName, java.lang.String value, MatchMode matchMode)
      Apply a "like" constraint to the named property using the provided match mode
      static SimpleExpression lt​(java.lang.String propertyName, java.lang.Object value)
      Apply a "less than" constraint to the named property
      static PropertyExpression ltProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply a "less than" constraint to two properties
      static NaturalIdentifier naturalId()
      Consider using any of the natural id based loading stuff from session instead, especially in cases where the restriction is the full set of natural id values.
      static SimpleExpression ne​(java.lang.String propertyName, java.lang.Object value)
      Apply a "not equal" constraint to the named property
      static Criterion neOrIsNotNull​(java.lang.String propertyName, java.lang.Object value)
      Apply a "not equal" constraint to the named property.
      static PropertyExpression neProperty​(java.lang.String propertyName, java.lang.String otherPropertyName)
      Apply a "not equal" constraint to two properties
      static Criterion not​(Criterion expression)
      Return the negation of an expression
      static Disjunction or​(Criterion... predicates)
      Return the disjunction of multiple expressions
      static LogicalExpression or​(Criterion lhs, Criterion rhs)
      Return the disjunction of two expressions
      static Criterion sizeEq​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sizeGe​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sizeGt​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sizeLe​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sizeLt​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sizeNe​(java.lang.String propertyName, int size)
      Constrain a collection valued property by size
      static Criterion sqlRestriction​(java.lang.String sql)
      Apply a constraint expressed in SQL with no JDBC parameters.
      static Criterion sqlRestriction​(java.lang.String sql, java.lang.Object[] values, Type[] types)
      Create a restriction expressed in SQL with JDBC parameters.
      static Criterion sqlRestriction​(java.lang.String sql, java.lang.Object value, Type type)
      Create a restriction expressed in SQL with one JDBC parameter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Restrictions

        protected Restrictions()
    • Method Detail

      • idEq

        public static Criterion idEq​(java.lang.Object value)
        Apply an "equal" constraint to the identifier property
        Parameters:
        value - The value to use in comparison
        Returns:
        Criterion
        See Also:
        IdentifierEqExpression
      • fkEq

        public static Criterion fkEq​(java.lang.String associationPropertyName,
                                     java.lang.Object value)
      • fkNe

        public static Criterion fkNe​(java.lang.String associationPropertyName,
                                     java.lang.Object value)
      • fkIsNotNull

        public static Criterion fkIsNotNull​(java.lang.String associationPropertyName)
      • fkIsNull

        public static Criterion fkIsNull​(java.lang.String associationPropertyName)
      • eq

        public static SimpleExpression eq​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply an "equal" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        SimpleExpression
        See Also:
        SimpleExpression
      • eqOrIsNull

        public static Criterion eqOrIsNull​(java.lang.String propertyName,
                                           java.lang.Object value)
        Apply an "equal" constraint to the named property. If the value is null, instead apply "is null".
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        eq(java.lang.String, java.lang.Object), isNull(java.lang.String)
      • ne

        public static SimpleExpression ne​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply a "not equal" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • neOrIsNotNull

        public static Criterion neOrIsNotNull​(java.lang.String propertyName,
                                              java.lang.Object value)
        Apply a "not equal" constraint to the named property. If the value is null, instead apply "is not null".
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        ne(java.lang.String, java.lang.Object), isNotNull(java.lang.String)
      • like

        public static SimpleExpression like​(java.lang.String propertyName,
                                            java.lang.Object value)
        Apply a "like" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • like

        public static SimpleExpression like​(java.lang.String propertyName,
                                            java.lang.String value,
                                            MatchMode matchMode)
        Apply a "like" constraint to the named property using the provided match mode
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        matchMode - The match mode to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • ilike

        public static Criterion ilike​(java.lang.String propertyName,
                                      java.lang.Object value)
        A case-insensitive "like" (similar to Postgres ilike operator)
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        LikeExpression
      • ilike

        public static Criterion ilike​(java.lang.String propertyName,
                                      java.lang.String value,
                                      MatchMode matchMode)
        A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        matchMode - The match mode to use in comparison
        Returns:
        The Criterion
        See Also:
        LikeExpression
      • gt

        public static SimpleExpression gt​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply a "greater than" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • lt

        public static SimpleExpression lt​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply a "less than" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • le

        public static SimpleExpression le​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply a "less than or equal" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • ge

        public static SimpleExpression ge​(java.lang.String propertyName,
                                          java.lang.Object value)
        Apply a "greater than or equal" constraint to the named property
        Parameters:
        propertyName - The name of the property
        value - The value to use in comparison
        Returns:
        The Criterion
        See Also:
        SimpleExpression
      • between

        public static Criterion between​(java.lang.String propertyName,
                                        java.lang.Object low,
                                        java.lang.Object high)
        Apply a "between" constraint to the named property
        Parameters:
        propertyName - The name of the property
        low - The low value
        high - The high value
        Returns:
        The Criterion
        See Also:
        BetweenExpression
      • in

        public static Criterion in​(java.lang.String propertyName,
                                   java.lang.Object... values)
        Apply an "in" constraint to the named property.
        Parameters:
        propertyName - The name of the property
        values - The literal values to use in the IN restriction
        Returns:
        The Criterion
        See Also:
        InExpression
      • in

        public static Criterion in​(java.lang.String propertyName,
                                   java.util.Collection values)
        Apply an "in" constraint to the named property.
        Parameters:
        propertyName - The name of the property
        values - The literal values to use in the IN restriction
        Returns:
        The Criterion
        See Also:
        InExpression
      • isNull

        public static Criterion isNull​(java.lang.String propertyName)
        Apply an "is null" constraint to the named property
        Parameters:
        propertyName - The name of the property
        Returns:
        Criterion
        See Also:
        NullExpression
      • isNotNull

        public static Criterion isNotNull​(java.lang.String propertyName)
        Apply an "is not null" constraint to the named property
        Parameters:
        propertyName - The property name
        Returns:
        The Criterion
        See Also:
        NotNullExpression
      • eqProperty

        public static PropertyExpression eqProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply an "equal" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • neProperty

        public static PropertyExpression neProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply a "not equal" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • ltProperty

        public static PropertyExpression ltProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply a "less than" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • leProperty

        public static PropertyExpression leProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply a "less than or equal" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • gtProperty

        public static PropertyExpression gtProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply a "greater than" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • geProperty

        public static PropertyExpression geProperty​(java.lang.String propertyName,
                                                    java.lang.String otherPropertyName)
        Apply a "greater than or equal" constraint to two properties
        Parameters:
        propertyName - One property name
        otherPropertyName - The other property name
        Returns:
        The Criterion
        See Also:
        PropertyExpression
      • and

        public static LogicalExpression and​(Criterion lhs,
                                            Criterion rhs)
        Return the conjunction of two expressions
        Parameters:
        lhs - One expression
        rhs - The other expression
        Returns:
        The Criterion
      • and

        public static Conjunction and​(Criterion... predicates)
        Return the conjunction of multiple expressions
        Parameters:
        predicates - The predicates making up the initial junction
        Returns:
        The conjunction
      • or

        public static LogicalExpression or​(Criterion lhs,
                                           Criterion rhs)
        Return the disjunction of two expressions
        Parameters:
        lhs - One expression
        rhs - The other expression
        Returns:
        The Criterion
      • or

        public static Disjunction or​(Criterion... predicates)
        Return the disjunction of multiple expressions
        Parameters:
        predicates - The predicates making up the initial junction
        Returns:
        The conjunction
      • not

        public static Criterion not​(Criterion expression)
        Return the negation of an expression
        Parameters:
        expression - The expression to be negated
        Returns:
        Criterion
        See Also:
        NotExpression
      • sqlRestriction

        public static Criterion sqlRestriction​(java.lang.String sql,
                                               java.lang.Object[] values,
                                               Type[] types)
        Create a restriction expressed in SQL with JDBC parameters. Any occurrences of {alias} will be replaced by the table alias.
        Parameters:
        sql - The SQL restriction
        values - The parameter values
        types - The parameter types
        Returns:
        The Criterion
        See Also:
        SQLCriterion
      • sqlRestriction

        public static Criterion sqlRestriction​(java.lang.String sql,
                                               java.lang.Object value,
                                               Type type)
        Create a restriction expressed in SQL with one JDBC parameter. Any occurrences of {alias} will be replaced by the table alias.
        Parameters:
        sql - The SQL restriction
        value - The parameter value
        type - The parameter type
        Returns:
        The Criterion
        See Also:
        SQLCriterion
      • sqlRestriction

        public static Criterion sqlRestriction​(java.lang.String sql)
        Apply a constraint expressed in SQL with no JDBC parameters. Any occurrences of {alias} will be replaced by the table alias.
        Parameters:
        sql - The SQL restriction
        Returns:
        The Criterion
        See Also:
        SQLCriterion
      • conjunction

        public static Conjunction conjunction()
        Group expressions together in a single conjunction (A and B and C...). This form creates an empty conjunction. See Junction.add(Criterion)
        Returns:
        Conjunction
      • conjunction

        public static Conjunction conjunction​(Criterion... conditions)
        Group expressions together in a single conjunction (A and B and C...).
        Parameters:
        conditions - The initial set of conditions to put into the Conjunction
        Returns:
        Conjunction
      • disjunction

        public static Disjunction disjunction()
        Group expressions together in a single disjunction (A or B or C...). This form creates an empty disjunction. See Junction.add(Criterion)
        Returns:
        Conjunction
      • disjunction

        public static Disjunction disjunction​(Criterion... conditions)
        Group expressions together in a single disjunction (A or B or C...).
        Parameters:
        conditions - The initial set of conditions to put into the Disjunction
        Returns:
        Conjunction
      • allEq

        public static Criterion allEq​(java.util.Map<java.lang.String,​?> propertyNameValues)
        Apply an "equals" constraint to each property in the key set of a Map
        Parameters:
        propertyNameValues - a map from property names to values
        Returns:
        Criterion
        See Also:
        Conjunction
      • isEmpty

        public static Criterion isEmpty​(java.lang.String propertyName)
        Constrain a collection valued property to be empty
        Parameters:
        propertyName - The name of the collection property
        Returns:
        The Criterion
        See Also:
        EmptyExpression
      • isNotEmpty

        public static Criterion isNotEmpty​(java.lang.String propertyName)
        Constrain a collection valued property to be non-empty
        Parameters:
        propertyName - The name of the collection property
        Returns:
        The Criterion
        See Also:
        NotEmptyExpression
      • sizeEq

        public static Criterion sizeEq​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression
      • sizeNe

        public static Criterion sizeNe​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression
      • sizeGt

        public static Criterion sizeGt​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression
      • sizeLt

        public static Criterion sizeLt​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression
      • sizeGe

        public static Criterion sizeGe​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression
      • sizeLe

        public static Criterion sizeLe​(java.lang.String propertyName,
                                       int size)
        Constrain a collection valued property by size
        Parameters:
        propertyName - The name of the collection property
        size - The size to use in comparison
        Returns:
        The Criterion
        See Also:
        SizeExpression