List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:br.com.webbudget.domain.model.repository.entries.CardRepository.java
License:Open Source License
/** * /*www. j a v a 2 s .c o m*/ * @param isBlocked * @param pageRequest * @return */ @Override public Page<Card> listByStatus(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.entries.ContactRepository.java
License:Open Source License
/** * * @param filter/*from w w w.jav a 2 s .c o m*/ * @param blocked * @param pageRequest * @return */ @Override public Page<Contact> listLazilyByFilter(String filter, Boolean blocked, PageRequest pageRequest) { final Criteria criteria = this.createCriteria(); if (filter != null) { criteria.add(Restrictions.or(Restrictions.ilike("name", "%" + filter + "%"), Restrictions.ilike("email", "%" + filter + "%"), Restrictions.eq("document", filter), Restrictions.ilike("city", "%" + filter + "%"))); } if (blocked != null) { criteria.add(Restrictions.eq("blocked", blocked)); } // 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.entries.CostCenterRepository.java
License:Open Source License
/** * /*from ww w. ja va2s.co m*/ * @param isBlocked * @param pageRequest * @return */ @Override public Page<CostCenter> 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.entries.MovementClassRepository.java
License:Open Source License
/** * /* www . jav a2 s . co m*/ * @param isBlocked * @param pageRequest * @return */ @Override public Page<MovementClass> 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.entries.VehicleRepository.java
License:Open Source License
/** * * @param vehicle/*from ww w . ja v a 2 s .com*/ * @return */ @Override public int findLastOdometer(Vehicle vehicle) { final Criteria criteria = this.createCriteria(); criteria.add(Restrictions.eq("id", vehicle.getId())); criteria.setProjection(Projections.property("odometer")); return (int) criteria.uniqueResult(); }
From source file:br.com.webbudget.domain.model.repository.entries.VehicleRepository.java
License:Open Source License
/** * * @param isBlocked/*from ww w . jav a 2 s . c o m*/ * @param pageRequest * @return */ @Override public Page<Vehicle> 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.entries.WalletBalanceRepository.java
License:Open Source License
/** * * @param wallet//from w w w . j av a 2s .c o m * @return */ @Override public WalletBalance findLastWalletBalance(Wallet wallet) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("wallet", "wl"); criteria.add(Restrictions.eq("wl.id", wallet.getId())); criteria.setProjection(Projections.max("id")); final Object id = criteria.uniqueResult(); if (id != null) { return this.findById((Long) id, false); } else { return null; } }
From source file:br.com.webbudget.domain.model.repository.entries.WalletRepository.java
License:Open Source License
/** * //w w w . j ava 2 s . com * @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.ApportionmentRepository.java
License:Open Source License
/** * * @param movementClass/*from ww w . ja v a 2s. c om*/ * @return */ @Override public BigDecimal totalMovementsPerClass(MovementClass movementClass) { final Criteria criteria = this.createCriteria(); criteria.setProjection(Projections.sum("value")); criteria.add(Restrictions.eq("movementClass", movementClass)); return (BigDecimal) criteria.uniqueResult(); }
From source file:br.com.webbudget.domain.model.repository.financial.ApportionmentRepository.java
License:Open Source License
/** * /* ww w . j a va 2 s . co m*/ * @param period * @param movementClass * @return */ @Override public BigDecimal totalMovementsPerClassAndPeriod(FinancialPeriod period, MovementClass movementClass) { final Criteria criteria = this.createCriteria(); criteria.createAlias("movement", "mv"); criteria.createAlias("mv.financialPeriod", "fp"); criteria.add(Restrictions.eq("fp.id", period.getId())); criteria.add(Restrictions.in("mv.movementStateType", new Object[] { MovementStateType.PAID, MovementStateType.CALCULATED })); criteria.add(Restrictions.eq("movementClass", movementClass)); criteria.setProjection(Projections.sum("value")); return (BigDecimal) criteria.uniqueResult(); }