List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.com.webbudget.domain.model.repository.entries.WalletBalanceRepository.java
License:Open Source License
/** * * @param walletBalanceType//ww w .j av a 2 s. co m * @return */ @Override public List<WalletBalance> listByType(WalletBalanceType walletBalanceType) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.add(Restrictions.eq("walletBalanceType", walletBalanceType)); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.entries.WalletBalanceRepository.java
License:Open Source License
/** * * @param source/*from ww w. j a v a 2s. c o m*/ * @param target * @param types * @return */ @Override public List<WalletBalance> listByWallet(Wallet source, Wallet target, WalletBalanceType... types) { final Criteria criteria = this.createCriteria(); if (target != null) { criteria.createAlias("targetWallet", "tgt"); criteria.add(Restrictions.eq("tgt.id", target.getId())); } if (source != null) { criteria.createAlias("sourceWallet", "src"); criteria.add(Restrictions.eq("src.id", source.getId())); } if (types != null) { for (WalletBalanceType type : types) { criteria.add(Restrictions.eq("walletBalanceType", type)); } } criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.entries.WalletRepository.java
License:Open Source License
/** * * @param isBlocked//w ww . j av a2 s . c o m * @return */ @Override public List<Wallet> listByStatus(Boolean isBlocked) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); if (isBlocked != null) { criteria.add(Restrictions.eq("blocked", isBlocked)); } criteria.addOrder(Order.asc("bank")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.entries.WalletRepository.java
License:Open Source License
/** * /*from w ww . ja v a2s . co m*/ * @param isBlocked * @param pageRequest * @return */ @Override public Page<Wallet> listLazilyByStatus(Boolean isBlocked, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (isBlocked != null) { criteria.add(Restrictions.eq("blocked", isBlocked)); } // projetamos para pegar o total de paginas possiveis criteria.setProjection(Projections.count("id")); final Long totalRows = (Long) criteria.uniqueResult(); // limpamos a projection para que a criteria seja reusada criteria.setProjection(null); criteria.setResultTransformer(Criteria.ROOT_ENTITY); // paginamos criteria.setFirstResult(pageRequest.getFirstResult()); criteria.setMaxResults(pageRequest.getPageSize()); if (pageRequest.getSortDirection() == PageRequest.SortDirection.ASC) { criteria.addOrder(Order.asc(pageRequest.getSortField())); } else if (pageRequest.getSortDirection() == PageRequest.SortDirection.DESC) { criteria.addOrder(Order.desc(pageRequest.getSortField())); } // montamos o resultado paginado return new Page<>(criteria.list(), totalRows); }
From source file:br.com.webbudget.domain.model.repository.financial.FixedMovementRepository.java
License:Open Source License
/** * * @param filter/*from w w w .j a v a 2 s. c o m*/ * @param pageRequest * @return */ @Override public Page<FixedMovement> listByFilter(String filter, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); final List<Criterion> criterions = new ArrayList<>(); // filtramos if (filter != null && !filter.isEmpty()) { criterions.add(Restrictions.ilike("description", "%" + filter + "%")); criterions.add(Restrictions.ilike("identification", "%" + filter + "%")); // se conseguir castar para bigdecimal trata como um filtro try { criterions.add(Restrictions.eq("value", new BigDecimal(filter))); } catch (NumberFormatException ex) { } } criteria.add(Restrictions.or(criterions.toArray(new Criterion[] {}))); // projetamos para pegar o total de paginas possiveis criteria.setProjection(Projections.count("id")); final Long totalRows = (Long) criteria.uniqueResult(); // limpamos a projection para que a criteria seja reusada criteria.setProjection(null); criteria.setResultTransformer(Criteria.ROOT_ENTITY); // paginamos criteria.setFirstResult(pageRequest.getFirstResult()); criteria.setMaxResults(pageRequest.getPageSize()); if (pageRequest.getSortDirection() == PageRequest.SortDirection.ASC) { criteria.addOrder(Order.asc(pageRequest.getSortField())); } else if (pageRequest.getSortDirection() == PageRequest.SortDirection.DESC) { criteria.addOrder(Order.desc(pageRequest.getSortField())); } // montamos o resultado paginado return new Page<>(criteria.list(), totalRows); }
From source file:br.com.webbudget.domain.model.repository.financial.LaunchRepository.java
License:Open Source License
/** * /*from ww w .java2s . co m*/ * @param fixedMovement * @param pageRequest * @return */ @Override public Page<Launch> listByFixedMovement(FixedMovement fixedMovement, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); criteria.createAlias("fixedMovement", "fm"); criteria.add(Restrictions.eq("fm.id", fixedMovement.getId())); // projetamos para pegar o total de paginas possiveis criteria.setProjection(Projections.count("id")); final Long totalRows = (Long) criteria.uniqueResult(); // limpamos a projection para que a criteria seja reusada criteria.setProjection(null); criteria.setResultTransformer(Criteria.ROOT_ENTITY); // paginamos criteria.setFirstResult(pageRequest.getFirstResult()); criteria.setMaxResults(pageRequest.getPageSize()); if (pageRequest.getSortDirection() == PageRequest.SortDirection.ASC) { criteria.addOrder(Order.asc(pageRequest.getSortField())); } else if (pageRequest.getSortDirection() == PageRequest.SortDirection.DESC) { criteria.addOrder(Order.desc(pageRequest.getSortField())); } // montamos o resultado paginado return new Page<>(criteria.list(), totalRows); }
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @return//from w w w.j a v a 2s. c om */ @Override public List<Movement> listByActiveFinancialPeriod() { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("financialPeriod", "fp"); criteria.add(Restrictions.eq("fp.closed", false)); criteria.add(Restrictions.isNull("fp.closing")); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @param contact/*from ww w .ja v a 2 s . c o m*/ * @return */ @Override public List<Movement> listByContact(Contact contact) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("contact", "ct"); criteria.add(Restrictions.eq("ct.id", contact.getId())); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @param cardInvoice/*from w w w .j av a 2 s . c om*/ * @return */ @Override public List<Movement> listByCardInvoice(CardInvoice cardInvoice) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("cardInvoice", "ci"); criteria.add(Restrictions.eq("ci.id", cardInvoice.getId())); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @param filter//from w w w. ja va 2s . c o m * @param pageRequest * @return */ @Override public Page<Movement> listByFilter(MovementFilter filter, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); final List<Criterion> criterions = new ArrayList<>(); criteria.createAlias("contact", "co", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("apportionments", "ap"); criteria.createAlias("ap.movementClass", "mc"); criteria.createAlias("ap.costCenter", "cc"); criteria.createAlias("financialPeriod", "fp"); // montramos os criterios de filtragem geral if (filter.hasCriteria()) { criterions.add(Restrictions.eq("code", filter.getCriteria())); criterions.add(Restrictions.ilike("description", "%" + filter.getCriteria() + "%")); criterions.add(Restrictions.ilike("mc.name", "%" + filter.getCriteria() + "%")); criterions.add(Restrictions.ilike("cc.name", "%" + filter.getCriteria() + "%")); criterions.add(Restrictions.ilike("co.name", "%" + filter.getCriteria() + "%")); // se conseguir castar para bigdecimal trata como um filtro try { criterions.add(Restrictions.eq("value", filter.criteriaToBigDecimal())); } catch (ParseException ex) { } } criteria.add(Restrictions.or(criterions.toArray(new Criterion[] {}))); criteria.add(Restrictions.and(filter.getCustomFilters())); // projetamos para pegar o total de paginas possiveis criteria.setProjection(Projections.count("id")); final Long totalRows = (Long) criteria.uniqueResult(); // limpamos a projection para que a criteria seja reusada criteria.setProjection(null); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // paginamos criteria.setFirstResult(pageRequest.getFirstResult()); criteria.setMaxResults(pageRequest.getPageSize()); // aplica o multisort dos campos if (pageRequest.isMultiSort()) { pageRequest.getMultiSortFields().stream().forEach(field -> { if (field.getDirection() == SortDirection.ASC) { criteria.addOrder(Order.asc(field.getSortField())); } else if (field.getDirection() == SortDirection.DESC) { criteria.addOrder(Order.desc(field.getSortField())); } }); } else if (pageRequest.getSortDirection() == SortDirection.ASC) { criteria.addOrder(Order.asc(pageRequest.getSortField())); } else if (pageRequest.getSortDirection() == SortDirection.DESC) { criteria.addOrder(Order.desc(pageRequest.getSortField())); } // montamos o resultado paginado return new Page<>(criteria.list(), totalRows); }