public abstract class JpaUtils extends Object
| Constructor and Description |
|---|
JpaUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
addOrder(String queryString,
String propertyPath,
boolean asc)
Add order by clause to queryString
|
static <T> void |
copyCriteria(javax.persistence.criteria.CriteriaQuery<T> from,
javax.persistence.criteria.CriteriaQuery<T> to) |
static void |
copyCriteriaNoSelection(javax.persistence.criteria.CriteriaQuery<?> from,
javax.persistence.criteria.CriteriaQuery<?> to)
Copy Criteria without Selection.
|
static void |
copyFetches(javax.persistence.criteria.Fetch<?,?> from,
javax.persistence.criteria.Fetch<?,?> to)
Copy Fetches
|
static void |
copyJoins(javax.persistence.criteria.From<?,?> from,
javax.persistence.criteria.From<?,?> to)
Copy Joins
|
static <T> Long |
count(javax.persistence.EntityManager em,
javax.persistence.criteria.CriteriaQuery<T> criteria)
Result count from a CriteriaQuery
|
static <T> javax.persistence.criteria.CriteriaQuery<Long> |
countCriteria(javax.persistence.EntityManager em,
javax.persistence.criteria.CriteriaQuery<T> criteria)
Create a row count CriteriaQuery from a CriteriaQuery
|
static String |
createCountQueryString(String queryString)
Create a count query string from a query string
|
static <T,K> javax.persistence.criteria.Join<T,K> |
findJoinedType(javax.persistence.criteria.CriteriaQuery<T> query,
Class<T> rootClass,
Class<K> joinClass)
Find Joined Root of type clazz
|
static <T> javax.persistence.criteria.Root<T> |
findRoot(javax.persistence.criteria.CriteriaQuery<?> query,
Class<T> clazz)
Find the Root with type class on CriteriaQuery Root Set
|
static <T> javax.persistence.criteria.Root<T> |
findRoot(javax.persistence.criteria.CriteriaQuery<T> query)
Find Root of result type
|
static String |
getAlias(String queryString)
Gets the alias of root entity of JQL query
|
static Set<javax.persistence.metamodel.Attribute<?,?>> |
getAttributes(javax.persistence.metamodel.EntityType<?> type,
javax.persistence.metamodel.Attribute.PersistentAttributeType persistentType)
Get all attributes of type by persistent type
|
static Set<javax.persistence.metamodel.Attribute<?,?>> |
getAttributes(javax.persistence.metamodel.EntityType<?> type,
javax.persistence.metamodel.Attribute.PersistentAttributeType persistentType,
Class<?> clazz)
Get all attributes where type or element type is assignable from class and has persistent type
|
static String |
getKeyQuery(String queryString,
String name)
Gets Query String for selecting primary keys
|
static String |
getMappedBy(javax.persistence.metamodel.Attribute<?,?> attribute)
Gets the mappedBy value from an attribute
|
static <T> String |
getOrCreateAlias(javax.persistence.criteria.Selection<T> selection)
Gets The result alias, if none set a default one and return it
|
static <T> javax.persistence.criteria.Path<T> |
getPath(javax.persistence.criteria.Path<?> path,
String propertyPath)
Gets a Path from Path using property path
|
static boolean |
hasPath(javax.persistence.criteria.Path<?> path,
String propertyPath)
Test if the path exists
|
static void |
initialize(javax.persistence.EntityManager em,
Object entity,
int depth)
Initialize a entity.
|
static boolean |
isTypeOrElementType(javax.persistence.metamodel.Attribute<?,?> attribute,
Class<?> clazz)
Test if attribute is type or in collections has element type
|
public static <T> Long count(javax.persistence.EntityManager em, javax.persistence.criteria.CriteriaQuery<T> criteria)
em - Entity Managercriteria - Criteria Query to count resultspublic static <T> javax.persistence.criteria.CriteriaQuery<Long> countCriteria(javax.persistence.EntityManager em, javax.persistence.criteria.CriteriaQuery<T> criteria)
em - entity managercriteria - source criteriapublic static <T> String getOrCreateAlias(javax.persistence.criteria.Selection<T> selection)
selection - public static <T> javax.persistence.criteria.Root<T> findRoot(javax.persistence.criteria.CriteriaQuery<T> query)
query - criteria querypublic static <T> javax.persistence.criteria.Root<T> findRoot(javax.persistence.criteria.CriteriaQuery<?> query,
Class<T> clazz)
T - root typequery - criteria queryclazz - root typepublic static <T,K> javax.persistence.criteria.Join<T,K> findJoinedType(javax.persistence.criteria.CriteriaQuery<T> query,
Class<T> rootClass,
Class<K> joinClass)
T - query - the criteria queryrootClass - the root classjoinClass - the join classpublic static <T> javax.persistence.criteria.Path<T> getPath(javax.persistence.criteria.Path<?> path,
String propertyPath)
path - the base pathpropertyPath - property path String like "customer.order.price"public static String createCountQueryString(String queryString)
queryString - string to parsepublic static String getAlias(String queryString)
queryString - JQL querypublic static String addOrder(String queryString, String propertyPath, boolean asc)
queryString - JPL Query StringpropertyPath - Order propertiasc - true if ascendingpublic static String getKeyQuery(String queryString, String name)
queryString - the original queryname - primary key namepublic static void copyCriteriaNoSelection(javax.persistence.criteria.CriteriaQuery<?> from,
javax.persistence.criteria.CriteriaQuery<?> to)
from - source Criteria.to - destination Criteria.public static <T> void copyCriteria(javax.persistence.criteria.CriteriaQuery<T> from,
javax.persistence.criteria.CriteriaQuery<T> to)
public static void copyJoins(javax.persistence.criteria.From<?,?> from,
javax.persistence.criteria.From<?,?> to)
from - source Jointo - destination Joinpublic static void copyFetches(javax.persistence.criteria.Fetch<?,?> from,
javax.persistence.criteria.Fetch<?,?> to)
from - source Fetchto - dest Fetchpublic static boolean hasPath(javax.persistence.criteria.Path<?> path,
String propertyPath)
path - path to test onpropertyPath - path to testpublic static void initialize(javax.persistence.EntityManager em,
Object entity,
int depth)
em - entity manager to useentity - entity to initializedepth - max depth on recursionpublic static Set<javax.persistence.metamodel.Attribute<?,?>> getAttributes(javax.persistence.metamodel.EntityType<?> type, javax.persistence.metamodel.Attribute.PersistentAttributeType persistentType, Class<?> clazz)
type - entity typepersistentType - persistentTypeclazz - classpublic static Set<javax.persistence.metamodel.Attribute<?,?>> getAttributes(javax.persistence.metamodel.EntityType<?> type, javax.persistence.metamodel.Attribute.PersistentAttributeType persistentType)
type - persistentType - public static boolean isTypeOrElementType(javax.persistence.metamodel.Attribute<?,?> attribute,
Class<?> clazz)
attribute - attribute to testclazz - Class to testpublic static String getMappedBy(javax.persistence.metamodel.Attribute<?,?> attribute)
attribute - attributeCopyright © 2014 JDAL. All Rights Reserved.