本文整理了Java中javax.persistence.criteria.CriteriaQuery.from()
方法的一些代码示例,展示了CriteriaQuery.from()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CriteriaQuery.from()
方法的具体详情如下:
包路径:javax.persistence.criteria.CriteriaQuery
类名称:CriteriaQuery
方法名:from
暂无
代码示例来源:origin: spring-projects/spring-data-examples
public List<User> myCustomBatchOperation() {
CriteriaQuery<User> criteriaQuery = em.getCriteriaBuilder().createQuery(User.class);
criteriaQuery.select(criteriaQuery.from(User.class));
return em.createQuery(criteriaQuery).getResultList();
}
}
代码示例来源:origin: rapidoid/rapidoid
public <T> Results<T> of(Class<T> clazz) {
CriteriaQuery<T> query = cb().createQuery(clazz);
query.from(clazz);
return find(query);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_criteria_from_root_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::criteria-from-root-example[]
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Person> criteria = builder.createQuery( Person.class );
Root<Person> root = criteria.from( Person.class );
//end::criteria-from-root-example[]
});
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long readNumberOfAddresses() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
criteria.select(builder.count(criteria.from(CustomerAddressImpl.class)));
TypedQuery<Long> query = em.createQuery(criteria);
return query.getSingleResult();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long readNumberOfOrderItems() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
criteria.select(builder.count(criteria.from(OrderItemImpl.class)));
TypedQuery<Long> query = em.createQuery(criteria);
return query.getSingleResult(); }
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long readNumberOfOrders() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
criteria.select(builder.count(criteria.from(OrderImpl.class)));
TypedQuery<Long> query = em.createQuery(criteria);
return query.getSingleResult();
}
}
代码示例来源:origin: rapidoid/rapidoid
public long count(Class<?> clazz) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
cq.select(cb.count(cq.from(clazz)));
return em.createQuery(cq).getSingleResult();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Long readNumberOfCustomers() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
criteria.select(builder.count(criteria.from(CustomerImpl.class)));
TypedQuery<Long> query = em.createQuery(criteria);
return query.getSingleResult();
}
}
代码示例来源: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 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: 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 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 List<StructuredContent> findAllContentItems() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<StructuredContent> criteria = builder.createQuery(StructuredContent.class);
Root<StructuredContentImpl> sc = criteria.from(StructuredContentImpl.class);
criteria.select(sc);
try {
TypedQuery<StructuredContent> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<StructuredContent>();
}
}
代码示例来源: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: BroadleafCommerce/BroadleafCommerce
@Override
public List<URLHandler> findAllURLHandlers() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<URLHandler> criteria = builder.createQuery(URLHandler.class);
Root<URLHandlerImpl> handler = criteria.from(URLHandlerImpl.class);
criteria.select(handler);
TypedQuery<URLHandler> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
try {
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<URLHandler>();
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Page> readAllPages() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Page> criteria = builder.createQuery(Page.class);
Root<PageImpl> page = criteria.from(PageImpl.class);
criteria.select(page);
try {
Query query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
} catch (NoResultException e) {
return Collections.emptyList();
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<PageTemplate> readAllPageTemplates() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<PageTemplate> criteria = builder.createQuery(PageTemplate.class);
Root<PageTemplateImpl> template = criteria.from(PageTemplateImpl.class);
criteria.select(template);
try {
Query query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
} catch (NoResultException e) {
return Collections.emptyList();
}
}
代码示例来源: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 Long readTotalStaticAssetCount() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
criteria.select(builder.count(criteria.from(StaticAssetImpl.class)));
TypedQuery<Long> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getSingleResult();
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!