List of usage examples for org.hibernate Criteria uniqueResult
public Object uniqueResult() throws HibernateException;
From source file:br.com.webbudget.domain.model.repository.entries.MovementClassRepository.java
License:Open Source License
/** * * @param name//from w w w . ja v a 2 s. co m * @param type * @param costCenter * @return */ @Override public MovementClass findByNameAndTypeAndCostCenter(String name, MovementClassType type, CostCenter costCenter) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("costCenter", "cc"); criteria.add(Restrictions.eq("cc.id", costCenter.getId())); criteria.add(Restrictions.eq("name", name)); criteria.add(Restrictions.eq("movementClassType", type)); return (MovementClass) criteria.uniqueResult(); }
From source file:br.com.webbudget.domain.model.repository.entries.VehicleRepository.java
License:Open Source License
/** * * @param vehicle//from ww w . j a va2 s . co m * @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 w w w. ja va 2 s . c om*/ * @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 ww w . jav a 2 s .c om * @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 ww . j a v a2 s.c o 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.entries.WalletRepository.java
License:Open Source License
/** * * @param name/* ww w.j av a2s .co m*/ * @param bank * @param walletType * @return */ @Override public Wallet findByNameAndBankAndType(String name, String bank, WalletType walletType) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.add(Restrictions.eq("name", name)); criteria.add(Restrictions.eq("walletType", walletType)); if (walletType == WalletType.BANK_ACCOUNT) { criteria.add(Restrictions.eq("bank", bank)); } return (Wallet) criteria.uniqueResult(); }
From source file:br.com.webbudget.domain.model.repository.financial.ApportionmentRepository.java
License:Open Source License
/** * * @param movementClass/*from w ww . jav 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
/** * /*www. jav a2 s . c om*/ * @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(); }
From source file:br.com.webbudget.domain.model.repository.financial.FixedMovementRepository.java
License:Open Source License
/** * * @param filter//ww w.ja v a2 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
/** * // w w w. j a va 2 s . c o m * @param movement * @return */ @Override public Launch findByMovement(Movement movement) { final Criteria criteria = this.createCriteria(); criteria.createAlias("movement", "m"); criteria.add(Restrictions.eq("m.id", movement.getId())); return (Launch) criteria.uniqueResult(); }