List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @param dueDate// www. j a v a 2 s . c o m * @param showOverdue * @return */ @Override public List<Movement> listByDueDate(LocalDate dueDate, boolean showOverdue) { final Criteria criteria = this.createCriteria(); if (showOverdue) { criteria.add(Restrictions.le("dueDate", dueDate)); criteria.add(Restrictions.eq("movementStateType", MovementStateType.OPEN)); } else { criteria.add(Restrictions.eq("dueDate", dueDate)); } criteria.addOrder(Order.asc("dueDate")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.MovementRepository.java
License:Open Source License
/** * * @param financialPeriod/*w w w . j a v a 2 s . com*/ * @param card * @return */ @Override public List<Movement> listPaidWithoutInvoiceByPeriodAndCard(FinancialPeriod financialPeriod, Card card) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.add(Restrictions.isNull("cardInvoice")); criteria.add(Restrictions.eq("cardInvoicePaid", Boolean.FALSE)); criteria.add(Restrictions.eq("movementStateType", MovementStateType.PAID)); criteria.createAlias("financialPeriod", "fp"); criteria.add(Restrictions.eq("fp.id", financialPeriod.getId())); criteria.createAlias("payment", "py").createAlias("py.card", "cc"); criteria.add(Restrictions.eq("cc.id", card.getId())); criteria.addOrder(Order.asc("py.paymentDate")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.logbook.RefuelingRepository.java
License:Open Source License
/** * * @param filter/*from w w w .jav a2s . c o m*/ * @param pageRequest * @return */ @Override public Page<Refueling> listLazily(String filter, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (StringUtils.isNotBlank(filter)) { // TODO colocar os filtros aqui } // 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.miscellany.FinancialPeriodRepository.java
License:Open Source License
/** * * @return/* w w w . ja v a 2 s. c o m*/ */ @Override public List<FinancialPeriod> listOpen() { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.add(Restrictions.eq("closed", false)); criteria.add(Restrictions.isNull("closing")); criteria.addOrder(Order.asc("end")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.miscellany.FinancialPeriodRepository.java
License:Open Source License
/** * /*from w ww . ja v a 2s . c o m*/ * @param isClosed * @param pageRequest * @return */ @Override public Page<FinancialPeriod> listByStatusLazily(Boolean isClosed, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (isClosed != null) { criteria.add(Restrictions.eq("closed", isClosed)); } // 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.miscellany.FinancialPeriodRepository.java
License:Open Source License
/** * //w ww. java 2 s. c o m * @return */ @Override public List<FinancialPeriod> listLastSixClosed() { final Criteria criteria = this.createCriteria(); criteria.add(Restrictions.eq("closed", true)); criteria.addOrder(Order.desc("id")); criteria.setMaxResults(6); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.tools.MessageRepository.java
License:Open Source License
/** * // w w w. java2 s. c o m * @param sender * @param filter * @param pageRequest * @return */ @Override public Page<Message> listSent(User sender, String filter, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (filter != null) { criteria.add(Restrictions.or(Restrictions.ilike("title", "%" + filter + "%"), Restrictions.ilike("content", "%" + filter + "%"))); } criteria.add(Restrictions.eq("deleted", false)); criteria.add(Restrictions.eq("sender", sender)); // 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.tools.UserMessageRepository.java
License:Open Source License
/** * /*w ww . ja va 2s .c o m*/ * @param recipient * @return */ @Override public List<UserMessage> listUnread(User recipient) { final Criteria criteria = this.createCriteria(); criteria.add(Restrictions.eq("read", false)); criteria.add(Restrictions.eq("recipient", recipient)); criteria.addOrder(Order.desc("inclusion")); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.tools.UserMessageRepository.java
License:Open Source License
/** * //from ww w. j a v a 2 s. co m * @param recipient * @param filter * @param pageRequest * @return */ @Override public Page<UserMessage> listReceived(User recipient, String filter, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (filter != null) { criteria.createAlias("message", "ms"); criteria.add(Restrictions.or(Restrictions.ilike("ms.title", "%" + filter + "%"), Restrictions.ilike("ms.content", "%" + filter + "%"))); } criteria.add(Restrictions.eq("deleted", false)); criteria.add(Restrictions.eq("recipient", recipient)); // 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.repository.movement.MovementClassRepository.java
License:Open Source License
/** * //from www.j av a 2 s . c o m * @param isBlocked * @return */ @Override public List<MovementClass> listByStatus(Boolean isBlocked) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); if (isBlocked != null) { criteria.add(Restrictions.eq("blocked", isBlocked)); } criteria.addOrder(Order.asc("name")); return criteria.list(); }