Example usage for org.hibernate.query.criteria.internal OrderImpl OrderImpl

List of usage examples for org.hibernate.query.criteria.internal OrderImpl OrderImpl

Introduction

In this page you can find the example usage for org.hibernate.query.criteria.internal OrderImpl OrderImpl.

Prototype

public OrderImpl(Expression<?> expression, boolean ascending) 

Source Link

Usage

From source file:org.jpos.ee.DBManager.java

License:Open Source License

public List<T> getAll(int offset, int limit, Map<String, Boolean> orders) {
    CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder();
    CriteriaQuery<T> query = criteriaBuilder.createQuery(clazz);
    Root<T> root = query.from(clazz);
    List<Order> orderList = new ArrayList<>();
    //ORDERS//from   w ww  . j ava 2 s .c o m
    if (orders != null) {
        for (Map.Entry<String, Boolean> entry : orders.entrySet()) {
            OrderImpl order = new OrderImpl(root.get(entry.getKey()), entry.getValue());
            orderList.add(order);
        }
    }
    Predicate[] predicates = buildFilters(root);
    if (predicates != null)
        query.where(predicates);
    query.select(root);
    query.orderBy(orderList);
    Query queryImp = db.session().createQuery(query);
    if (limit != -1) {
        queryImp.setMaxResults(limit);
    }
    List<T> list = queryImp.setFirstResult(offset).getResultList();
    return list;
}

From source file:org.jpos.qi.minigl.AccountManager.java

License:Open Source License

public List<Account> getAllChildren(int offset, int limit, Map<String, Boolean> orders, Account parent)
        throws Exception {
    CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder();
    CriteriaQuery<Account> query = criteriaBuilder.createQuery(Account.class);
    Root<Account> root = query.from(Account.class);
    List<Order> orderList = new ArrayList<>();
    //ORDERS/*from w w  w .j av a2  s  .  c  o  m*/
    for (Map.Entry<String, Boolean> entry : orders.entrySet()) {
        OrderImpl order = new OrderImpl(root.get(entry.getKey()), entry.getValue());
        orderList.add(order);
    }
    //Is child of parent
    Predicate p;
    if (parent != null) {
        p = criteriaBuilder.equal(root.get("parent"), parent.getId());
    } else {
        p = criteriaBuilder.isNull(root.get("parent"));
    }
    query.select(root);
    query.orderBy(orderList);
    query.where(p);
    List<Account> list = db.session().createQuery(query).setMaxResults(limit).setFirstResult(offset)
            .getResultList();
    return list;
}

From source file:org.jpos.qi.minigl.AccountManager.java

License:Open Source License

public List<CompositeAccount> getCompositeAccounts(int offset, int limit, Map<String, Boolean> orders)
        throws Exception {
    CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder();
    CriteriaQuery<CompositeAccount> query = criteriaBuilder.createQuery(CompositeAccount.class);
    Root<CompositeAccount> root = query.from(CompositeAccount.class);
    List<Order> orderList = new ArrayList<>();
    //ORDERS/*from   www  . j  ava2  s . c o m*/
    for (Map.Entry<String, Boolean> entry : orders.entrySet()) {
        OrderImpl order = new OrderImpl(root.get(entry.getKey()), entry.getValue());
        orderList.add(order);
    }
    query.select(root);
    query.orderBy(orderList);
    List<CompositeAccount> list = db.session().createQuery(query).setMaxResults(limit).setFirstResult(offset)
            .getResultList();
    return list;
}