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:com.sfs.captor.controller.ProductReleaseAction.java

/**
 * load product releases/*from  w  ww  . j  ava  2s.  c  o m*/
 */
private void loadList() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ProductRelease> c = cb.createQuery(ProductRelease.class);
    Root<ProductRelease> obj = c.from(ProductRelease.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id")));
    this.productReleases = em.createQuery(c).getResultList();
}

From source file:eu.uqasar.service.ProductService.java

public List<Product> getAllByAscendingNameFiltered(
        eu.uqasar.web.pages.products.panels.ProductFilterStructure filter, int first, int count) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Product> criteria = cb.createQuery(Product.class);
    Root<Product> from = criteria.from(Product.class);
    List<Predicate> predicates = getFilterPredicates(filter, cb, from);
    if (!predicates.isEmpty()) {
        criteria.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    }//  ww  w  .j  a  v  a 2  s .c om

    criteria.orderBy(cb.asc(from.get(Product_.releaseDate)));
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();

}

From source file:csns.model.core.dao.jpa.UserDaoImpl.java

@Override
public List<User> getUsers(Long ids[]) {
    if (ids == null || ids.length < 1)
        return new ArrayList<User>();

    CriteriaBuilder cbuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<User> cquery = cbuilder.createQuery(User.class);
    Root<User> user = cquery.from(User.class);

    Predicate criteria = cbuilder.equal(user.get("id"), ids[0]);
    for (int i = 1; i < ids.length; ++i)
        criteria = cbuilder.or(criteria, cbuilder.equal(user.get("id"), ids[i]));
    cquery.where(criteria);//from   ww w.  jav  a 2 s .c  o m

    cquery.orderBy(cbuilder.asc(user.get("lastName")), cbuilder.asc(user.get("firstName")));

    return entityManager.createQuery(cquery).getResultList();
}

From source file:com.aimdek.ccm.dao.impl.UserRepositoryImpl.java

/**
 * Adds the sorting.//from w ww .  ja  v a  2s. co m
 *
 * @param sortField the sort field
 * @param sortOrder the sort order
 * @param query the query
 * @param builder the builder
 * @param root the root
 */
private void addSorting(String sortField, String sortOrder, CriteriaQuery<User> query, CriteriaBuilder builder,
        Root<User> root) {
    boolean isSet = FALSE;
    if (CommonUtil.isNotNull(sortField) && !sortField.contains(FIELDCONSTANT_CARDNUMBER)
            && !sortField.contains(FIELDCONSTANT_CREDITLIMIT) && !sortField.contains(FIELDCONSTANT_BALANCE)) {
        isSet = TRUE;
        if (sortOrder.startsWith(SORT_ORDER_ASCENDING)) {
            query.orderBy(builder.asc(root.get(sortField)));
        } else {
            query.orderBy(builder.desc(root.get(sortField)));
        }
    }
    if (!isSet) {
        query.orderBy(builder.desc(root.get(FIELD_CONSTANT_CREATED_AT)));
    }
}

From source file:com.sfs.captor.controller.ProjectPackageAction.java

/**
 * Load project packages/* w  ww .j ava 2  s.  com*/
 */
private void loadList() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ProjectPackage> c = cb.createQuery(ProjectPackage.class);
    Root<ProjectPackage> obj = c.from(ProjectPackage.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id")));
    this.projectPackages = em.createQuery(c).getResultList();
}

From source file:com.samples.platform.core.SystemUserInitDao.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 void enterSystemUser(final String contextName, final String userName, final String password,
        final String... roleNames) {
    AuthenticationType ac = this.of.createAuthenticationType();
    ac.setContext(contextName);
    ac.setEnabled(true);
    GrantedAuthorityType r;
    for (String roleName : roleNames) {
        r = this.of.createGrantedAuthorityType();
        r.setRoleName(roleName);
        ac.getGrantedAuthority().add(r);
    }
    ac.setPassword(password);
    ac.setUserName(userName);
    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), contextName));
    ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.userName), userName));
    q.where(ands);
    q.orderBy(cb.asc(c.<String>get(AuthenticationType_.userName)));
    TypedQuery<AuthenticationType> typedQuery = this.em.createQuery(q);
    try {
        AuthenticationType stored = typedQuery.getSingleResult();
        if (stored != null) {
            this.em.persist(ac);
        }
    } catch (NoResultException e) {
        this.em.persist(ac);
    }
}

From source file:cl.troncador.delfin.query.constraint.PrepareOrderAdapter.java

public Order[] getOrderArray(Root<T> root, CriteriaBuilder criteriaBuilder) {
    List<Order> orderList = new ArrayList<Order>();

    for (Pair<SingularAttribute<T, ?>, Direction> directionedColumn : directionedColumnList) {
        Direction direction = directionedColumn.getRight();
        SingularAttribute<T, ?> column = directionedColumn.getLeft();
        Path<?> path = root.get(column);
        Order order = null;/*from  w  ww  .  j  av  a 2 s  .  c  o m*/
        switch (direction) {
        case ASC:
            order = criteriaBuilder.asc(path);
            break;
        case DES:
            order = criteriaBuilder.desc(path);
            break;
        }
        orderList.add(order);
    }
    return orderList.toArray(new Order[orderList.size()]);
}

From source file:eu.uqasar.service.ProcessService.java

public List<Process> getAllByAscendingEndDateNameFiltered(ProcessesFilterStructure filter, int first,
        int count) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Process> criteria = cb.createQuery(Process.class);
    Root<Process> root = criteria.from(Process.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  .  ja v a 2 s .  co m

    criteria.orderBy(cb.asc(root.get(Process_.endDate)));
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();

}

From source file:eu.uqasar.service.ProcessService.java

public List<Process> getAllAscendingStartDateNameFiltered(ProcessesFilterStructure filter, int first,
        int count) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Process> criteria = cb.createQuery(Process.class);
    Root<Process> root = criteria.from(Process.class);
    List<Predicate> predicates = getFilterPredicates(filter, cb, root);
    if (!predicates.isEmpty()) {
        criteria.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    }/*from   w  ww . j av a 2 s  . c o m*/

    criteria.orderBy(cb.asc(root.get(Process_.startDate)));
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();

}

From source file:utils.jpa.EntityResource.java

private List<T> getAllPriv(@BeanParam TableSearchQuery tb, List<String> fieldsSearchBy) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<T> cq = cb.createQuery(entityClass);
    Root<T> root = cq.from(entityClass);

    cq.select(root);//ww w . j av a2s  .c  om

    //setting order
    if (tb.getOrderType().equals(OrderType.DESC)) {
        cq.orderBy(cb.desc(root.get(tb.getOrder())));
    } else {
        cq.orderBy(cb.asc(root.get(tb.getOrder())));
    }

    Query query = tb.createQuery(em, cb, cq, root);
    if (query == null) {
        query = createCommonQuery(cb, cq, root, tb, fieldsSearchBy);
    }

    if (tb.getOffset() > 0) {
        query.setFirstResult(tb.getOffset());
    }
    if (tb.getLimit() > 0) {
        query.setMaxResults(tb.getLimit());
    }

    return query.getResultList();
}