List of usage examples for javax.persistence.criteria CriteriaBuilder or
Predicate or(Expression<Boolean> x, Expression<Boolean> y);
From source file:net.carinae.dev.async.dao.QueuedTaskHolderDaoJPA2.java
@Override public QueuedTaskHolder findNextTaskForExecution() { Calendar NOW = Calendar.getInstance(); // select qt from QueuedTask where // qt.startedStamp == null AND // (qth.triggerStamp == null || qth.triggerStamp < NOW) // order by qth.version ASC, qt.creationStamp ASC CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); CriteriaQuery<QueuedTaskHolder> cq = cb.createQuery(QueuedTaskHolder.class); Root<QueuedTaskHolder> qth = cq.from(QueuedTaskHolder.class); cq.select(qth)//from www . ja v a 2s . c om .where(cb.and(cb.isNull(qth.get(QueuedTaskHolder_.startedStamp)), cb.or(cb.isNull(qth.get(QueuedTaskHolder_.triggerStamp)), cb.lessThan(qth.get(QueuedTaskHolder_.triggerStamp), NOW)))) .orderBy(cb.asc(qth.get(QueuedTaskHolder_.version)), cb.asc(qth.get(QueuedTaskHolder_.creationStamp))); List<QueuedTaskHolder> results = this.entityManager.createQuery(cq).setMaxResults(1).getResultList(); if (results.isEmpty()) { return null; } else { return results.get(0); } }
From source file:org.openregistry.core.repository.jpa.JpaReferenceRepository.java
public Region getRegionByCodeOrName(final String code) { final CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder(); final CriteriaQuery<JpaRegionImpl> c = criteriaBuilder.createQuery(JpaRegionImpl.class); c.distinct(true);//from w w w . j av a2 s. co m final Root<JpaRegionImpl> region = c.from(JpaRegionImpl.class); c.where(criteriaBuilder.or(criteriaBuilder.equal(region.get(JpaRegionImpl_.code), code), criteriaBuilder.like(region.get(JpaRegionImpl_.name), code))); try { return this.entityManager.createQuery(c).getSingleResult(); } catch (final Exception e) { log.debug(e.getMessage(), e); return null; } }
From source file:net.groupbuy.dao.impl.PromotionDaoImpl.java
public List<Promotion> findList(Boolean hasBegun, Boolean hasEnded, Integer count, List<Filter> filters, List<Order> orders) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Promotion> criteriaQuery = criteriaBuilder.createQuery(Promotion.class); Root<Promotion> root = criteriaQuery.from(Promotion.class); criteriaQuery.select(root);//from ww w . j a v a 2 s. co m Predicate restrictions = criteriaBuilder.conjunction(); if (hasBegun != null) { if (hasBegun) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("beginDate").isNull(), criteriaBuilder.lessThanOrEqualTo(root.<Date>get("beginDate"), new Date()))); } else { restrictions = criteriaBuilder.and(restrictions, root.get("beginDate").isNotNull(), criteriaBuilder.greaterThan(root.<Date>get("beginDate"), new Date())); } } if (hasEnded != null) { if (hasEnded) { restrictions = criteriaBuilder.and(restrictions, root.get("endDate").isNotNull(), criteriaBuilder.lessThan(root.<Date>get("endDate"), new Date())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("endDate").isNull(), criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("endDate"), new Date()))); } } criteriaQuery.where(restrictions); return super.findList(criteriaQuery, null, count, filters, orders); }
From source file:de.egore911.hexanalyzer.persistence.selector.PluginSelector.java
@Nonnull @Override//ww w .ja v a 2s . c o m protected List<Predicate> generatePredicateList(@Nonnull CriteriaBuilder builder, @Nonnull Root<PluginEntity> from, @Nonnull CriteriaQuery<?> criteriaQuery) { List<Predicate> predicates = super.generatePredicateList(builder, from, criteriaQuery); if (extensionPoint != null) { builder.equal(from.get(PluginEntity_.extensionPoint), extensionPoint); } if (StringUtils.isNotEmpty(search)) { String likePattern = '%' + search + '%'; predicates.add(builder.or(builder.like(from.get(PluginEntity_.qualifiedName), likePattern), builder.like(from.get(PluginEntity_.source), likePattern))); } return predicates; }
From source file:org.openlmis.fulfillment.repository.custom.impl.OrderRepositoryImpl.java
/** * Retrieves the distinct UUIDs of the available requesting facilities. *//* w w w . j a v a 2 s . c o m*/ @Override public List<UUID> getRequestingFacilities(List<UUID> supplyingFacilityIds) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<UUID> query = builder.createQuery(UUID.class); Root<Order> root = query.from(Order.class); if (!isEmpty(supplyingFacilityIds)) { Predicate predicate = builder.disjunction(); for (Object elem : supplyingFacilityIds) { predicate = builder.or(predicate, builder.equal(root.get(SUPPLYING_FACILITY_ID), elem)); } query.where(predicate); } query.select(root.get(REQUESTING_FACILITY_ID)).distinct(true); return entityManager.createQuery(query).getResultList(); }
From source file:net.groupbuy.dao.impl.ArticleDaoImpl.java
public Page<Article> findPage(ArticleCategory articleCategory, List<Tag> tags, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Article> criteriaQuery = criteriaBuilder.createQuery(Article.class); Root<Article> root = criteriaQuery.from(Article.class); criteriaQuery.select(root);//from ww w . j a va2 s .c o m Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isPublication"), true)); if (articleCategory != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.equal(root.get("articleCategory"), articleCategory), criteriaBuilder.like(root.get("articleCategory").<String>get("treePath"), "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId() + ArticleCategory.TREE_PATH_SEPARATOR + "%"))); } if (tags != null && !tags.isEmpty()) { Subquery<Article> subquery = criteriaQuery.subquery(Article.class); Root<Article> subqueryRoot = subquery.from(Article.class); subquery.select(subqueryRoot); subquery.where(criteriaBuilder.equal(subqueryRoot, root), subqueryRoot.join("tags").in(tags)); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.exists(subquery)); } criteriaQuery.where(restrictions); criteriaQuery.orderBy(criteriaBuilder.desc(root.get("isTop"))); return super.findPage(criteriaQuery, pageable); }
From source file:net.groupbuy.dao.impl.ArticleDaoImpl.java
public List<Article> findList(ArticleCategory articleCategory, List<Tag> tags, Integer count, List<Filter> filters, List<Order> orders) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Article> criteriaQuery = criteriaBuilder.createQuery(Article.class); Root<Article> root = criteriaQuery.from(Article.class); criteriaQuery.select(root);// w ww . j av a 2s.c o m Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isPublication"), true)); if (articleCategory != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.equal(root.get("articleCategory"), articleCategory), criteriaBuilder.like(root.get("articleCategory").<String>get("treePath"), "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId() + ArticleCategory.TREE_PATH_SEPARATOR + "%"))); } if (tags != null && !tags.isEmpty()) { Subquery<Article> subquery = criteriaQuery.subquery(Article.class); Root<Article> subqueryRoot = subquery.from(Article.class); subquery.select(subqueryRoot); subquery.where(criteriaBuilder.equal(subqueryRoot, root), subqueryRoot.join("tags").in(tags)); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.exists(subquery)); } criteriaQuery.where(restrictions); criteriaQuery.orderBy(criteriaBuilder.desc(root.get("isTop"))); return super.findList(criteriaQuery, null, count, filters, orders); }
From source file:eu.uqasar.service.user.UserService.java
public boolean ldapBasedUserExists(final LdapUser user) { logger.infof("looking for users with username %s or mail %s", user.getUserName(), user.getMail()); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); Predicate userName = cb.equal(root.get(User_.userName), user.getUserName()); Predicate mail = cb.equal(root.get(User_.mail), user.getMail()); query.where(cb.or(userName, mail)); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); return !resultList.isEmpty(); }
From source file:net.groupbuy.dao.impl.ArticleDaoImpl.java
public List<Article> findList(ArticleCategory articleCategory, Date beginDate, Date endDate, Integer first, Integer count) {/*from w w w.jav a 2 s .com*/ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Article> criteriaQuery = criteriaBuilder.createQuery(Article.class); Root<Article> root = criteriaQuery.from(Article.class); criteriaQuery.select(root); Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isPublication"), true)); if (articleCategory != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.equal(root.get("articleCategory"), articleCategory), criteriaBuilder.like(root.get("articleCategory").<String>get("treePath"), "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId() + ArticleCategory.TREE_PATH_SEPARATOR + "%"))); } if (beginDate != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("createDate"), beginDate)); } if (endDate != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date>get("createDate"), endDate)); } criteriaQuery.where(restrictions); criteriaQuery.orderBy(criteriaBuilder.desc(root.get("isTop"))); return super.findList(criteriaQuery, first, count, null, null); }
From source file:com.expressui.sample.view.role.RoleQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Role> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(name)) { ParameterExpression<String> p = builder.parameter(String.class, "name"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("name")), p)); }/*from w ww . j a v a 2 s. c o m*/ if (!isEmpty(doesNotBelongToUser)) { ParameterExpression<User> p = builder.parameter(User.class, "doesNotBelongToUser"); Join join = rootEntity.join("userRoles", JoinType.LEFT); criteria.add(builder.or(builder.notEqual(join.get("user"), p), builder.isNull(join.get("user")))); } return criteria; }