Class PropertyCriteriaQueryBuilder<E extends PersistenceEntity,​T>

  • Type Parameters:
    E - query entity type
    T - query result type
    All Implemented Interfaces:
    CriteriaQueryBuilder<T>, java.io.Serializable

    public class PropertyCriteriaQueryBuilder<E extends PersistenceEntity,​T>
    extends java.lang.Object
    implements CriteriaQueryBuilder<T>
    PropertyCriteriaQueryBuilder: build CriteriaQuery from a list of CriteriaElement(s).
    Since:
    4.2
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Class<E> entityType
      entity type
      protected java.util.List<? extends CriteriaElement> propertyQueryElements
      a list of PropertyQueryElements as query restrictions and/or orders
      protected java.lang.Class<T> resultType
      type of query results retrieved from persistence
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void addOrders​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, java.util.List<javax.persistence.criteria.Order> ordersToAdd)
      Add the orders to the end of list of existing orders of the criteriaQuery.
      static <T> void addOrders​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, javax.persistence.criteria.Order... orders)
      Add the orders to the end of list of existing orders of the criteriaQuery.
      void addPropertyQueryElements​(java.util.List<? extends CriteriaElement> propertyQueryElements)
      Add the list of CriteriaElement(s) that is used to build CriteriaQuery
      static <T> void addToCriteria​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CommonAbstractCriteria criteria, java.util.List<? extends CriteriaElement> criteriaElements, java.lang.String parentPropertyNamePath)
      Add the list of propertyQueryElements to the criteria.
      void build​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
      Build criteria query
      static CriteriaPredicate getDateCriterion​(java.lang.String propertyNamePath, DatePeriod datePeriod, boolean localDateTime, java.util.TimeZone timeZone)
      Get date query criterion: the value of the date property falls into the date period.
      static CriteriaPredicate getDateCriterion​(java.lang.String propertyNamePath, InstantPeriod instantPeriod)
      Get date query criterion: the value of the date property falls into the date period.
      static javax.persistence.criteria.Predicate getDatePredicate​(java.lang.String propertyNamePath, DatePeriod datePeriod, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CommonAbstractCriteria criteria, EntityJoinGraph joinGraph, boolean localDateTime, java.util.TimeZone timeZone)
      Get date query criterion: the value of the date property falls into the date period.
      static CriteriaExpression<java.lang.Boolean> getEntityAttrQueryCriterion​(java.lang.String parentPropertyNamePath, EntityAttr entityAttr, java.lang.Object value, CriteriaFunction.Function function)
      Get the query criterion for the attribute.
      static CriteriaExpression<java.lang.Boolean> getEntityAttrQueryRestriction​(java.lang.String parentPropertyNamePath, java.util.List<EntityAttrValue> entityAttrValues, boolean matchAny, boolean ignoreIfEmpty)
      Get query restrictions for matching attribute values using CriteriaFunction.Function.EQ
      EntityFetchGraph getEntityFetchGraph()
      Get entity fetch graph if any.
      static EntityFetchGraph getEntityFetchGraph​(CriteriaElement[] propertyQueryElements)
      Get the entity fetch Graph from the list of propertyQueryElements
      static EntityFetchGraph getEntityFetchGraph​(java.util.List<? extends CriteriaElement> propertyQueryElements)
      Get the entity fetch Graph from the list of propertyQueryElements
      java.lang.Class<E> getEntityType()
      Get the entity type to query
      static javax.persistence.criteria.Predicate getHierarchyRestriction​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CommonAbstractCriteria criteria, java.lang.String propertyNamePath, Hierarchy hierarchyEntity, EntityJoinGraph joinGraph)
      Get hierarchy restriction, matching the hierarchyEntity and descendant hierarchy entities.
      static <T> javax.persistence.criteria.Predicate getHierarchyRestriction​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CommonAbstractCriteria criteria, java.lang.String propertyNamePath, java.lang.String hierarchyId, EntityJoinGraph joinGraph)
      Get hierarchy restriction, matching the hierarchyId and its descendant hierarchies.
      static java.lang.Object getHint​(java.util.List<? extends CriteriaElement> criteriaElements, java.lang.String hintName)
      Get the hint from the list of propertyQueryElements
      static <X,​Y>
      javax.persistence.criteria.Join<Y,​?>
      getJoin​(javax.persistence.criteria.From<X,​Y> from, java.lang.String property)
      Get the join with the property name from the path (from).
      static EntityJoinGraph getJoinGraph​(CriteriaElement[] propertyQueryElements)
      Get entity join graph from the list of propertyQueryElements
      static EntityJoinGraph getJoinGraph​(java.util.List<? extends CriteriaElement> propertyQueryElements)
      Get the entity join graph from the list of propertyQueryElements
      static java.util.List<javax.persistence.criteria.Expression<?>> getJPAExpressions​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CommonAbstractCriteria criteria, java.util.List<CriteriaExpression> expressions, java.lang.String parentPropertyNamePath, EntityJoinGraph joinGraph, java.util.Map<java.lang.String,​javax.persistence.criteria.Selection<?>> aliasMap)
      Create JPA expressions from a list of CriteriaExpression(s).
      static <T> java.util.List<javax.persistence.criteria.Order> getOrders​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, CriteriaElement[] criteriaElements)
      Get the list of query orders from the list of CriteriaElements.
      static java.lang.String getPropertyNamePath​(java.lang.String parentPropertyNamePath, java.lang.String propertyName)
      Concatenate the parent path and property name.
      static <T> javax.persistence.criteria.Path<T> getPropertyPath​(javax.persistence.criteria.CommonAbstractCriteria criteria, javax.persistence.criteria.Path parentPath, java.lang.String propertyNamePath)
      Get property path that can be used in building a Criteria, creating inner joins for non-leaf properties on the path if they do not exist.
      static <T> javax.persistence.criteria.Path<T> getPropertyPath​(javax.persistence.criteria.CommonAbstractCriteria criteria, javax.persistence.criteria.Path parentPath, java.lang.String propertyNamePath, EntityJoinGraph joinGraph)
      Get property path that can be used in building a Criteria, creating joins for non-leaf properties on the path if they do not exist.
      java.util.List<? extends CriteriaElement> getPropertyQueryElements()
      Get the list of CriteriaElement(s) that is used to build CriteriaQuery
      java.lang.Class getQueryEntityType()
      Get query entity type that is the root entity type of query.
      java.lang.Class<T> getResultType()
      Get query result type
      void setEntityType​(java.lang.Class<E> entityType)
      Set the entity type to query
      void setPropertyQueryElements​(java.util.List<? extends CriteriaElement> propertyQueryElements)
      Set the list of CriteriaElement(s) that is used to build CriteriaQuery
      void setResultType​(java.lang.Class<T> resultType)
      Set query result type
      • Methods inherited from class java.lang.Object

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

      • entityType

        protected java.lang.Class<E extends PersistenceEntity> entityType
        entity type
      • resultType

        protected java.lang.Class<T> resultType
        type of query results retrieved from persistence
      • propertyQueryElements

        protected java.util.List<? extends CriteriaElement> propertyQueryElements
        a list of PropertyQueryElements as query restrictions and/or orders
    • Constructor Detail

      • PropertyCriteriaQueryBuilder

        public PropertyCriteriaQueryBuilder​(java.lang.Class<E> entityType,
                                            java.util.List<? extends CriteriaElement> propertyQueryElements,
                                            java.lang.Class<T> resultType)
        Constructor
        Parameters:
        entityType - the entity type of the properties
        propertyQueryElements - a list of PropertyQueryElements
        resultType - query result type
      • PropertyCriteriaQueryBuilder

        public PropertyCriteriaQueryBuilder​(java.lang.Class<E> entityType,
                                            CriteriaElement[] propertyQueryElements,
                                            java.lang.Class<T> resultType)
        Constructor
        Parameters:
        entityType - the entity type of the properties
        propertyQueryElements - an array of PropertyQueryElements
        resultType - query result type
    • Method Detail

      • getEntityType

        public java.lang.Class<E> getEntityType()
        Get the entity type to query
        Returns:
        entity type
      • setEntityType

        public void setEntityType​(java.lang.Class<E> entityType)
        Set the entity type to query
        Parameters:
        entityType - entity type
      • getResultType

        public java.lang.Class<T> getResultType()
        Get query result type
        Returns:
        query result type
      • setResultType

        public void setResultType​(java.lang.Class<T> resultType)
        Set query result type
        Parameters:
        resultType - query result type
      • getPropertyQueryElements

        public java.util.List<? extends CriteriaElement> getPropertyQueryElements()
        Get the list of CriteriaElement(s) that is used to build CriteriaQuery
        Returns:
        a list of CriteriaElement(s)
      • setPropertyQueryElements

        public void setPropertyQueryElements​(java.util.List<? extends CriteriaElement> propertyQueryElements)
        Set the list of CriteriaElement(s) that is used to build CriteriaQuery
        Parameters:
        propertyQueryElements - a list of CriteriaElement(s)
      • addPropertyQueryElements

        public void addPropertyQueryElements​(java.util.List<? extends CriteriaElement> propertyQueryElements)
        Add the list of CriteriaElement(s) that is used to build CriteriaQuery
        Parameters:
        propertyQueryElements - the list of CriteriaElement(s) to add
      • build

        public void build​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                          javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
        Description copied from interface: CriteriaQueryBuilder
        Build criteria query
        Specified by:
        build in interface CriteriaQueryBuilder<E extends PersistenceEntity>
        Parameters:
        criteriaBuilder - the CriteriaBuilder instance
        criteriaQuery - the criteriaQuery being built
      • getJPAExpressions

        public static java.util.List<javax.persistence.criteria.Expression<?>> getJPAExpressions​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                                                 javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                                                 java.util.List<CriteriaExpression> expressions,
                                                                                                 java.lang.String parentPropertyNamePath,
                                                                                                 EntityJoinGraph joinGraph,
                                                                                                 java.util.Map<java.lang.String,​javax.persistence.criteria.Selection<?>> aliasMap)
        Create JPA expressions from a list of CriteriaExpression(s).
        Parameters:
        criteriaBuilder - CriteriaBuilder instance
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        parentPropertyNamePath - parent property name path, null if property name paths of this CriteriaElement are directly under the root of criteria.
        joinGraph - entity join graph
        aliasMap - alias map that is used to resolve aliases in the expression, and created aliases will be put into the map if any.
        Returns:
        a list of JPA expressions
      • addToCriteria

        public static <T> void addToCriteria​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                             javax.persistence.criteria.CommonAbstractCriteria criteria,
                                             java.util.List<? extends CriteriaElement> criteriaElements,
                                             java.lang.String parentPropertyNamePath)
        Add the list of propertyQueryElements to the criteria.

        Existing or multiple restrictions, orders, selections, groups and group restrictions will be merged. orders, selections, groups and group restrictions are meaning for CriteriaQuery only, and will be ignored for CriteriaUpdate or CriteriaDelete.

        Parameters:
        criteriaBuilder - CriteriaBuilder instance
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        criteriaElements - a list of property query elements
        parentPropertyNamePath - parent property name path of the propertyQueryElements. null if they are top-level.
      • getJoinGraph

        public static EntityJoinGraph getJoinGraph​(java.util.List<? extends CriteriaElement> propertyQueryElements)
        Get the entity join graph from the list of propertyQueryElements
        Parameters:
        propertyQueryElements - a list of PropertyQueryElements
        Returns:
        EntityJoinGraph instance. return null if not found.
      • getJoinGraph

        public static EntityJoinGraph getJoinGraph​(CriteriaElement[] propertyQueryElements)
        Get entity join graph from the list of propertyQueryElements
        Parameters:
        propertyQueryElements - an array of PropertyQueryElements
        Returns:
        EntityJoinGraph instance, return null if not found.
      • getEntityFetchGraph

        public static EntityFetchGraph getEntityFetchGraph​(java.util.List<? extends CriteriaElement> propertyQueryElements)
        Get the entity fetch Graph from the list of propertyQueryElements
        Parameters:
        propertyQueryElements - a list of PropertyQueryElements
        Returns:
        EntityFetchGraph instance. return null if not found.
      • getEntityFetchGraph

        public static EntityFetchGraph getEntityFetchGraph​(CriteriaElement[] propertyQueryElements)
        Get the entity fetch Graph from the list of propertyQueryElements
        Parameters:
        propertyQueryElements - a list of PropertyQueryElements
        Returns:
        EntityFetchGraph instance. return null if not found.
      • getHint

        public static java.lang.Object getHint​(java.util.List<? extends CriteriaElement> criteriaElements,
                                               java.lang.String hintName)
        Get the hint from the list of propertyQueryElements
        Parameters:
        criteriaElements - a list of PropertyQueryElements
        Returns:
        hint object. return null if not found.
      • addOrders

        public static <T> void addOrders​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery,
                                         javax.persistence.criteria.Order... orders)
        Add the orders to the end of list of existing orders of the criteriaQuery.
        Parameters:
        criteriaQuery - a CriteriaQuery instance
        orders - the orders to append
      • addOrders

        public static <T> void addOrders​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery,
                                         java.util.List<javax.persistence.criteria.Order> ordersToAdd)
        Add the orders to the end of list of existing orders of the criteriaQuery.
        Parameters:
        criteriaQuery - a CriteriaQuery instance
        ordersToAdd - the orders to append
      • getPropertyNamePath

        public static java.lang.String getPropertyNamePath​(java.lang.String parentPropertyNamePath,
                                                           java.lang.String propertyName)
        Concatenate the parent path and property name.
        Parameters:
        parentPropertyNamePath - parent path such a.b.c
        propertyName - property name that can be a name path. it can be an empty string.
        Returns:
        full property name path
      • getHierarchyRestriction

        public static <T> javax.persistence.criteria.Predicate getHierarchyRestriction​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                                       javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                                       java.lang.String propertyNamePath,
                                                                                       java.lang.String hierarchyId,
                                                                                       EntityJoinGraph joinGraph)
        Get hierarchy restriction, matching the hierarchyId and its descendant hierarchies.

        The hierarchy property type is String, not a Hierarchy entity.

        Parameters:
        criteriaBuilder - CriteriaBuilder instance
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        propertyNamePath - hierarchy property name path such as a.b.c
        hierarchyId - hierarchy id
        joinGraph - entity join graph
        Returns:
        query Predicate instance
      • getHierarchyRestriction

        public static javax.persistence.criteria.Predicate getHierarchyRestriction​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                                   javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                                   java.lang.String propertyNamePath,
                                                                                   Hierarchy hierarchyEntity,
                                                                                   EntityJoinGraph joinGraph)
        Get hierarchy restriction, matching the hierarchyEntity and descendant hierarchy entities.

        The hierarchy property type is a Hierarchy entity.

        Parameters:
        criteriaBuilder - CriteriaBuilder instance
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        propertyNamePath - hierarchy property name path such as a.b.c
        hierarchyEntity - hierarchy entity
        joinGraph - entity join graph
        Returns:
        query Predicate instance
      • getPropertyPath

        public static <T> javax.persistence.criteria.Path<T> getPropertyPath​(javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                             javax.persistence.criteria.Path parentPath,
                                                                             java.lang.String propertyNamePath)
        Get property path that can be used in building a Criteria, creating inner joins for non-leaf properties on the path if they do not exist.
        Parameters:
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        parentPath - parent path. if null, default to the first root of the criteriaQuery.
        propertyNamePath - the property name path relative to the parent path
        Returns:
        the Path of the property
      • getPropertyPath

        public static <T> javax.persistence.criteria.Path<T> getPropertyPath​(javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                             javax.persistence.criteria.Path parentPath,
                                                                             java.lang.String propertyNamePath,
                                                                             EntityJoinGraph joinGraph)
        Get property path that can be used in building a Criteria, creating joins for non-leaf properties on the path if they do not exist. If the propertyNamePath is null or empty, return the parentPath.
        Parameters:
        criteria - the CriteriaQuery, CriteriaDelete or CriteriaUpdate being built
        parentPath - parent path. if null, default to the first root of the criteria.
        propertyNamePath - the property name path relative to the parent path
        joinGraph - entity join graph
        Returns:
        the Path of the property
      • getJoin

        public static <X,​Y> javax.persistence.criteria.Join<Y,​?> getJoin​(javax.persistence.criteria.From<X,​Y> from,
                                                                                     java.lang.String property)
        Get the join with the property name from the path (from).
        Parameters:
        from - From path
        property - property name
        Returns:
        Join instance. return null if it does not exist
      • getOrders

        public static <T> java.util.List<javax.persistence.criteria.Order> getOrders​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                                     javax.persistence.criteria.CriteriaQuery<T> criteriaQuery,
                                                                                     CriteriaElement[] criteriaElements)
        Get the list of query orders from the list of CriteriaElements.
        Parameters:
        criteriaBuilder - CriteriaBuilder instance
        criteriaQuery - the CriteriaQuery being built
        criteriaElements - a list of CriteriaElements
        Returns:
        a list of Orders. return empty list if there is no orders found.
      • getEntityAttrQueryRestriction

        public static CriteriaExpression<java.lang.Boolean> getEntityAttrQueryRestriction​(java.lang.String parentPropertyNamePath,
                                                                                          java.util.List<EntityAttrValue> entityAttrValues,
                                                                                          boolean matchAny,
                                                                                          boolean ignoreIfEmpty)
        Get query restrictions for matching attribute values using CriteriaFunction.Function.EQ
        Parameters:
        parentPropertyNamePath - the property name path of the EntityAttrValueSupport
        entityAttrValues - a list of attribute values
        matchAny - if true, match any attribute; if false, match all attributes.
        ignoreIfEmpty - whether to ignore the restriction if the attrValues is null or empty. If false, isEmpty restriction will be added.
        Returns:
        a DetachedCriteria. return null if the restriction is empty.
      • getEntityAttrQueryCriterion

        public static CriteriaExpression<java.lang.Boolean> getEntityAttrQueryCriterion​(java.lang.String parentPropertyNamePath,
                                                                                        EntityAttr entityAttr,
                                                                                        java.lang.Object value,
                                                                                        CriteriaFunction.Function function)
        Get the query criterion for the attribute. For example,
         OrderItem attribute: color=RED
         
         order.orderItems.entityAttrValues.attribute.name="color"
         order.orderItems.entityAttrValues.value="RED"
         
        parentPropertyNamePath is order.orderItems.
        Parameters:
        parentPropertyNamePath - the property name path of the EntityAttrValueSupport, null for root
        entityAttr - an EntityAttr
        value - attribute value
        Returns:
        a boolean CrieteriaExpression. return null if value is null.
        Since:
        5.6
      • getDateCriterion

        public static CriteriaPredicate getDateCriterion​(java.lang.String propertyNamePath,
                                                         InstantPeriod instantPeriod)
        Get date query criterion: the value of the date property falls into the date period.
        Parameters:
        propertyNamePath - date property name path whose value is not a local date/time
        instantPeriod - instant period
        Returns:
        predicate
      • getDateCriterion

        public static CriteriaPredicate getDateCriterion​(java.lang.String propertyNamePath,
                                                         DatePeriod datePeriod,
                                                         boolean localDateTime,
                                                         java.util.TimeZone timeZone)
        Get date query criterion: the value of the date property falls into the date period.
        Parameters:
        propertyNamePath - date property name path
        datePeriod - date period
        localDateTime - whether the date property is a local date/time.
        timeZone - if needed, time zone is used to convert time between instant in time line and local date/time.
        Returns:
        predicate
      • getDatePredicate

        public static javax.persistence.criteria.Predicate getDatePredicate​(java.lang.String propertyNamePath,
                                                                            DatePeriod datePeriod,
                                                                            javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                            javax.persistence.criteria.CommonAbstractCriteria criteria,
                                                                            EntityJoinGraph joinGraph,
                                                                            boolean localDateTime,
                                                                            java.util.TimeZone timeZone)
        Get date query criterion: the value of the date property falls into the date period.
        Parameters:
        propertyNamePath - date property name path
        datePeriod - date period
        criteriaBuilder - criteria builder
        criteria - criteria query, update or delete.
        joinGraph - entity join graph
        localDateTime - whether the date property is a local date/time
        timeZone - if the date property is not a local date/time, time zone will used to get instants in time line for date period.
        Returns:
        a predicate