List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * // w ww .ja v a 2 s. c om * @param adapter * @return */ public List<CubesMetricMeasurement> getAllByAdapter(AdapterSettings adapter) { logger.info("Get measurements for adapter: " + adapter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.adapter), adapter); query.where(condition); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * /*ww w.j a va 2s.c om*/ * @param first * @param count * @param adapter * @return */ public List<CubesMetricMeasurement> getAllByAdapter(int first, int count, AdapterSettings adapter) { logger.info("Get measurements for adapter: " + adapter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.adapter), adapter); query.orderBy(cb.asc(root.get(CubesMetricMeasurement_.self))); query.where(condition); return em.createQuery(query).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * /*from w w w . j a v a 2s. c o m*/ * @param metric * @return * @throws uQasarException */ public List<CubesMetricMeasurement> getMeasurementsForMetric(String metric) throws uQasarException { logger.info("Get measurements for metric: " + metric); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.cubesMetric), metric); query.where(condition); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * @param project// w ww.j a va 2s. c om * @return List with all the measurements of a project */ public List<CubesMetricMeasurement> getMeasurementByProject(Project project) { logger.info("Obtaining measurements for the project: " + project); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.project), project); query.where(condition); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.user.UserService.java
private List<Predicate> getFilterPredicates(final UserFilterStructure filter, CriteriaBuilder cb, Root<User> from) { List<Predicate> predicates = new ArrayList<>(); if (filter == null) { return predicates; }/* w ww.ja va 2 s . c o m*/ if (filter.getRole() != null) { predicates.add(cb.equal(from.get(User_.userRole), filter.getRole())); } if (filter.getSource() != null) { predicates.add(cb.equal(from.get(User_.source), filter.getSource())); } if (filter.getStatus() != null) { predicates.add(cb.equal(from.get(User_.registrationStatus), filter.getStatus())); } if (!StringUtils.isEmpty(filter.getName())) { Predicate firstName = cb.like(cb.lower(from.get(User_.lastName)), LIKE_WILDCARD + filter.getName().toLowerCase() + LIKE_WILDCARD); Predicate lastName = cb.like(from.get(User_.firstName), LIKE_WILDCARD + filter.getName() + LIKE_WILDCARD); Predicate userName = cb.like(from.get(User_.userName), LIKE_WILDCARD + filter.getName() + LIKE_WILDCARD); Expression<String> fullName = cb.concat(cb.concat(from.get(User_.firstName), " "), from.get(User_.lastName)); Expression<String> un = cb.concat(" (", cb.concat(from.get(User_.userName), ")")); Predicate fn = cb.like(fullName, LIKE_WILDCARD + filter.getName() + LIKE_WILDCARD); Expression<String> fnu = cb.concat(fullName, un); Predicate ff1 = cb.like(fnu, LIKE_WILDCARD + filter.getName() + LIKE_WILDCARD); predicates.add(cb.or(firstName, lastName, userName, fn, ff1)); } return predicates; }
From source file:se.inera.intyg.intygstjanst.persistence.model.dao.impl.CertificateDaoImpl.java
@Override public List<Certificate> findCertificate(Personnummer civicRegistrationNumber, List<String> types, LocalDate fromDate, LocalDate toDate, List<String> careUnits) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Certificate> query = criteriaBuilder.createQuery(Certificate.class); Root<Certificate> root = query.from(Certificate.class); root.fetch("states", JoinType.LEFT); if (civicRegistrationNumber == null) { return Collections.emptyList(); }/*from ww w . j a v a 2 s.c o m*/ List<Predicate> predicates = new ArrayList<>(); // meta data has to match civic registration number predicates.add(criteriaBuilder.equal(root.get("civicRegistrationNumber"), DaoUtil.formatPnrForPersistence(civicRegistrationNumber))); // filter by certificate types if (types != null && !types.isEmpty()) { predicates.add(criteriaBuilder.lower(root.<String>get("type")).in(toLowerCase(types))); } // filter by care unit if (careUnits != null && !careUnits.isEmpty()) { predicates.add(root.<String>get("careUnitId").in(careUnits)); } query.where(predicates.toArray(new Predicate[predicates.size()])); // order by signed date query.orderBy(criteriaBuilder.asc(root.get("signedDate"))); List<Certificate> tmpResult = entityManager.createQuery(query).getResultList(); List<Certificate> result = filterDuplicates(tmpResult); // expect a small number, so lets filter in memory return new DateFilter(result).filter(fromDate, toDate); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * /*from w w w. j a va 2 s . c om*/ * @param metric * @param date * @return * @throws uQasarException */ public int countMeasurementsByMetricAndDate(String metric, Date date) throws uQasarException { logger.info("Count measurements for metric: " + metric + "and date: " + date); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.cubesMetric), metric); Predicate condition2 = cb.equal(root.get(CubesMetricMeasurement_.timeStamp), date); Predicate condition3 = cb.and(condition, condition2); query.where(condition3); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); return em.createQuery(query).getResultList().size(); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * // w w w . j a va2 s. co m * @param metric * @return * @throws uQasarException */ private List<CubesMetricMeasurement> getMeasurementsByMetricAndDate(String metric, Date date) throws uQasarException { logger.info("Get measurements for metric: " + metric); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.cubesMetric), metric); Predicate condition2 = cb.equal(root.get(CubesMetricMeasurement_.timeStamp), date); Predicate condition3 = cb.and(condition, condition2); query.where(condition3); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); return em.createQuery(query).getResultList(); }
From source file:com.orange.clara.tool.controllers.AbstractDefaultController.java
protected List<WatchedResource> getFilteredWatchedResources(User user, boolean isAdmin, String isPublic, String tags, String types, Date afterDate) { Specification<WatchedResource> specification = new Specification<WatchedResource>() { @Override/* ww w . ja va 2s .c o m*/ public Predicate toPredicate(Root<WatchedResource> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<>(); if (tags != null) { ListJoin<WatchedResource, Tag> tagJoin = root.joinList("tags"); predicates.add(cb.isTrue(tagJoin.get("name").in(Tag.namesFromStringList(tags)))); } if (types != null) { predicates.add(cb.isTrue(root.get("type").in(ResourceType.fromStringList(types)))); } if (isPublic != null) { predicates.add(cb.isTrue(root.get("isPublic"))); } if (afterDate != null) { predicates.add(cb.greaterThan(root.get("updatedResourceAt"), afterDate)); } if (!isAdmin) { ListJoin<WatchedResource, User> usersJoin = root.joinList("users"); predicates.add(cb.equal(usersJoin.get("uuid"), user.getUuid())); } Predicate finalPredicate = cb.and(predicates.toArray(new Predicate[] {})); if (isPublic != null) { finalPredicate = cb.or(finalPredicate, cb.isTrue(root.get("isPublic"))); } return finalPredicate; } }; return this.watchedResourceRepo.findAll(specification); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * @param project/*from w w w . ja v a2 s . c o m*/ * @param metric * @return */ public CubesMetricMeasurement getLatestMeasurementByProjectAndMetric(String project, String metric) { logger.info("Obtaining measurements for the project: " + project + " and metric: " + metric); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.cubeName), project); Predicate condition2 = cb.equal(root.get(CubesMetricMeasurement_.cubesMetric), metric); Predicate condition3 = cb.and(condition, condition2); query.where(condition3); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); List<CubesMetricMeasurement> measurements = em.createQuery(query).getResultList(); CubesMetricMeasurement measurement = null; if (measurements != null && measurements.size() > 0 && measurements.get(0) != null) { measurement = measurements.get(0); // Get the most "fresh" result } return measurement; }