本文整理了Java中javax.persistence.criteria.Root.get
方法的一些代码示例,展示了Root.get
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Root.get
方法的具体详情如下:
包路径:javax.persistence.criteria.Root
类名称:Root
方法名:get
[英]Return the metamodel entity corresponding to the root.
[中]返回根对应的元模型实体。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<PageField> readPageFieldsByPageId(Long pageId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<PageField> criteria = builder.createQuery(PageField.class);
Root<PageFieldImpl> pageField = criteria.from(PageFieldImpl.class);
criteria.select(pageField);
Path<Object> path = pageField.get("page").get("id");
criteria.where(builder.equal(pageField.get("page").get("id"), pageId));
TypedQuery<PageField> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: spring-projects/spring-data-examples
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Root<Account> accounts = query.from(Account.class);
Path<Date> expiryDate = accounts.<Date> get("expiryDate");
Predicate customerIsAccountOwner = cb.equal(accounts.<Customer> get("customer"), root);
Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate());
return cb.and(customerIsAccountOwner, accountExpiryDateBefore);
}
};
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Translation> readTranslations(TranslatedEntity entity, String entityId, String fieldName) {
entityId = getUpdatedEntityId(entity, entityId);
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Translation> criteria = builder.createQuery(Translation.class);
Root<TranslationImpl> translation = criteria.from(TranslationImpl.class);
criteria.select(translation);
criteria.where(builder.equal(translation.get("entityType"), entity.getFriendlyType()),
builder.equal(translation.get("entityId"), entityId),
builder.equal(translation.get("fieldName"), fieldName)
);
TypedQuery<Translation> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder,
From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath,
List<Character> directValues) {
CriteriaQuery<Serializable> criteria = fieldPathBuilder.getCriteria();
Root<CountryImpl> blcCountry = criteria.from(CountryImpl.class);
Predicate join = builder.equal(
root.get("alpha2").as(String.class),
blcCountry.get("abbreviation").as(String.class)
);
return join;
}
})
代码示例来源:origin: kiegroup/jbpm
@Override
public Long findTaskIdByContentId( Long contentId ) {
check();
CriteriaBuilder builder = this.em.getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<TaskImpl> taskRoot = query.from(TaskImpl.class);
Root<ContentImpl> contentRoot = query.from(ContentImpl.class);
query.select(taskRoot.get(TaskImpl_.id));
Predicate taskContentJoinPred = builder.equal(
contentRoot.get(ContentImpl_.id),
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.outputContentId));
Predicate contentIdPred = builder.equal(
contentRoot.get(ContentImpl_.id),
contentId);
query.where(builder.and(taskContentJoinPred, contentIdPred));
Query choppedLiver = em.createQuery(query);
return (Long) choppedLiver.getSingleResult();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Attribute attr = mt.getAttribute(piece);
if (attr != null) {
Root additionalRoot = criteria.from(clazz);
restrictions.add(builder.equal(path, additionalRoot));
path = additionalRoot.get(piece);
found = true;
break;
代码示例来源:origin: stackoverflow.com
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Employee.class);
Root emp = cq.from(Employee.class);
<b>
<i>
Path<List<Project>>
</i>
</b>
projects = emp.get("projects"));
cq.where(cb.isEmpty(projects);
cq.select(emp);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Customer readCustomerByExternalId(String id) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
Root<? extends Customer> customer = criteria.from(entityConfiguration.lookupEntityClass(Customer.class.getName(), Customer.class));
criteria.select(customer);
criteria.where(builder.equal(customer.get("externalId"), id));
TypedQuery<Customer> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, false);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Customer");
List<Customer> resultList = query.getResultList();
return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
}
代码示例来源:origin: spring-projects/spring-data-examples
@Override
public void removedExpiredAccounts(LocalDate reference) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Account> query = cb.createQuery(Account.class);
Root<Account> account = query.from(Account.class);
query.where(cb.lessThan(account.get("expiryDate").as(Date.class), reference.toDateTimeAtStartOfDay().toDate()));
for (Account each : em.createQuery(query).getResultList()) {
em.remove(each);
}
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long countAllowedValuesForProductOptionById(Long productOptionId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<ProductOptionValueImpl> root = criteria.from(ProductOptionValueImpl.class);
criteria.select(builder.count(root));
List<Predicate> restrictions = new ArrayList<>();
List<Long> mergedIds = sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, productOptionId);
restrictions.add(root.get("productOption").in(mergedIds));
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Long> query = em.createQuery(criteria);
return query.getSingleResult();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public AdminPermission readAdminPermissionByNameAndType(String name, String type) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
criteria.select(adminPerm);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(adminPerm.get("name"), name));
restrictions.add(builder.equal(adminPerm.get("type"), type));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<AdminPermission> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminPermission> results = query.getResultList();
if (results == null || results.size() == 0) {
return null;
} else {
return results.get(0);
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Translation readTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode) {
entityId = getUpdatedEntityId(entity, entityId);
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Translation> criteria = builder.createQuery(Translation.class);
Root<TranslationImpl> translation = criteria.from(TranslationImpl.class);
criteria.select(translation);
criteria.where(builder.equal(translation.get("entityType"), entity.getFriendlyType()),
builder.equal(translation.get("entityId"), entityId),
builder.equal(translation.get("fieldName"), fieldName),
builder.equal(translation.get("localeCode"), localeCode)
);
TypedQuery<Translation> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
List<Translation> translations = query.getResultList();
if (translations.size() > 1) {
throw new IllegalStateException("Found multiple translations for: " + entity.getFriendlyType() + "|" + entityId + "|" + fieldName + "|" + localeCode);
}
if (!translations.isEmpty()) {
return translations.get(0);
}
return null;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public AdminPermission readAdminPermissionByName(String name) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
criteria.select(adminPerm);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(adminPerm.get("name"), name));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<AdminPermission> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminPermission> results = query.getResultList();
if (results == null || results.size() == 0) {
return null;
} else {
return results.get(0);
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<IndexFieldType> getIndexFieldTypes(FieldType facetFieldType) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<IndexFieldType> criteria = builder.createQuery(IndexFieldType.class);
Root<IndexFieldTypeImpl> root = criteria.from(IndexFieldTypeImpl.class);
criteria.select(root);
criteria.where(
builder.equal(root.get("fieldType").as(String.class), facetFieldType.getType())
);
TypedQuery<IndexFieldType> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Order> readOrdersByDateRange(final Date startDate, final Date endDate) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
Root<OrderImpl> order = criteria.from(OrderImpl.class);
criteria.select(order);
criteria.where(builder.between(order.<Date>get("submitDate"), startDate, endDate));
criteria.orderBy(builder.desc(order.get("submitDate")));
TypedQuery<Order> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Page> findPageByURI(String uri) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Page> criteriaQuery = builder.createQuery(Page.class);
Root pageRoot = criteriaQuery.from(PageImpl.class);
criteriaQuery.select(pageRoot);
List<Predicate> restrictions = new ArrayList<>();
restrictions.add(builder.equal(pageRoot.get("fullUrl"), uri));
Date currentDate = DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, getCurrentDateResolution());
addActiveDateRestrictions(builder, pageRoot, restrictions, currentDate, currentDate);
addOfflineRestriction(builder, pageRoot, restrictions);
criteriaQuery.where(restrictions.toArray(new Predicate[restrictions.size()]));
return getResultForQueryAndCache(criteriaQuery);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Order> readOrdersForCustomersInDateRange(List<Long> customerIds, Date startDate, Date endDate) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
Root<OrderImpl> order = criteria.from(OrderImpl.class);
criteria.select(order);
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<Order> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Page> findPageByURIAndActiveDate(final String uri, final Date activeDate) {
final CriteriaBuilder builder = em.getCriteriaBuilder();
final CriteriaQuery<Page> criteriaQuery = builder.createQuery(Page.class);
final Root pageRoot = criteriaQuery.from(PageImpl.class);
criteriaQuery.select(pageRoot);
final List<Predicate> restrictions = new ArrayList<>();
restrictions.add(builder.equal(pageRoot.get("fullUrl"), uri));
final Date nextDay = DateUtils.addDays(activeDate, 1);
addOfflineRestriction(builder, pageRoot, restrictions);
addActiveDateRestrictions(builder, pageRoot, restrictions, nextDay, activeDate);
criteriaQuery.where(restrictions.toArray(new Predicate[restrictions.size()]));
List<Page> pages = getResultForQueryAndCache(criteriaQuery);
return filterInactive(pages);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long countUsesByCustomer(Order order, Long customerId, Long offerId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<OfferAuditImpl> root = criteria.from(OfferAuditImpl.class);
criteria.select(builder.count(root));
List<Predicate> restrictions = new ArrayList<>();
restrictions.add(
builder.and(
builder.or(
builder.notEqual(root.get("orderId"), getOrderId(order)),
builder.isNull(root.get("orderId"))
),
builder.equal(root.get("customerId"), customerId),
builder.equal(root.get("offerId"), offerId)
)
);
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
try {
return em.createQuery(criteria).getSingleResult();
} catch (Exception e) {
LOG.error("Error counting offer uses by customer.", e);
return null;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Field readFieldByAbbreviation(String abbreviation) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Field> criteria = builder.createQuery(Field.class);
Root<FieldImpl> root = criteria.from(FieldImpl.class);
criteria.select(root);
criteria.where(
builder.equal(root.get("abbreviation").as(String.class), abbreviation)
);
TypedQuery<Field> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
try {
return query.getSingleResult();
} catch (javax.persistence.NoResultException e) {
//must not be an abbreviation
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!