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

x33g5p2x  于2022-01-21 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(110)

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

Join.fetch介绍

暂无

代码示例

代码示例来源:origin: org.lorislab.armonitor/armonitor-ejb

/**
 * Gets the projects list for the dashboard.
 *
 * @return the projects list for the dashboard.
 */
public List<StoreProject> getDashboardProjects() {
  List<StoreProject> result = new ArrayList<>();
  CriteriaBuilder cb = getBaseEAO().getCriteriaBuilder();
  CriteriaQuery<StoreProject> cq = getBaseEAO().createCriteriaQuery();
  Root<StoreProject> root = cq.from(StoreProject.class);
  cq.distinct(true);
  List<Predicate> predicates = new ArrayList<>();
  predicates.add(cb.equal(root.get(StoreProject_.enabled), true));
  Join<StoreProject, StoreApplication> applications = (Join<StoreProject, StoreApplication>) root.fetch(StoreProject_.applications, JoinType.LEFT);
  predicates.add(cb.equal(applications.get(StoreApplication_.enabled), true));
  Join<StoreApplication, StoreSystem> systems = (Join<StoreApplication, StoreSystem>) applications.fetch(StoreApplication_.systems, JoinType.LEFT);
  predicates.add(cb.equal(systems.get(StoreSystem_.enabled), true));
  
  cq.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
  try {
    TypedQuery<StoreProject> typeQuery = getBaseEAO().createTypedQuery(cq);
    result = typeQuery.getResultList();
  } catch (NoResultException ex) {
    // do nothing
  }
  return result;
}

代码示例来源:origin: devicehive/devicehive-java-server

@SuppressWarnings("unchecked")
  private static List<Predicate> deviceSpecificPrincipalPredicates(CriteriaBuilder cb, Root<Device> from, Optional<HivePrincipal> principal) {
    final List<Predicate> predicates = new LinkedList<>();
    final Join<Device, Network> networkJoin = (Join) from.fetch("network", JoinType.LEFT);
    final Join<Device, DeviceType> deviceTypeJoin = (Join) from.fetch("deviceType", JoinType.LEFT);
    principal.ifPresent(p -> {
      UserVO user = p.getUser();

      if (user != null && !user.isAdmin()) {

        // Joining after check to prevent duplicate objects
        final Join<Device, Network> usersJoin = (Join) networkJoin.fetch("users", JoinType.LEFT);
        predicates.add(cb.equal(usersJoin.<Long>get("id"), user.getId()));
      }

      if (p.getNetworkIds() != null) {
        predicates.add(networkJoin.<Long>get("id").in(p.getNetworkIds()));
      }

      if (p.getDeviceTypeIds() != null) {
        predicates.add(deviceTypeJoin.<Long>get("id").in(p.getDeviceTypeIds()));
      }
    });

    return predicates;
  }
}

相关文章