List of usage examples for javax.persistence.criteria Root fetch
<Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute, JoinType jt);
From source file:org.apereo.portal.persondir.dao.jpa.JpaLocalAccountDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { this.nameParameter = this.createParameterExpression(String.class, "name"); this.findAllAccountsQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<LocalAccountPersonImpl>>() { @Override/*from w w w. j ava 2s.c om*/ public CriteriaQuery<LocalAccountPersonImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<LocalAccountPersonImpl> criteriaQuery = cb .createQuery(LocalAccountPersonImpl.class); final Root<LocalAccountPersonImpl> accountRoot = criteriaQuery .from(LocalAccountPersonImpl.class); accountRoot.fetch(LocalAccountPersonImpl_.attributes, JoinType.LEFT) .fetch(LocalAccountPersonAttributeImpl_.values, JoinType.LEFT); criteriaQuery.select(accountRoot); return criteriaQuery; } }); this.findAccountByNameQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<LocalAccountPersonImpl>>() { @Override public CriteriaQuery<LocalAccountPersonImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<LocalAccountPersonImpl> criteriaQuery = cb .createQuery(LocalAccountPersonImpl.class); final Root<LocalAccountPersonImpl> accountRoot = criteriaQuery .from(LocalAccountPersonImpl.class); accountRoot.fetch(LocalAccountPersonImpl_.attributes, JoinType.LEFT) .fetch(LocalAccountPersonAttributeImpl_.values, JoinType.LEFT); criteriaQuery.select(accountRoot); criteriaQuery.where(cb.equal(accountRoot.get(LocalAccountPersonImpl_.name), nameParameter)); return criteriaQuery; } }); this.findAvailableAttributesQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<String>>() { @Override public CriteriaQuery<String> apply(CriteriaBuilder cb) { final CriteriaQuery<String> criteriaQuery = cb.createQuery(String.class); final Root<LocalAccountPersonAttributeImpl> accountRoot = criteriaQuery .from(LocalAccountPersonAttributeImpl.class); criteriaQuery.select(accountRoot.get(LocalAccountPersonAttributeImpl_.name)); criteriaQuery.distinct(true); return criteriaQuery; } }); }
From source file:org.apereo.portal.portlet.dao.jpa.JpaPortletDefinitionDao.java
/** * Add all the fetches needed for completely loading the object graph *//*from ww w . j a va 2 s.co m*/ protected void addFetches(final Root<PortletDefinitionImpl> definitionRoot) { definitionRoot.fetch(PortletDefinitionImpl_.portletPreferences, JoinType.LEFT) .fetch(PortletPreferencesImpl_.portletPreferences, JoinType.LEFT) .fetch(PortletPreferenceImpl_.values, JoinType.LEFT); definitionRoot.fetch(PortletDefinitionImpl_.parameters, JoinType.LEFT); definitionRoot.fetch(PortletDefinitionImpl_.localizations, JoinType.LEFT); }
From source file:org.apereo.portal.portlet.dao.jpa.JpaPortletEntityDao.java
/** * Add all the fetches needed for completely loading the object graph *//*w w w . j av a2 s . c o m*/ 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); }
From source file:org.broadleafcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByIds(List<Long> productIds) { if (productIds == null || productIds.size() == 0) { return null; }/*ww w. j av a2 s. co m*/ 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); FetchParent fetchParent = product.fetch("defaultSku", JoinType.LEFT); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { fetchParent.fetch("skuMedia", 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()])))); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { criteria.distinct(true); } TypedQuery<Product> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.jasig.portal.permission.dao.jpa.JpaPermissionOwnerDao.java
@Override public void afterPropertiesSet() throws Exception { this.fnameParameter = this.createParameterExpression(String.class, "fname"); this.findAllPermissionOwners = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<PermissionOwnerImpl>>() { @Override//ww w. j a v a2 s .co m public CriteriaQuery<PermissionOwnerImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<PermissionOwnerImpl> criteriaQuery = cb .createQuery(PermissionOwnerImpl.class); final Root<PermissionOwnerImpl> ownerRoot = criteriaQuery.from(PermissionOwnerImpl.class); criteriaQuery.select(ownerRoot); ownerRoot.fetch(PermissionOwnerImpl_.activities, JoinType.LEFT); return criteriaQuery; } }); this.findPermissionOwnerByFname = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<PermissionOwnerImpl>>() { @Override public CriteriaQuery<PermissionOwnerImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<PermissionOwnerImpl> criteriaQuery = cb .createQuery(PermissionOwnerImpl.class); final Root<PermissionOwnerImpl> ownerRoot = criteriaQuery.from(PermissionOwnerImpl.class); criteriaQuery.select(ownerRoot); ownerRoot.fetch(PermissionOwnerImpl_.activities, JoinType.LEFT); criteriaQuery.where(cb.equal(ownerRoot.get(PermissionOwnerImpl_.fname), fnameParameter)); return criteriaQuery; } }); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByIds(List<Long> productIds) { if (productIds == null || productIds.size() == 0) { return null; }//from www.j av a 2 s. c o m 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); FetchParent fetchParent = product.fetch("defaultSku", JoinType.LEFT); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { fetchParent.fetch("skuMedia", 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(em, ProductImpl.class, productIds.toArray(new Long[productIds.size()])))); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { criteria.distinct(true); } TypedQuery<Product> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }