public abstract class QueryCriteriaUtil extends Object
Modifier | Constructor and Description |
---|---|
protected |
QueryCriteriaUtil() |
|
QueryCriteriaUtil(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes) |
Modifier and Type | Method and Description |
---|---|
static void |
addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes,
String listId,
javax.persistence.metamodel.Attribute attr) |
static void |
addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes,
String listId,
Class table,
javax.persistence.metamodel.Attribute attr) |
static void |
applyMetaCriteriaToQuery(javax.persistence.Query query,
QueryWhere queryWhere)
Small method to apply the meta criteria from the
QueryWhere instance to the Query instance |
static javax.persistence.criteria.Predicate |
basicCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaBuilder builder,
javax.persistence.criteria.Expression entityField,
QueryCriteria criteria)
This method creates the basic types of
Predicate from trivial QueryCriteria (NORMAL/REGEXP/RANGE). |
static <C,I> List<I> |
convertListToInterfaceList(List<C> internalResult,
Class<I> interfaceType) |
protected static String |
convertRegexToJPALikeExpression(String regexInput)
Conver the regex (parameter) string to the JPA like syntax
|
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.
|
static <T> javax.persistence.criteria.Expression |
defaultGetEntityField(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 JPA
CriteriaQuery . |
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"?
|
protected Map<Class,Map<String,javax.persistence.metamodel.Attribute>> |
getCriteriaAttributes() |
protected abstract javax.persistence.criteria.CriteriaBuilder |
getCriteriaBuilder() |
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 a
Predicate
This method is overridden in some extended QueryCriteriaUtil implementations |
protected <T,R> javax.persistence.criteria.Expression |
getOrderByExpression(javax.persistence.criteria.CriteriaQuery<R> query,
Class<T> queryType,
String orderByListId) |
static <T> javax.persistence.criteria.Root |
getRoot(javax.persistence.criteria.AbstractQuery<T> query,
Class queryType)
This is a helper method to retrieve a particular
Root from a CriteriaQuery instance |
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 attributes
Map passed
as an argument to the constructor. |
protected void |
initialize(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes) |
protected abstract boolean |
initializeCriteriaAttributes()
The implementation of this method should be synchronized!
|
public QueryCriteriaUtil(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes)
protected QueryCriteriaUtil()
protected void initialize(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes)
protected Map<Class,Map<String,javax.persistence.metamodel.Attribute>> getCriteriaAttributes()
public static <C,I> List<I> convertListToInterfaceList(List<C> internalResult, Class<I> interfaceType)
public static void addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, javax.persistence.metamodel.Attribute attr)
public static void addCriteria(Map<Class,Map<String,javax.persistence.metamodel.Attribute>> criteriaAttributes, String listId, Class table, javax.persistence.metamodel.Attribute attr)
protected abstract boolean initializeCriteriaAttributes()
protected abstract javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
public <T> List<T> doCriteriaQuery(QueryWhere queryWhere, Class<T> queryType)
CriteriaQuery
.
CriteriaBuilder
and CriteriaQuery
instance are created.CriteriaQuery
instance is filled using the criteria in the QueryWhere
instanceQuery
instance is createdqueryWhere
- a QueryWhere
instance containing the query criteriaqueryType
- The type (Class
) of the resultList
.protected <R,T> void fillCriteriaQuery(javax.persistence.criteria.CriteriaQuery<R> query, QueryWhere queryWhere, javax.persistence.criteria.CriteriaBuilder builder, Class<T> queryType)
CriteriaQuery
from a QueryWhere
instance.query
- The (empty) CriteriaQuery
that will be filled using the QueryCriteria
and other information in the QueryWhere
instancequeryWhere
- The QueryWhere
instance, with abstract information that should be added to the CriteriaQuery
builder
- The CriteriaBuilder
, helpful when creating Predicate
s to add to the CriteriaQuery
queryType
- The Class
indicating the main Root
of the CriteriaQuery
public static <T> javax.persistence.criteria.Root getRoot(javax.persistence.criteria.AbstractQuery<T> query, Class queryType)
Root
from a CriteriaQuery
instanceprotected <T> javax.persistence.criteria.Expression getEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)
Predicate
This method is overridden in some extended QueryCriteriaUtil
implementationsquery
- The CriteriaQuery
that we're buildinglistId
- The list id of the given QueryCriteria
Expression
with the Path
to the field represented by the QueryCriteria.getListId()
valuepublic static <T> javax.persistence.criteria.Expression defaultGetEntityField(javax.persistence.criteria.CriteriaQuery<T> query, String listId, javax.persistence.metamodel.Attribute attr)
public static javax.persistence.criteria.Predicate basicCreatePredicateFromSingleCriteria(javax.persistence.criteria.CriteriaBuilder builder, javax.persistence.criteria.Expression entityField, QueryCriteria criteria)
Predicate
from trivial QueryCriteria
(NORMAL/REGEXP/RANGE).builder
- The CriteriaBuilder
, helpful when creating Predicate
s to add to the CriteriaQuery
entityField
- The Expression
representing a field/column in an entity/table.criteria
- The QueryCriteria
with the values to use as the RHS of a Predicate
Predicate
protected static String convertRegexToJPALikeExpression(String regexInput)
regexInput
- The parameter stringprotected 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)
Map>
passed
as an argument to the constructor.
For example, the QueryParameterIdentifiers.LAST_VARIABLE_LIST
criteria specifies
that only the most recent VariableInstanceLog
should be retrieved.
This method is called from the #createPredicateFromSingleCriteria(CriteriaQuery, QueryCriteria, CriteriaBuilder, Class)
method when no Attribute
instance can be found in the
instances criteria attributes Map>
.
criteriaQuery
- The CriteriaQuery
instance.criteria
- The QueryCriteria
instance with the criteria information.criteriaBuilder
- The CriteriaBuilder
instance used to help create the query predicate.queryType
- The Class
of the query, used to identify the type of queryresultType
- The Class
of the result being request.Predicate
representin the information in the QueryCriteria
instance.protected abstract <T> List<T> createQueryAndCallApplyMetaCriteriaAndGetResult(QueryWhere queryWhere, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, javax.persistence.criteria.CriteriaBuilder builder)
EntityManager
instanceQuery
from the given CriteriaQuery
instance.applyMetaCriteriaToQuery(Query, QueryWhere)
methodQuery
instance.EntityManager
instance.
criteriaQuery
- The created and filled CriteriaQuery
instancebuilder
- The CriteriaBuilder
, helpful when creating Predicate
s to add to the CriteriaQuery
queryWhere
- The QueryWhere
instance containing the meta criteria information.List
of instances, representing the query result.public static void applyMetaCriteriaToQuery(javax.persistence.Query query, QueryWhere queryWhere)
QueryWhere
instance to the Query
instancequery
- The Query
instancequeryWhere
- The QueryWhere
instance, with the abstract information about the queryCopyright © 2001–2016 JBoss by Red Hat. All rights reserved.