public abstract class QueryUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
COUNT_QUERY_STRING |
static String |
DELETE_ALL_QUERY_STRING |
Modifier and Type | Method and Description |
---|---|
static <T> javax.persistence.Query |
applyAndBind(String queryString,
Iterable<T> entities,
javax.persistence.EntityManager entityManager)
Creates a where-clause referencing the given entities and appends it to the given query string.
|
static String |
applySorting(String query,
Sort sort)
Adds order by clause to the JPQL query.
|
static String |
applySorting(String query,
Sort sort,
String alias)
Adds order by clause to the JPQL query.
|
static String |
createCountQueryFor(String originalQuery)
Creates a count projected query from the given original query.
|
static String |
createCountQueryFor(String originalQuery,
String countProjection)
Creates a count projected query from the given original query.
|
static String |
detectAlias(String query)
Resolves the alias for the entity to be retrieved from the given JPA query.
|
static String |
getExistsQueryString(String entityName,
String countQueryPlaceHolder,
Iterable<String> idAttributes)
Returns the query string to execute an exists query for the given id attributes.
|
static String |
getQueryString(String template,
String entityName)
Returns the query string for the given class name.
|
static boolean |
hasConstructorExpression(String query)
Returns whether the given JPQL query contains a constructor expression.
|
static boolean |
hasNamedParameter(javax.persistence.Query query)
Returns whether the given
Query contains named parameters. |
static boolean |
hasNamedParameter(String query)
Returns whether the given query contains named parameters.
|
static List<javax.persistence.criteria.Order> |
toOrders(Sort sort,
javax.persistence.criteria.Root<?> root,
javax.persistence.criteria.CriteriaBuilder cb)
Turns the given
Sort into Order s. |
public static final String COUNT_QUERY_STRING
public static final String DELETE_ALL_QUERY_STRING
public static String getExistsQueryString(String entityName, String countQueryPlaceHolder, Iterable<String> idAttributes)
entityName
- the name of the entity to create the query for, must not be null.countQueryPlaceHolder
- the placeholder for the count clause, must not be null.idAttributes
- the id attributes for the entity, must not be null.public static String getQueryString(String template, String entityName)
template
- entityName
- public static String applySorting(String query, Sort sort)
DEFAULT_ALIAS
to bind the sorting property to.query
- sort
- public static String applySorting(String query, Sort sort, String alias)
query
- sort
- alias
- public static String detectAlias(String query)
query
- public static <T> javax.persistence.Query applyAndBind(String queryString, Iterable<T> entities, javax.persistence.EntityManager entityManager)
T
- queryString
- entities
- entityManager
- public static String createCountQueryFor(String originalQuery)
originalQuery
- must not be null or empty.public static String createCountQueryFor(String originalQuery, String countProjection)
originalQuery
- must not be null.countProjection
- may be null.public static boolean hasNamedParameter(javax.persistence.Query query)
Query
contains named parameters.query
- public static boolean hasNamedParameter(String query)
query
- can be null or empty.public static List<javax.persistence.criteria.Order> toOrders(Sort sort, javax.persistence.criteria.Root<?> root, javax.persistence.criteria.CriteriaBuilder cb)
Sort
into Order
s.sort
- the Sort
instance to be transformed into JPA Order
s.root
- must not be null.cb
- must not be null.public static boolean hasConstructorExpression(String query)
query
- must not be null or empty.Copyright © 2011-2015–2016 Pivotal Software, Inc.. All rights reserved.