Package com.cmobilecom.af.session
Class PropertyCriteriaQueryBuilder<E extends PersistenceEntity,T>
- java.lang.Object
-
- com.cmobilecom.af.session.PropertyCriteriaQueryBuilder<E,T>
-
- Type Parameters:
E
- query entity typeT
- 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 typeprotected java.util.List<? extends CriteriaElement>
propertyQueryElements
a list of PropertyQueryElements as query restrictions and/or ordersprotected java.lang.Class<T>
resultType
type of query results retrieved from persistence
-
Constructor Summary
Constructors Constructor Description PropertyCriteriaQueryBuilder(java.lang.Class<E> entityType, CriteriaElement[] propertyQueryElements, java.lang.Class<T> resultType)
ConstructorPropertyCriteriaQueryBuilder(java.lang.Class<E> entityType, java.util.List<? extends CriteriaElement> propertyQueryElements, java.lang.Class<T> resultType)
Constructor
-
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 CriteriaQuerystatic <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 querystatic 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.EQEntityFetchGraph
getEntityFetchGraph()
Get entity fetch graph if any.static EntityFetchGraph
getEntityFetchGraph(CriteriaElement[] propertyQueryElements)
Get the entity fetch Graph from the list of propertyQueryElementsstatic EntityFetchGraph
getEntityFetchGraph(java.util.List<? extends CriteriaElement> propertyQueryElements)
Get the entity fetch Graph from the list of propertyQueryElementsjava.lang.Class<E>
getEntityType()
Get the entity type to querystatic 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 propertyQueryElementsstatic <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 propertyQueryElementsstatic EntityJoinGraph
getJoinGraph(java.util.List<? extends CriteriaElement> propertyQueryElements)
Get the entity join graph from the list of propertyQueryElementsstatic 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 CriteriaQueryjava.lang.Class
getQueryEntityType()
Get query entity type that is the root entity type of query.java.lang.Class<T>
getResultType()
Get query result typevoid
setEntityType(java.lang.Class<E> entityType)
Set the entity type to queryvoid
setPropertyQueryElements(java.util.List<? extends CriteriaElement> propertyQueryElements)
Set the list of CriteriaElement(s) that is used to build CriteriaQueryvoid
setResultType(java.lang.Class<T> resultType)
Set query result type
-
-
-
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 propertiespropertyQueryElements
- a list of PropertyQueryElementsresultType
- 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 propertiespropertyQueryElements
- an array of PropertyQueryElementsresultType
- 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 interfaceCriteriaQueryBuilder<E extends PersistenceEntity>
- Parameters:
criteriaBuilder
- the CriteriaBuilder instancecriteriaQuery
- 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 instancecriteria
- the CriteriaQuery, CriteriaDelete or CriteriaUpdate being builtparentPropertyNamePath
- parent property name path, null if property name paths of this CriteriaElement are directly under the root of criteria.joinGraph
- entity join graphaliasMap
- 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 instancecriteria
- the CriteriaQuery, CriteriaDelete or CriteriaUpdate being builtcriteriaElements
- a list of property query elementsparentPropertyNamePath
- 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 instanceorders
- 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 instanceordersToAdd
- 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.cpropertyName
- 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 instancecriteria
- the CriteriaQuery, CriteriaDelete or CriteriaUpdate being builtpropertyNamePath
- hierarchy property name path such as a.b.chierarchyId
- hierarchy idjoinGraph
- 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 instancecriteria
- the CriteriaQuery, CriteriaDelete or CriteriaUpdate being builtpropertyNamePath
- hierarchy property name path such as a.b.chierarchyEntity
- hierarchy entityjoinGraph
- 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 builtparentPath
- 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 builtparentPath
- parent path. if null, default to the first root of the criteria.propertyNamePath
- the property name path relative to the parent pathjoinGraph
- 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 pathproperty
- 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 instancecriteriaQuery
- the CriteriaQuery being builtcriteriaElements
- a list of CriteriaElements- Returns:
- a list of Orders. return empty list if there is no orders found.
-
getEntityFetchGraph
public EntityFetchGraph getEntityFetchGraph()
Description copied from interface:CriteriaQueryBuilder
Get entity fetch graph if any.- Specified by:
getEntityFetchGraph
in interfaceCriteriaQueryBuilder<E extends PersistenceEntity>
- Returns:
- EntityFetchGraph instance. return null if not defined
-
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 EntityAttrValueSupportentityAttrValues
- a list of attribute valuesmatchAny
- 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 rootentityAttr
- an EntityAttrvalue
- 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/timeinstantPeriod
- 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 pathdatePeriod
- date periodlocalDateTime
- 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 pathdatePeriod
- date periodcriteriaBuilder
- criteria buildercriteria
- criteria query, update or delete.joinGraph
- entity join graphlocalDateTime
- whether the date property is a local date/timetimeZone
- 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
-
getQueryEntityType
public java.lang.Class getQueryEntityType()
Description copied from interface:CriteriaQueryBuilder
Get query entity type that is the root entity type of query.- Specified by:
getQueryEntityType
in interfaceCriteriaQueryBuilder<E extends PersistenceEntity>
- Returns:
- query entity type.
-
-