Example usage for javax.persistence.criteria CriteriaBuilder asc

List of usage examples for javax.persistence.criteria CriteriaBuilder asc

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder asc.

Prototype

Order asc(Expression<?> x);

Source Link

Document

Create an ordering by the ascending value of the expression.

Usage

From source file:org.ow2.proactive.scheduling.api.graphql.fetchers.DatabaseConnectionFetcher.java

protected int applySlicing(CriteriaQuery<E> criteriaQuery, CriteriaBuilder criteriaBuilder,
        Path<? extends Number> taskIdPath, Integer first, Integer last) {
    // apply slicing
    int maxResults = -1;

    // first is set
    if (first != null) {
        if (first < 0) {
            throw new IllegalArgumentException("Argument 'first' must be equal or greater than 0");
        }/*from  w  w  w  .j  a  va  2 s .  c  o m*/

        criteriaQuery.orderBy(criteriaBuilder.asc(taskIdPath));
        maxResults = first;
    }

    // last is set
    if (last != null) {
        if (last < 0) {
            throw new IllegalArgumentException("Argument 'last' must be equal or greater than 0");
        }

        criteriaQuery.orderBy(criteriaBuilder.desc(taskIdPath));
        maxResults = last;
    }

    if (first == null && last == null) {
        criteriaQuery.orderBy(criteriaBuilder.asc(taskIdPath));
    }
    return maxResults;
}

From source file:eu.uqasar.service.user.UserService.java

public List<User> getAllByAscendingNameFiltered(UserFilterStructure filter, int first, int count) {
    logger.infof("loading all Users ordered by ascending name matching the given filter %s...", filter);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> criteria = cb.createQuery(User.class);
    Root<User> root = criteria.from(User.class);
    List<Predicate> predicates = getFilterPredicates(filter, cb, root);
    if (!predicates.isEmpty()) {
        criteria.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    }//from  w w w .j a  v  a  2s . c  o m
    criteria.orderBy(cb.asc(root.get(User_.lastName)), cb.asc(root.get(User_.firstName)));
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();

}

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 ww  .j  a  v  a  2 s . c  o  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:eu.uqasar.service.dataadapter.JiraDataService.java

/**
 * /* w w  w  .j a  v  a  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.captor.controller.RequirementAction.java

/**
 * load requirements/*from  www . jav a2  s  . co  m*/
 */
private void loadList() throws UCMException {

    Set<String> versions = this.projectService.findActiveProductReleaseVersions(this.authUser, this.project);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Requirement> c = cb.createQuery(Requirement.class);
    Root<Requirement> obj = c.from(Requirement.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project),
            obj.get("productRelease").get("version").in(versions)).orderBy(cb.asc(obj.get("id")));
    this.requirements = em.createQuery(c).getResultList();

}

From source file:com.sfs.ucm.controller.SpecificationAction.java

/**
 * Load resources//  www. j a  v  a 2  s. co  m
 * 
 * @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:com.sfs.ucm.controller.SpecificationAction.java

/**
 * load specifications/*w  ww. ja  v a  2  s  . c  o  m*/
 */
private void loadList() throws UCMException {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Specification> c = cb.createQuery(Specification.class);
    Root<Specification> obj = c.from(Specification.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id")));
    this.specifications = em.createQuery(c).getResultList();

}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * /*  w  ww . j  a va  2  s  . c  o  m*/
 * @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:net.groupbuy.dao.impl.BaseDaoImpl.java

protected List<T> findList(CriteriaQuery<T> criteriaQuery, Integer first, Integer count, List<Filter> filters,
        List<Order> orders) {
    Assert.notNull(criteriaQuery);//from  w  w  w.j av  a 2s  .c  o  m
    Assert.notNull(criteriaQuery.getSelection());
    Assert.notEmpty(criteriaQuery.getRoots());

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    Root<T> root = getRoot(criteriaQuery);
    addRestrictions(criteriaQuery, filters);
    addOrders(criteriaQuery, orders);
    if (criteriaQuery.getOrderList().isEmpty()) {
        if (OrderEntity.class.isAssignableFrom(entityClass)) {
            criteriaQuery.orderBy(criteriaBuilder.asc(root.get(OrderEntity.ORDER_PROPERTY_NAME)));
        } else {
            criteriaQuery.orderBy(criteriaBuilder.desc(root.get(OrderEntity.CREATE_DATE_PROPERTY_NAME)));
        }
    }
    TypedQuery<T> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT);
    if (first != null) {
        query.setFirstResult(first);
    }
    if (count != null) {
        query.setMaxResults(count);
    }
    return query.getResultList();
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of serviceIds available.
 *
 * @param modelVersion//from   w  ww . j  a va 2  s .  co  m
 *            the model version.
 * @return the list of serviceIds available.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<String> getRevisions() {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<String> q = cb.createQuery(String.class);
    final Root<EnterpriseType> f = q.from(EnterpriseType.class);
    q.select(f.<String>get(EnterpriseType_.modelVersion));
    q.orderBy(cb.asc(f.<String>get(EnterpriseType_.modelVersion)));
    final TypedQuery<String> typedQuery = this.em.createQuery(q);
    final List<String> value = typedQuery.getResultList();
    return value;
}