Java Code Examples for javax.persistence.criteria.CriteriaQuery#getRoots()

The following examples show how to use javax.persistence.criteria.CriteriaQuery#getRoots() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryUtil.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
public static boolean hasManyRootsFetchesOrJoins(CriteriaQuery<?> criteriaQuery) {
	Set<Root<?>> roots = criteriaQuery.getRoots();

	// more than one root, user is supposed to handle this manually
	if (roots.size() != 1)
		return false;

	for (Root<?> root : roots) {
		if (containsMultiRelationFetch(root.getFetches()))
			return true;

		if (containsMultiRelationJoin(root.getJoins()))
			return true;
	}
	return false;
}
 
Example 2
Source File: QueryUtil.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
public static boolean hasManyRootsFetchesOrJoins(CriteriaQuery<?> criteriaQuery) {
  Set<Root<?>> roots = criteriaQuery.getRoots();

  // more than one root, user is supposed to handle this manually
  if (roots.size() != 1)
    return false;

  for (Root<?> root : roots) {
    if (containsMultiRelationFetch(root.getFetches()))
      return true;

    if (containsMultiRelationJoin(root.getJoins()))
      return true;
  }
  return false;
}
 
Example 3
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Find the Root with type class on CriteriaQuery Root Set
 * @param <T> root type
 * @param query criteria query
 * @param clazz root type
 * @return Root<T> of null if none
 */
@SuppressWarnings("unchecked")
public static  <T> Root<T> findRoot(CriteriaQuery<?> query, Class<T> clazz) {

	for (Root<?> r : query.getRoots()) {
		if (clazz.equals(r.getJavaType())) {
			return (Root<T>) r.as(clazz);
		}
	}
	return null;
}
 
Example 4
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Copy criteria without selection and order.
 * @param from source Criteria.
 * @param to destination Criteria.
 */
private static void copyCriteriaWithoutSelectionAndOrder(
		CriteriaQuery<?> from, CriteriaQuery<?> to, boolean copyFetches) {
	if (isEclipseLink(from) && from.getRestriction() != null) {
		// EclipseLink adds roots from predicate paths to critera. Skip copying 
		// roots as workaround.
	}
	else {
		 // Copy Roots
		 for (Root<?> root : from.getRoots()) {
			 Root<?> dest = to.from(root.getJavaType());
			 dest.alias(getOrCreateAlias(root));
			 copyJoins(root, dest);
			 if (copyFetches)
				 copyFetches(root, dest);
		 }
	}
	
	to.groupBy(from.getGroupList());
	to.distinct(from.isDistinct());
	
	if (from.getGroupRestriction() != null)
		to.having(from.getGroupRestriction());
	
	Predicate predicate = from.getRestriction();
	if (predicate != null)
		to.where(predicate);
}