本文整理了Java中javax.persistence.EntityManager.getCriteriaBuilder()
方法的一些代码示例,展示了EntityManager.getCriteriaBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.getCriteriaBuilder()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:getCriteriaBuilder
[英]Return an instance of CriteriaBuilder
for the creation of CriteriaQuery
objects.
[中]返回用于创建CriteriaQuery
对象的CriteriaBuilder
实例。
代码示例来源: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: 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: 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 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: 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: 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 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<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 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: 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 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();
}
内容来源于网络,如有侵权,请联系作者删除!