List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
From source file:br.com.webbudget.domain.model.repository.entries.WalletBalanceRepository.java
License:Open Source License
/** * * @param wallet/*w w w .j a v 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.WalletBalanceRepository.java
License:Open Source License
/** * * @param source/*from www . j ava 2 s. 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.financial.ApportionmentRepository.java
License:Open Source License
/** * * @param movement//from ww w . j a va 2 s . c om * @return */ @Override public List<Apportionment> listByMovement(Movement movement) { final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass()); criteria.createAlias("movement", "mv"); criteria.add(Restrictions.eq("mv.id", movement.getId())); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.ApportionmentRepository.java
License:Open Source License
/** * * @param fixedMovement/*from w w w . j a v a2 s.c o m*/ * @return */ @Override public List<Apportionment> listByFixedMovement(FixedMovement fixedMovement) { final Criteria criteria = this.createCriteria(); criteria.createAlias("fixedMovement", "fm"); criteria.add(Restrictions.eq("fm.id", fixedMovement.getId())); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.ApportionmentRepository.java
License:Open Source License
/** * //from ww w . j av a 2 s . com * @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.LaunchRepository.java
License:Open Source License
/** * /* w w w . ja v a2s. 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(); }
From source file:br.com.webbudget.domain.model.repository.financial.LaunchRepository.java
License:Open Source License
/** * /* ww w . j a v a 2s .c o m*/ * @param fixedMovement * @return */ @Override public Long countByFixedMovement(FixedMovement fixedMovement) { 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")); return (Long) criteria.uniqueResult(); }
From source file:br.com.webbudget.domain.model.repository.financial.LaunchRepository.java
License:Open Source License
/** * /*from w w w. j av a 2 s . c o m*/ * @param fixedMovement * @return */ @Override public List<Launch> listByFixedMovement(FixedMovement fixedMovement) { final Criteria criteria = this.createCriteria(); criteria.createAlias("fixedMovement", "fm"); criteria.add(Restrictions.eq("fm.id", fixedMovement.getId())); return criteria.list(); }
From source file:br.com.webbudget.domain.model.repository.financial.LaunchRepository.java
License:Open Source License
/** * // ww w . j ava 2 s . c om * @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 ava2 s .c o m*/ */ @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(); }