Package org.jbpm.query.jpa.impl
Class QueryCriteriaUtil
- java.lang.Object
-
- org.jbpm.query.jpa.impl.QueryCriteriaUtil
-
public abstract class QueryCriteriaUtil extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueryCriteriaUtil()QueryCriteriaUtil(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static voidaddCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, Class table, javax.persistence.metamodel.Attribute attr)static voidaddCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, javax.persistence.metamodel.Attribute attr)static voidapplyMetaCriteriaToQuery(javax.persistence.Query query, QueryWhere queryWhere)Small method to apply the meta criteria from theQueryWhereinstance to theQueryinstancestatic javax.persistence.criteria.PredicatebasicCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaBuilder builder, javax.persistence.criteria.Expression entityField, QueryCriteria criteria)This method creates the basic types ofPredicatefrom trivialQueryCriteria(NORMAL/REGEXP/RANGE).static <C,I>
List<I>convertListToInterfaceList(List<C> internalResult, Class<I> interfaceType)protected static StringconvertRegexToJPALikeExpression(String regexInput)Conver the regex (parameter) string to the JPA like syntaxprotected abstract <T> List<T>createQueryAndCallApplyMetaCriteriaAndGetResult(QueryWhere queryWhere, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, javax.persistence.criteria.CriteriaBuilder builder)This method does the persistence-related logic related to executing a query.static <T> javax.persistence.criteria.ExpressiondefaultGetEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)<T> List<T>doCriteriaQuery(QueryWhere queryWhere, Class<T> queryType)This method takes the high-level steps needed in order to create a JPACriteriaQuery.protected <R,T>
voidfillCriteriaQuery(javax.persistence.criteria.CriteriaQuery<R> query, QueryWhere queryWhere, javax.persistence.criteria.CriteriaBuilder builder, Class<T> queryType)This is the main ("highest"?protected Map<Class,Map<String,javax.persistence.metamodel.Attribute>>getCriteriaAttributes()protected abstract javax.persistence.criteria.CriteriaBuildergetCriteriaBuilder()protected <T> javax.persistence.criteria.ExpressiongetEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)This method retrieves the entity "field" that can be used as the LHS of aPredicateprotected <T,R>
javax.persistence.criteria.ExpressiongetOrderByExpression(javax.persistence.criteria.CriteriaQuery<R> query, Class<T> queryType, String orderByListId)static <T> javax.persistence.criteria.RootgetRoot(javax.persistence.criteria.AbstractQuery<T> query, Class queryType)This is a helper method to retrieve a particularRootfrom aCriteriaQueryinstanceprotected abstract <R,T>
javax.persistence.criteria.PredicateimplSpecificCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaQuery<R> query, javax.persistence.criteria.CriteriaBuilder builder, Class queryType, QueryCriteria criteria, QueryWhere queryWhere)Some criteria do not directly refer to a field, such as those stored in the criteria attributesMappassed as an argument to the constructor.protected voidinitialize(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes)protected abstract booleaninitializeCriteriaAttributes()The implementation of this method should be synchronized!
-
-
-
Method Detail
-
initialize
protected void initialize(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes)
-
getCriteriaAttributes
protected Map<Class,Map<String,javax.persistence.metamodel.Attribute>> getCriteriaAttributes()
-
convertListToInterfaceList
public static <C,I> List<I> convertListToInterfaceList(List<C> internalResult, Class<I> interfaceType)
-
addCriteria
public static void addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, javax.persistence.metamodel.Attribute attr)
-
addCriteria
public static void addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, Class table, javax.persistence.metamodel.Attribute attr)
-
initializeCriteriaAttributes
protected abstract boolean initializeCriteriaAttributes()
The implementation of this method should be synchronized!
-
getCriteriaBuilder
protected abstract javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
-
doCriteriaQuery
public <T> List<T> doCriteriaQuery(QueryWhere queryWhere, Class<T> queryType)
This method takes the high-level steps needed in order to create a JPACriteriaQuery.- A
CriteriaBuilderandCriteriaQueryinstance are created. - The tables being selected from are defined in the query.
- The
CriteriaQueryinstance is filled using the criteria in theQueryWhereinstance - A JPA
Queryinstance is created - The meta criteria (max results, offset) are applied to the query
- The results are retrieved and returned
- Parameters:
queryWhere- aQueryWhereinstance containing the query criteriaqueryType- The type (Class) of the result- Returns:
- The result of the query, a
List.
- A
-
fillCriteriaQuery
protected <R,T> void fillCriteriaQuery(javax.persistence.criteria.CriteriaQuery<R> query, QueryWhere queryWhere, javax.persistence.criteria.CriteriaBuilder builder, Class<T> queryType)This is the main ("highest"? "most abstract"?) method that is used to create aCriteriaQueryfrom aQueryWhereinstance.- Parameters:
query- The (empty)CriteriaQuerythat will be filled using theQueryCriteriaand other information in theQueryWhereinstancequeryWhere- TheQueryWhereinstance, with abstract information that should be added to theCriteriaQuerybuilder- TheCriteriaBuilder, helpful when creatingPredicates to add to theCriteriaQueryqueryType- TheClassindicating the mainRootof theCriteriaQuery
-
getRoot
public static <T> javax.persistence.criteria.Root getRoot(javax.persistence.criteria.AbstractQuery<T> query, Class queryType)This is a helper method to retrieve a particularRootfrom aCriteriaQueryinstance
-
getEntityField
protected <T> javax.persistence.criteria.Expression getEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)This method retrieves the entity "field" that can be used as the LHS of aPredicateThis method is overridden in some extendedQueryCriteriaUtilimplementations- Parameters:
query- TheCriteriaQuerythat we're buildinglistId- The list id of the givenQueryCriteria- Returns:
- An
Expressionwith thePathto the field represented by theQueryCriteria.getListId()value
-
defaultGetEntityField
public static <T> javax.persistence.criteria.Expression defaultGetEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)
-
basicCreatePredicateFromSingleCriteria
public static javax.persistence.criteria.Predicate basicCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaBuilder builder, javax.persistence.criteria.Expression entityField, QueryCriteria criteria)This method creates the basic types ofPredicatefrom trivialQueryCriteria(NORMAL/REGEXP/RANGE).- Parameters:
builder- TheCriteriaBuilder, helpful when creatingPredicates to add to theCriteriaQueryentityField- TheExpressionrepresenting a field/column in an entity/table.criteria- TheQueryCriteriawith the values to use as the RHS of aPredicate- Returns:
- The created
Predicate
-
convertRegexToJPALikeExpression
protected static String convertRegexToJPALikeExpression(String regexInput)
Conver the regex (parameter) string to the JPA like syntax- Parameters:
regexInput- The parameter string- Returns:
- The String in JPA syntax for a regular expressions
-
implSpecificCreatePredicateFromSingleCriteria
protected abstract <R,T> javax.persistence.criteria.Predicate implSpecificCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaQuery<R> query, javax.persistence.criteria.CriteriaBuilder builder, Class queryType, QueryCriteria criteria, QueryWhere queryWhere)Some criteria do not directly refer to a field, such as those stored in the criteria attributesMappassed as an argument to the constructor. For example, theQueryParameterIdentifiers.LAST_VARIABLE_LISTcriteria specifies that only the most recentVariableInstanceLogshould be retrieved. This method is called from the#createPredicateFromSingleCriteria(CriteriaQuery, QueryCriteria, CriteriaBuilder, Class)method when noAttributeinstance can be found in the instances criteria attributesMap.- Parameters:
criteriaQuery- TheCriteriaQueryinstance.criteria- TheQueryCriteriainstance with the criteria information.criteriaBuilder- TheCriteriaBuilderinstance used to help create the query predicate.queryType- TheClassof the query, used to identify the type of queryresultType- TheClassof the result being request.- Returns:
- A
Predicaterepresentin the information in theQueryCriteriainstance.
-
createQueryAndCallApplyMetaCriteriaAndGetResult
protected abstract <T> List<T> createQueryAndCallApplyMetaCriteriaAndGetResult(QueryWhere queryWhere, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, javax.persistence.criteria.CriteriaBuilder builder)
This method does the persistence-related logic related to executing a query. All implementations of this method should do the following, in approximately the following order:- Get an
EntityManagerinstance - Join a transaction using the entity manager
- Create a
Queryfrom the givenCriteriaQueryinstance. - Call the
applyMetaCriteriaToQuery(Query, QueryWhere)method - Retrieve the result from the
Queryinstance. - Close the transaction created, and the created
EntityManagerinstance. - Return the query result
- Parameters:
criteriaQuery- The created and filledCriteriaQueryinstancebuilder- TheCriteriaBuilder, helpful when creatingPredicates to add to theCriteriaQueryqueryWhere- TheQueryWhereinstance containing the meta criteria information.- Returns:
- A
Listof instances, representing the query result.
- Get an
-
applyMetaCriteriaToQuery
public static void applyMetaCriteriaToQuery(javax.persistence.Query query, QueryWhere queryWhere)Small method to apply the meta criteria from theQueryWhereinstance to theQueryinstance- Parameters:
query- TheQueryinstancequeryWhere- TheQueryWhereinstance, with the abstract information about the query
-
-