Package com.ocs.dynamo.dao.impl
Class JpaQueryBuilder
- java.lang.Object
-
- com.ocs.dynamo.dao.impl.JpaQueryBuilder
-
public final class JpaQueryBuilder extends Object
- Author:
- patrick.deenen, bas.rutten Class for constructing JPA queries built on the criteria API
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> javax.persistence.TypedQuery<Long>createCountQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, Filter filter, boolean distinct)Creates a query that performs a countstatic <T> javax.persistence.TypedQuery<javax.persistence.Tuple>createDistinctQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, String distinctField, SortOrder... sortOrders)Creates a distinct querystatic <ID,T>
javax.persistence.TypedQuery<T>createFetchQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, List<ID> ids, Filter additionalFilter, SortOrders sortOrders, FetchJoinInformation[] fetchJoins)Creates a query that fetches objects based on their IDsstatic <ID,T>
javax.persistence.TypedQuery<T>createFetchSingleObjectQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, ID id, FetchJoinInformation[] fetchJoins)Create a query for fetching a single objectstatic <T> javax.persistence.TypedQuery<javax.persistence.Tuple>createIdQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, Filter filter, SortOrder... sortOrders)Creates a query for retrieving the IDs of the entities that match the provided filterstatic Map<String,Object>createParameterMap()Creates an empty parameter mapstatic <T> javax.persistence.TypedQuery<T>createSelectQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, FetchJoinInformation[] fetchJoins, SortOrder... sortOrders)Creates a query that simply selects some objects based on some filterstatic <T> javax.persistence.TypedQuery<Object[]>createSelectQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, String[] selectProperties, SortOrders sortOrders)Creates a query that fetches properties instead of entities.static <T> javax.persistence.criteria.CriteriaQuery<T>createUniquePropertyFetchQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, FetchJoinInformation[] fetchJoins, String propertyName, Object value, boolean caseSensitive)Creates a query to fetch an object based on a value of a unique propertystatic <T> javax.persistence.criteria.CriteriaQuery<T>createUniquePropertyQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, String propertyName, Object value, boolean caseSensitive)Creates a query used to retrieve a single entity based on a unique property valuestatic voidsetParameters(javax.persistence.TypedQuery<?> query, Map<String,Object> pars)Sets any parameter values on the query
-
-
-
Method Detail
-
createCountQuery
public static <T> javax.persistence.TypedQuery<Long> createCountQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, Filter filter, boolean distinct)
Creates a query that performs a count- Parameters:
entityManager- the entity managerentityClass- the entity classfilter- the filter to applydistinct- whether to return only distinct results- Returns:
-
createDistinctQuery
public static <T> javax.persistence.TypedQuery<javax.persistence.Tuple> createDistinctQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, String distinctField, SortOrder... sortOrders)
Creates a distinct query- Parameters:
filter-entityManager-entityClass-distinctField-sortOrders-- Returns:
-
createFetchQuery
public static <ID,T> javax.persistence.TypedQuery<T> createFetchQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, List<ID> ids, Filter additionalFilter, SortOrders sortOrders, FetchJoinInformation[] fetchJoins)Creates a query that fetches objects based on their IDs- Parameters:
entityManager- the entity managerentityClass- the entity classids- the IDs of the desired entitiessortOrders- the sorting informationfetchJoins- the desired fetch joins- Returns:
-
createFetchSingleObjectQuery
public static <ID,T> javax.persistence.TypedQuery<T> createFetchSingleObjectQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, ID id, FetchJoinInformation[] fetchJoins)Create a query for fetching a single object- Parameters:
entityManager- the entity managerentityClass- the entity classid- ID of the object to returnfetchJoins- fetch joins to include- Returns:
-
createIdQuery
public static <T> javax.persistence.TypedQuery<javax.persistence.Tuple> createIdQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, Filter filter, SortOrder... sortOrders)Creates a query for retrieving the IDs of the entities that match the provided filter- Parameters:
entityManager- the entity managerentityClass- the entity classfilter- the filter to applysortOrder- the sorting to apply- Returns:
-
createParameterMap
public static Map<String,Object> createParameterMap()
Creates an empty parameter map- Returns:
-
createSelectQuery
public static <T> javax.persistence.TypedQuery<T> createSelectQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, FetchJoinInformation[] fetchJoins, SortOrder... sortOrders)
Creates a query that simply selects some objects based on some filter- Parameters:
filter- the filterentityManager- the entity managerentityClass- the entity classsortOrder- the sorting information- Returns:
-
createSelectQuery
public static <T> javax.persistence.TypedQuery<Object[]> createSelectQuery(Filter filter, javax.persistence.EntityManager entityManager, Class<T> entityClass, String[] selectProperties, SortOrders sortOrders)
Creates a query that fetches properties instead of entities. Supports aggregated functions; when used will automatically add group by expressions for all properties in the select list without an aggregated function.- Parameters:
filter- the filterentityManager- the entity managerentityClass- the entity classselectProperties- the properties to use in the selectionsortOrders- the sorting information- Returns:
-
createUniquePropertyFetchQuery
public static <T> javax.persistence.criteria.CriteriaQuery<T> createUniquePropertyFetchQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, FetchJoinInformation[] fetchJoins, String propertyName, Object value, boolean caseSensitive)Creates a query to fetch an object based on a value of a unique property- Parameters:
entityManager- the entity managerentityClass- the entity classfetchJoins- the fetch joins to includepropertyName- name of the property to search onvalue- value of the property to search on- Returns:
-
createUniquePropertyQuery
public static <T> javax.persistence.criteria.CriteriaQuery<T> createUniquePropertyQuery(javax.persistence.EntityManager entityManager, Class<T> entityClass, String propertyName, Object value, boolean caseSensitive)Creates a query used to retrieve a single entity based on a unique property value- Parameters:
entityManager-entityClass-propertyName-value-- Returns:
-
-