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

x33g5p2x  于2022-01-28 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(258)

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

Root.fetch介绍

暂无

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public List<Product> readProductsByIds(List<Long> productIds) {
  if (productIds == null || productIds.size() == 0) {
    return null;
  }
  if (productIds.size() > 100) {
    logger.warn("Not recommended to use the readProductsByIds method for long lists of productIds, since " +
        "Hibernate is required to transform the distinct results. The list of requested" +
        "product ids was (" + productIds.size() +") in length.");
  }
  // Set up the criteria query that specifies we want to return Products
  CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
  Root<ProductImpl> product = criteria.from(ProductImpl.class);
  product.fetch("defaultSku", JoinType.LEFT);
  criteria.select(product);
  // We only want results that match the product IDs
  criteria.where(product.get("id").as(Long.class).in(
      sandBoxHelper.mergeCloneIds(ProductImpl.class,
          productIds.toArray(new Long[productIds.size()]))));
  TypedQuery<Product> query = em.createQuery(criteria);
  query.setHint(QueryHints.HINT_CACHEABLE, true);
  query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
  return query.getResultList();
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected CriteriaQuery<Product> getCriteriaForActiveProducts(Date currentDate, Long lastId) {
  // Set up the criteria query that specifies we want to return Products
  CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
  // The root of our search is Product
  Root<ProductImpl> product = criteria.from(ProductImpl.class);
  // We need to filter on active date on the sku
  Join<Product, Sku> sku = product.join("defaultSku");
  product.fetch("defaultSku");
  // Product objects are what we want back
  criteria.select(product);
  // Ensure the product is currently active
  List<Predicate> restrictions = new ArrayList<Predicate>();
  attachActiveRestriction(currentDate, product, sku, restrictions);
  if (lastId != null) {
    restrictions.add(builder.gt(product.get("id").as(Long.class), lastId));
  }
  // Add the restrictions to the criteria query
  criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
  //Add ordering so that paginated queries are consistent
  criteria.orderBy(builder.asc(product.get("id")));
  return criteria;
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void test_criteria_from_fetch_example() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    //tag::criteria-from-fetch-example[]
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Phone> criteria = builder.createQuery( Phone.class );
    Root<Phone> root = criteria.from( Phone.class );
    // Phone.person is a @ManyToOne
    Fetch<Phone, Person> personFetch = root.fetch( Phone_.person );
    // Person.addresses is an @ElementCollection
    Fetch<Person, String> addressesJoin = personFetch.fetch( Person_.addresses );
    criteria.where( builder.isNotEmpty( root.get( Phone_.calls ) ) );
    List<Phone> phones = entityManager.createQuery( criteria ).getResultList();
    //end::criteria-from-fetch-example[]
    assertEquals(2, phones.size());
  });
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
  public void hhh13151Test() throws Exception {
    Session s = openSession();

    // Prepare Query
    CriteriaBuilder cb = s.getCriteriaBuilder();
    CriteriaQuery<SuperEntity> criteria = cb.createQuery( SuperEntity.class );
    Root<SuperEntity> root = criteria.from( SuperEntity.class );
    cb.treat( root, SubEntity.class ).fetch( "subField" );

    // Execute
    Transaction tx = s.beginTransaction();
    List<SuperEntity> result = s.createQuery( criteria ).getResultList();
    tx.commit();
    s.close();

    // Check results
    SideEntity subField = ( (SubEntity) result.get( 0 ) ).getSubField();
    String name = subField.getName();
    assertTrue( name != null );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

CriteriaQuery<Employee> query = builder.createQuery( Employee.class );
Root<Employee> root = query.from( Employee.class );
root.fetch( "projects", JoinType.LEFT);
query.select(root).where(
  builder.and(

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

/** Add the needed fetches to a critera query */
protected void addFetches(final Root<StylesheetUserPreferencesImpl> descriptorRoot) {
  descriptorRoot.fetch(StylesheetUserPreferencesImpl_.layoutAttributes, JoinType.LEFT);
  descriptorRoot.fetch(StylesheetUserPreferencesImpl_.outputProperties, JoinType.LEFT);
  descriptorRoot.fetch(StylesheetUserPreferencesImpl_.parameters, JoinType.LEFT);
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework

@Override
  protected void prepareFetch(Root<T> root, QueryConfig config) {
    for (String path : fetchAssociations) {
      root.fetch(path);
    }
  }
}

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

@Override
protected void addFetches(Root<PortletExecutionAggregationImpl> root) {
  root.fetch(PortletExecutionAggregationImpl_.statisticalSummary, JoinType.LEFT);
}

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

@Override
protected void addFetches(Root<LoginAggregationImpl> root) {
  root.fetch(LoginAggregationImpl_.uniqueStrings, JoinType.LEFT);
}

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

@Override
protected void addFetches(Root<TabRenderAggregationImpl> root) {
  root.fetch(TabRenderAggregationImpl_.statisticalSummary, JoinType.LEFT);
}

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

@Override
protected void addFetches(Root<ConcurrentUserAggregationImpl> root) {
  root.fetch(ConcurrentUserAggregationImpl_.uniqueStrings, JoinType.LEFT);
}

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
@SuppressWarnings("hiding")
public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) {
  return getWrapped().fetch(attributeName, jt);
}

代码示例来源:origin: uaihebert/uaicriteria

public void createJoinInRoot(final String joinName, final JoinType joinType, final boolean isFetch) {
  if (isFetch) {
    this.joinFetch = root.fetch(joinName, joinType);
    return;
  }
  this.join = root.join(joinName, joinType);
}

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
@SuppressWarnings("hiding")
public <X, Y> Fetch<X, Y> fetch(String attributeName) {
  return getWrapped().fetch(attributeName);
}

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

/** Add all the fetches needed for completely loading the object graph */
protected void addFetches(final Root<PortletEntityImpl> definitionRoot) {
  definitionRoot
      .fetch(PortletEntityImpl_.portletPreferences, JoinType.LEFT)
      .fetch(PortletPreferencesImpl_.portletPreferences, JoinType.LEFT)
      .fetch(PortletPreferenceImpl_.values, JoinType.LEFT);
  definitionRoot.fetch(PortletEntityImpl_.windowStates, JoinType.LEFT);
}

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute, JoinType jt) {
  return getWrapped().fetch(attribute, jt);
}

代码示例来源:origin: tkaczmarzyk/specification-arg-resolver

@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  if (!Number.class.isAssignableFrom(query.getResultType())) { // do not join in count queries
    for (String path : pathsToFetch){
      root.fetch(path, joinType);
    }
  }
  return null;
}

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> attribute) {
  return getWrapped().fetch(attribute);
}

代码示例来源:origin: ZhongjunTian/spring-repository-plus

private void join(Root<Object> root, List<String> joinFetchTables, JoinType type) {
  if (joinFetchTables != null && (joinFetchTables.size() > 0)) {
    logger.debug("{} join root {} with table {}",
        type.name(), root.getJavaType(), joinFetchTables);
    for (String table : joinFetchTables) {
      if (table != null)
        root.fetch(table, type);
    }
  }
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework

@Override
protected void prepareFetch(Root<T> root, QueryConfig config) {
  for (ConditionalCriteria criteria : conditionalCriterias) {
    if (Operator.FetchEager.equals(criteria.getOperator())) {
      // TODO: this is not tested
      root.fetch(criteria.getPropertyFullName());
    } else if (Operator.FetchLazy.equals(criteria.getOperator())) {
      // TODO: fetchLazy is not supported actually
    }
  }
}

相关文章