List of usage examples for javax.persistence.criteria CriteriaQuery orderBy
CriteriaQuery<T> orderBy(List<Order> o);
From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java
@Override @TransactionAttribute// ww w . ja va2 s . c o m public List<T> findByExample(final T example, final T example2, final OrderBy<T> sortParam, final long first, final long count, final String... fg) { if (fg != null) { entityManager.pushFetchPlan(); entityManager.getFetchPlan().addFetchGroups(fg); } OpenJPACriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<T> q = cb.createQuery(persistentClass); Root<T> from = q.from(persistentClass); q.where(newQbePredicates(cb, from, example, example2)); if (sortParam != null) { List<Order> orderList = sortParam.orders(cb, from); if (orderList != null && !orderList.isEmpty()) { q.orderBy(orderList); } } TypedQuery<T> query = entityManager.createQuery(q); OrmUtils.firstCount(query, first, count); List<T> resultList = query.getResultList(); if (fg != null) { entityManager.popFetchPlan(); } return resultList; }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * //from w w w.j a v a 2 s. c o m * @param first * @param count * @return */ public List<CubesMetricMeasurement> getAllByAscendingName(int first, int count) { logger.infof("loading all CubesMetricMeasurement ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> criteria = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = criteria.from(CubesMetricMeasurement.class); criteria.orderBy(cb.asc(root.get(CubesMetricMeasurement_.self))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepository.java
/** * Creates a {@link TypedQuery} for the given {@link Specification} and {@link Sort}. * // ww w. ja v a2 s .c om * @param spec can be {@literal null}. * @param sort can be {@literal null}. * @return */ protected TypedQuery<M> getQuery(Specification<M> spec, Sort sort) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<M> query = builder.createQuery(getDomainClass()); Root<M> root = applySpecificationToCriteria(spec, query); query.select(root); if (sort != null) { query.orderBy(toOrders(sort, root, builder)); } return applyRepositoryMethodMetadata(em.createQuery(query)); }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
/** * Get the latest date of measurement snapshots * @return/*from www .ja v a 2 s. co m*/ */ private Date getLatestDate() { logger.info("Get the latest date from CUBES measurements..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class); Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class); query.select(root); query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp))); return em.createQuery(query).setMaxResults(1).getSingleResult().getTimeStamp(); }
From source file:com.qpark.eip.core.spring.auth.dao.AuthorityDao.java
/** * Get the {@link AuthenticationType}s out of the database. * * @param enabled//from w w w . ja va 2 s . co m * if not <code>null</code> and <code>true</code> only the * enabled {@link AuthenticationType}s are replied. * @return the list of {@link AuthenticationType}s. */ @Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public List<AuthenticationType> getAuthenticationTypes(final Boolean enabled) { CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<AuthenticationType> q = cb.createQuery(AuthenticationType.class); Root<AuthenticationType> c = q.from(AuthenticationType.class); Predicate ands = cb.conjunction(); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.context), this.getContextName())); if (enabled != null) { ands.getExpressions().add(cb.equal(c.<Boolean>get(AuthenticationType_.enabled), enabled)); } q.where(ands); q.orderBy(cb.asc(c.<String>get(AuthenticationType_.userName))); TypedQuery<AuthenticationType> typedQuery = this.em.createQuery(q); List<AuthenticationType> list = typedQuery.getResultList(); for (AuthenticationType auth : list) { for (GrantedAuthorityType gr : auth.getGrantedAuthority()) { gr.getRoleName(); } for (int i = 0; i < auth.getGrantedAuthority().size(); i++) { // eager loading... auth.getGrantedAuthority().get(i); } } return list; }
From source file:com.sishuok.es.common.repository.support.SimpleBaseRepository.java
/** * Creates a {@link javax.persistence.TypedQuery} for the given {@link org.springframework.data.jpa.domain.Specification} and {@link org.springframework.data.domain.Sort}. * * @param spec can be {@literal null}./* ww w .j a v a 2 s .c o m*/ * @param sort can be {@literal null}. * @return */ private TypedQuery<M> getQuery(Specification<M> spec, Sort sort) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<M> query = builder.createQuery(entityClass); Root<M> root = applySpecificationToCriteria(spec, query); query.select(root); applyJoins(root); if (sort != null) { query.orderBy(toOrders(sort, root, builder)); } TypedQuery<M> q = em.createQuery(query); repositoryHelper.applyEnableQueryCache(q); return applyLockMode(q); }
From source file:com.luna.common.repository.support.SimpleBaseRepository.java
/** * Creates a {@link javax.persistence.TypedQuery} for the given {@link org.springframework.data.jpa.domain.Specification} and {@link org.springframework.data.domain.Sort}. * * @param spec can be {@literal null}.//from w w w. j av a 2 s . com * @param sort can be {@literal null}. * @return */ protected TypedQuery<M> getQuery(Specification<M> spec, Sort sort) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<M> query = builder.createQuery(entityClass); Root<M> root = applySpecificationToCriteria(spec, query); query.select(root); applyJoins(root); if (sort != null) { query.orderBy(toOrders(sort, root, builder)); } TypedQuery<M> q = em.createQuery(query); repositoryHelper.applyEnableQueryCache(q); return applyLockMode(q); }
From source file:eu.uqasar.service.dataadapter.JiraDataService.java
/** * //from w w w . j a va 2 s . co m * @param first * @param count * @param adapter * @return */ public List<JiraMetricMeasurement> getAllByAdapter(int first, int count, AdapterSettings adapter) { logger.info("Get measurements for adapter: " + adapter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class); Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class); Predicate condition = cb.equal(root.get(JiraMetricMeasurement_.adapter), adapter); query.orderBy(cb.asc(root.get(JiraMetricMeasurement_.jiraKey))); query.where(condition); return em.createQuery(query).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:com.sfs.ucm.controller.SpecificationAction.java
/** * Load resources/*from w w w . j av a2 s. c om*/ * * @param project */ private void loadFeatures(final Project project) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Feature> c = cb.createQuery(Feature.class); Root<Feature> obj = c.from(Feature.class); c.select(obj); c.where(cb.equal(obj.get("project"), project)); c.orderBy(cb.asc(obj.get("id"))); this.features = em.createQuery(c).getResultList(); }
From source file:eu.uqasar.service.dataadapter.JiraDataService.java
/** * //from w w w. j av a 2 s .com * @param metric * @return * @throws uQasarException */ public List<JiraMetricMeasurement> getMeasurementsForMetric(String metric) throws uQasarException { logger.info("Get measurements for metric: " + metric); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class); Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class); Predicate condition = cb.equal(root.get(JiraMetricMeasurement_.jiraMetric), metric); query.where(condition); query.orderBy(cb.desc(root.get(JiraMetricMeasurement_.timeStamp))); return em.createQuery(query).getResultList(); }