本文整理了Java中javax.persistence.criteria.Root.join
方法的一些代码示例,展示了Root.join
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Root.join
方法的具体详情如下:
包路径:javax.persistence.criteria.Root
类名称:Root
方法名:join
暂无
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Boolean offerCodeIsUsed(OfferCode code) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
Root<OrderImpl> baseOrder = criteria.from(OrderImpl.class);
criteria.select(baseOrder);
Join<OrderImpl, OfferCodeImpl> join = baseOrder.join("addedOfferCodes");
criteria.where(builder.equal(join.get("id"), code.getId()));
TypedQuery<Order> query = em.createQuery(criteria);
try {
query.getSingleResult();
} catch (NoResultException e) {
return false;
}
return true;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<IndexField> readAllIndexFieldsByFieldId(Long fieldId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
Root<IndexFieldImpl> search = criteria.from(IndexFieldImpl.class);
criteria.select(search);
criteria.where(
builder.equal(search.join("field").get("id").as(Long.class), fieldId)
);
TypedQuery<IndexField> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected Long readCountAllActiveProductsInternal(Date currentDate) {
// Set up the criteria query that specifies we want to return a Long
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.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");
// We want the count of products
criteria.select(builder.count(product));
// Ensure the product is currently active
List<Predicate> restrictions = new ArrayList<Predicate>();
attachActiveRestriction(currentDate, product, sku, restrictions);
// Add the restrictions to the criteria query
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Long> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getSingleResult();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public IndexField readIndexFieldByFieldId(Long fieldId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
Root<IndexFieldImpl> search = criteria.from(IndexFieldImpl.class);
criteria.select(search);
criteria.where(
builder.equal(search.join("field").get("id").as(Long.class), fieldId)
);
TypedQuery<IndexField> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<OrderItem> readOrderItemsForCustomersInDateRange(List<Long> customerIds, Date startDate, Date endDate) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
Root<OrderImpl> order = criteria.from(OrderImpl.class);
Join<Order, OrderItem> orderItems = order.join("orderItems");
criteria.select(orderItems);
List<Predicate> restrictions = new ArrayList<>();
restrictions.add(builder.between(order.<Date>get("submitDate"), startDate, endDate));
restrictions.add(order.get("customer").get("id").in(customerIds));
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
criteria.orderBy(builder.desc(order.get("customer")), builder.asc(order.get("submitDate")));
TypedQuery<OrderItem> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
private TypedQuery<Long> getProductIdsUsingProductOptionByIdQuery(Long productOptionId, boolean count) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The root of our search is ProductOptionXref
Root<ProductOptionXrefImpl> productOptionXref = criteria.from(ProductOptionXrefImpl.class);
Join<ProductOptionXref, Product> product = productOptionXref.join("product");
Join<ProductOptionXref, ProductOption> productOption = productOptionXref.join("productOption");
if (count) {
criteria.select(builder.count(product));
} else {
// Product IDs are what we want back
criteria.select(product.get("id").as(Long.class));
}
criteria.distinct(true);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(productOption.get("id").in(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, productOptionId)));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return em.createQuery(criteria);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<OrderItem> readBatchOrderItems(int start, int count, List<OrderStatus> statuses) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
Root<OrderImpl> order = criteria.from(OrderImpl.class);
Join<Order, OrderItem> orderItems = order.join("orderItems");
criteria.select(orderItems);
List<Predicate> restrictions = new ArrayList<>();
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
if (CollectionUtils.isNotEmpty(statuses)) {
// We only want results that match the orders with the correct status
ArrayList<String> statusStrings = new ArrayList<String>();
for (OrderStatus status : statuses) {
statusStrings.add(status.getType());
}
criteria.where(order.get("status").as(String.class).in(statusStrings));
}
TypedQuery<OrderItem> query = em.createQuery(criteria);
query.setFirstResult(start);
query.setMaxResults(count);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
return query.getResultList();
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Join<CategoryProductXref, Product> product = productXref.join("product");
Join<Product, Sku> sku = product.join("defaultSku");
Join<CategoryProductXref, Category> category = productXref.join("category");
代码示例来源: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: BroadleafCommerce/BroadleafCommerce
@Override
public SearchFacet readSearchFacetForField(Field field) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class);
Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class);
criteria.select(facet);
criteria.where(
builder.equal(facet.join("fieldType").join("indexField").join("field").get("id").as(Long.class), field.getId())
);
TypedQuery<SearchFacet> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
fieldName = fieldName.substring("defaultSku.".length());
} else if (fieldName.contains("productAttributes.")) {
pathToUse = product.join("productAttributes");
代码示例来源:origin: kiegroup/jbpm
|| listId.equals(CREATED_BY_LIST) ) {
if( taskDataJoin == null ) {
taskDataJoin = taskRoot.join(TaskImpl_.taskData);
|| listId.equals(EXCLUDED_OWNER_ID_LIST) ) {
if( peopleAssignJoin == null ) {
peopleAssignJoin = taskRoot.join(TaskImpl_.peopleAssignments);
} else {
if( taskDataJoin == null ) {
taskDataJoin = taskRoot.join(TaskImpl_.taskData);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Join<Product, Sku> sku = product.join("defaultSku");
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_criteria_from_join_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::criteria-from-join-example[]
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Phone> criteria = builder.createQuery( Phone.class );
Root<Phone> root = criteria.from( Phone.class );
// Phone.person is a @ManyToOne
Join<Phone, Person> personJoin = root.join( Phone_.person );
// Person.addresses is an @ElementCollection
Join<Person, String> addressesJoin = personJoin.join( Person_.addresses );
criteria.where( builder.isNotEmpty( root.get( Phone_.calls ) ) );
List<Phone> phones = entityManager.createQuery( criteria ).getResultList();
//end::criteria-from-join-example[]
assertEquals(2, phones.size());
});
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<SearchFacet> readAllSearchFacets(FieldEntity entityType) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class);
Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class);
criteria.select(facet);
Path<Character> archived = facet.get("archiveStatus").get("archived");
criteria.where(
builder.equal(facet.get("showOnSearch").as(Boolean.class), true),
builder.or(builder.isNull(archived.as(String.class)),
builder.notEqual(archived.as(Character.class), 'Y')),
facet.join("fieldType")
.join("indexField")
.join("field")
.get("entityType")
.as(String.class)
.in(entityType.getAllLookupTypes())
);
TypedQuery<SearchFacet> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
return query.getResultList();
}
代码示例来源: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
peopleAssignJoin = taskRoot.join(TaskImpl_.peopleAssignments);
代码示例来源:origin: kiegroup/jbpm
taskRoot.join(TaskImpl_.taskData); // added for convienence sake, since other logic expects to find this join
代码示例来源:origin: kiegroup/jbpm
Join<TaskImpl, TaskDataImpl> join = taskRoot.join(TaskImpl_.taskData);
Join<TaskImpl, PeopleAssignmentsImpl> peopleAssign = taskRoot.join(TaskImpl_.peopleAssignments);
ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> busAdmins = peopleAssign.join(PeopleAssignmentsImpl_.businessAdministrators, JoinType.LEFT);
ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> potOwners = peopleAssign.join(PeopleAssignmentsImpl_.potentialOwners, JoinType.LEFT);
代码示例来源:origin: jamesagnew/hapi-fhir
switch (theType) {
case DATE:
join = myResourceTableRoot.join("myParamsDate", JoinType.LEFT);
break;
case NUMBER:
join = myResourceTableRoot.join("myParamsNumber", JoinType.LEFT);
break;
case QUANTITY:
join = myResourceTableRoot.join("myParamsQuantity", JoinType.LEFT);
break;
case REFERENCE:
join = myResourceTableRoot.join("myResourceLinks", JoinType.LEFT);
break;
case STRING:
join = myResourceTableRoot.join("myParamsString", JoinType.LEFT);
break;
case URI:
join = myResourceTableRoot.join("myParamsUri", JoinType.LEFT);
break;
case TOKEN:
join = myResourceTableRoot.join("myParamsToken", JoinType.LEFT);
break;
内容来源于网络,如有侵权,请联系作者删除!