javax.persistence.criteria.CriteriaQuery.getRoots()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中javax.persistence.criteria.CriteriaQuery.getRoots()方法的一些代码示例,展示了CriteriaQuery.getRoots()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CriteriaQuery.getRoots()方法的具体详情如下:
包路径:javax.persistence.criteria.CriteriaQuery
类名称:CriteriaQuery
方法名:getRoots

CriteriaQuery.getRoots介绍

暂无

代码示例

代码示例来源:origin: kiegroup/jbpm

@SuppressWarnings("unchecked")
public static <T> Expression defaultGetEntityField(CriteriaQuery<T> query, String listId, Attribute attr) {
  Expression entityField = null;
  if( attr != null ) {
    Class attrType = attr.getDeclaringType().getJavaType();
    for( From from : query.getRoots() ) {
      if( from.getJavaType().equals(attrType) ) {
        if( attr != null ) {
          if( attr instanceof SingularAttribute ) {
            entityField = from.get((SingularAttribute) attr);
          } else if( attr instanceof PluralAttribute ) {
            entityField = from.get((PluralAttribute) attr);
          } else {
            throw new IllegalStateException("Unexpected attribute type when processing criteria with list id " + listId + ": " + attr.getClass().getName() );
          }
          break;
        }
      }
    }
  }
  // if entityField  == null, this is because this QueryCriteria is a implementation specific criteria, such as "LAST_VARIABLE_LIST"
  return entityField;
}

代码示例来源:origin: kiegroup/jbpm

@Override
protected <T> Expression getEntityField(CriteriaQuery<T> query, String listId, Attribute attr) {
  if( attr == null ) {
    return null;
  }
  Root<TaskImpl> taskRoot = null;
  Join<TaskImpl, TaskDataImpl> taskDataJoin = null;
  Join<TaskImpl, PeopleAssignmentsImpl> peopAssignJoin = null;
  for( Root root : query.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> join : taskRoot.getJoins() ) {
       if( TaskDataImpl.class.equals(join.getJavaType()) ) {
         taskDataJoin = (Join<TaskImpl, TaskDataImpl>) join;
       } else if( PeopleAssignmentsImpl.class.equals(join.getJavaType()) )  {
         peopAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) join;
       }
      }
    }
  }
  assert taskRoot != null : "Unable to find TaskImpl Root in query!";
  if( taskDataJoin == null ) {
    taskDataJoin = taskRoot.join(TaskImpl_.taskData);
  }
  assert taskDataJoin != null : "Unable to find TaskDataImpl Join in query!";
  return taskImplSpecificGetEntityField(query, taskRoot,
      taskDataJoin, peopAssignJoin,
      listId, attr);
}

代码示例来源:origin: kiegroup/jbpm

private <T> void useDistinctWhenLefOuterJoinsPresent(CriteriaQuery<T> criteriaQuery) {
  boolean useDistinct = false;
  Root<TaskImpl> taskRoot = null;
  ROOTS_FOR: for( Root root : criteriaQuery.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> taskJoin : taskRoot.getJoins() ) {
       if( PeopleAssignmentsImpl.class.equals(taskJoin.getJavaType()) )  {
         Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) taskJoin;
         if( JoinType.LEFT.equals(peopleAssignJoin.getJoinType()) ) {
           useDistinct = true;
           break ROOTS_FOR;
         }
         for( Join peopleAssignJoinJoin : peopleAssignJoin.getJoins() ) {
           if( JoinType.LEFT.equals(peopleAssignJoinJoin.getJoinType()) ) {
             useDistinct = true;
             break ROOTS_FOR;
           }
         }
       }
      }
    }
  }
  if( useDistinct ) {
    criteriaQuery.distinct(true);
  }
}

代码示例来源:origin: lordlothar99/strategy-spring-security-acl

@SuppressWarnings("unchecked")
private Root<Object> root(CriteriaQuery<?> criteriaQuery) {
 return (Root<Object>) criteriaQuery.getRoots().iterator().next();
}

代码示例来源:origin: Impetus/Kundera

Set<Root<?>> roots = criteriaQuery.getRoots();

代码示例来源:origin: com.walterjwhite.infrastructure.datastore.modules/google-guice-persist-criteria-builder

public int count(CriteriaQuery criteriaQuery) {
 return (count(
   criteriaQuery,
   (Root<? extends AbstractEntity>) criteriaQuery.getRoots().iterator().next()));
}

代码示例来源:origin: com.charlyghislain.authenticator/authenticator-ejb

private static <T extends WithId> Root<T> getMainSelection(CriteriaQuery<T> query) {
  return query.getRoots().stream()
      .filter(r -> r.getJavaType().isAssignableFrom(query.getResultType()))
      .map(r -> (Root<T>) r)
      .filter(r -> !r.isCorrelated())
      .findFirst()
      .orElseThrow(IllegalStateException::new);
}

代码示例来源:origin: org.jasig.portal/uPortal-utils-core

/**
 * Creates the cache region name for the criteria query
 *
 * @param criteriaQuery The criteria to create the cache name for
 */
protected final <T> String getCacheRegionName(CriteriaQuery<T> criteriaQuery) {
  final Set<Root<?>> roots = criteriaQuery.getRoots();
  final Class<?> cacheRegionType = roots.iterator().next().getJavaType();
  final String cacheRegion = cacheRegionType.getName() + QUERY_SUFFIX;
  if (roots.size() > 1) {
    logger.warn(
        "Query "
            + criteriaQuery
            + " in "
            + this.getClass()
            + " has "
            + roots.size()
            + " roots. The first will be used to generated the cache region name: "
            + cacheRegion);
  }
  return cacheRegion;
}

代码示例来源:origin: Jasig/uPortal

/**
 * Creates the cache region name for the criteria query
 *
 * @param criteriaQuery The criteria to create the cache name for
 */
protected final <T> String getCacheRegionName(CriteriaQuery<T> criteriaQuery) {
  final Set<Root<?>> roots = criteriaQuery.getRoots();
  final Class<?> cacheRegionType = roots.iterator().next().getJavaType();
  final String cacheRegion = cacheRegionType.getName() + QUERY_SUFFIX;
  if (roots.size() > 1) {
    logger.warn(
        "Query "
            + criteriaQuery
            + " in "
            + this.getClass()
            + " has "
            + roots.size()
            + " roots. The first will be used to generated the cache region name: "
            + cacheRegion);
  }
  return cacheRegion;
}

代码示例来源:origin: com.blazebit/blaze-persistence-integration-spring-data-base

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void processSpecification(CriteriaQuery<?> criteriaQuery, Object[] values) {
  BlazeCriteriaQuery<?> blazeCriteriaQuery = (BlazeCriteriaQuery<?>) criteriaQuery;
  int specificationIndex = parameters.getSpecificationIndex();
  if (specificationIndex >= 0) {
    Specification<?> specification = (Specification<?>) values[specificationIndex];
    Root root = criteriaQuery.getRoots().iterator().next();
    BlazeCriteriaBuilder criteriaBuilder = blazeCriteriaQuery.getCriteriaBuilder();
    Predicate predicate = specification.toPredicate(root, criteriaQuery, criteriaBuilder);
    criteriaQuery.where(predicate);
  }
}

代码示例来源:origin: Blazebit/blaze-persistence

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void processSpecification(CriteriaQuery<?> criteriaQuery, Object[] values) {
  BlazeCriteriaQuery<?> blazeCriteriaQuery = (BlazeCriteriaQuery<?>) criteriaQuery;
  int specificationIndex = parameters.getSpecificationIndex();
  if (specificationIndex >= 0) {
    Specification<?> specification = (Specification<?>) values[specificationIndex];
    Root root = criteriaQuery.getRoots().iterator().next();
    BlazeCriteriaBuilder criteriaBuilder = blazeCriteriaQuery.getCriteriaBuilder();
    Predicate predicate = specification.toPredicate(root, criteriaQuery, criteriaBuilder);
    criteriaQuery.where(predicate);
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

/**
 * 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
 */
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;
}

代码示例来源:origin: katharsis-project/katharsis-framework

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;
}

代码示例来源:origin: katharsis-project/katharsis-framework

@Override
@SuppressWarnings({ "rawtypes" })
public long getTotalRowCount() {
  Selection<T> selection = query.getSelection();
  List<Order> orderList = query.getOrderList();
  try {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    Expression<Long> countExpr;
    Set<Root<?>> roots = query.getRoots();
    if (roots.size() != 1) {
      throw new IllegalStateException("cannot compute totalRowCount in case of multiple query roots");
    }
    if (!query.getGroupList().isEmpty()) {
      throw new IllegalStateException("cannot compute totalRowCount for grouped queries");
    }
    // transform query to a count query
    Root root = roots.iterator().next();
    countExpr = builder.count(root);
    query.multiselect(countExpr);
    query.orderBy(new ArrayList<Order>());
    TypedQuery countQuery = em.createQuery(query);
    return (Long) countQuery.getSingleResult();
  }
  finally {
    // transform count query back to regular query
    query.multiselect(selection);
    query.orderBy(orderList);
  }
}

代码示例来源:origin: org.jbpm/jbpm-human-task-jpa

@Override
protected <T> Expression getEntityField(CriteriaQuery<T> query, String listId, Attribute attr) {
  if( attr == null ) {
    return null;
  }
  Root<TaskImpl> taskRoot = null;
  Join<TaskImpl, TaskDataImpl> taskDataJoin = null;
  Join<TaskImpl, PeopleAssignmentsImpl> peopAssignJoin = null;
  for( Root root : query.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> join : taskRoot.getJoins() ) {
       if( TaskDataImpl.class.equals(join.getJavaType()) ) {
         taskDataJoin = (Join<TaskImpl, TaskDataImpl>) join;
       } else if( PeopleAssignmentsImpl.class.equals(join.getJavaType()) )  {
         peopAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) join;
       }
      }
    }
  }
  assert taskRoot != null : "Unable to find TaskImpl Root in query!";
  if( taskDataJoin == null ) {
    taskDataJoin = taskRoot.join(TaskImpl_.taskData);
  }
  assert taskDataJoin != null : "Unable to find TaskDataImpl Join in query!";
  return taskImplSpecificGetEntityField(query, taskRoot,
      taskDataJoin, peopAssignJoin,
      listId, attr);
}

代码示例来源:origin: org.jbpm/jbpm-human-task-jpa

private <T> void useDistinctWhenLefOuterJoinsPresent(CriteriaQuery<T> criteriaQuery) {
  boolean useDistinct = false;
  Root<TaskImpl> taskRoot = null;
  ROOTS_FOR: for( Root root : criteriaQuery.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> taskJoin : taskRoot.getJoins() ) {
       if( PeopleAssignmentsImpl.class.equals(taskJoin.getJavaType()) )  {
         Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) taskJoin;
         if( JoinType.LEFT.equals(peopleAssignJoin.getJoinType()) ) {
           useDistinct = true;
           break ROOTS_FOR;
         }
         for( Join peopleAssignJoinJoin : peopleAssignJoin.getJoins() ) {
           if( JoinType.LEFT.equals(peopleAssignJoinJoin.getJoinType()) ) {
             useDistinct = true;
             break ROOTS_FOR;
           }
         }
       }
      }
    }
  }
  if( useDistinct ) {
    criteriaQuery.distinct(true);
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

/**
 * Copy Criteria without Selection
 *
 * @param from source Criteria
 * @param to   destination Criteria
 */
public static void copyCriteriaNoSelection(CriteriaQuery<?> from, CriteriaQuery<?> to) {
  // Copy Roots
  for (Root<?> root : from.getRoots()) {
    Root<?> dest = to.from(root.getJavaType());
    dest.alias(getOrCreateAlias(root));
    copyJoins(root, dest);
  }
  if (from.getGroupList() != null) to.groupBy(from.getGroupList());
  to.distinct(from.isDistinct());
  if (from.getGroupRestriction() != null) to.having(from.getGroupRestriction());
  if (from.getRestriction() != null) to.where(from.getRestriction());
  if (from.getOrderList() != null) to.orderBy(from.getOrderList());
}

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-mapper

Set<Root<?>> roots = criteriaQuery.getRoots();

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

Set<Root<?>> roots = criteriaQuery.getRoots();

相关文章