List of usage examples for org.hibernate.criterion Restrictions le
public static SimpleExpression le(String propertyName, Object value)
From source file:ca.myewb.model.ApplicationSessionModel.java
License:Open Source License
public static List<ApplicationSessionModel> getRecentlyClosedSessions(int pastWeeks) { Calendar cal = GregorianCalendar.getInstance(); cal.add(Calendar.DATE, pastWeeks * -7); SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(HibernateUtil .currentSession().createCriteria(ApplicationSessionModel.class) .add(Restrictions.gt("closeDate", cal.getTime())).add(Restrictions.le("closeDate", new Date()))); return openSessions.list(); }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public PagingLoadResult<Loan> getLoans(PagingLoadConfig configs) throws PigeException { PermissionHelper.checkLoanManagementPermission(getThreadLocalRequest()); logger.debug("Rcupration des emprunts " + "[Pagination: dpart=" + configs.getOffset() + ", max=" + configs.getLimit() + "] ..."); Transaction tx = null;/*from w w w. java 2 s. com*/ List<Loan> loans = null; Session session = null; Integer loanCount = 0; Integer offset = 0; Integer limit = 0; try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); Date startDate = null; Date endDate = null; Criteria loansCriteria = session.createCriteria(Loan.class); Criteria usersCriteria = null; List<FilterConfig> searchConfigs = configs.get(PIGE.SEARCH_CONFIGS); List<FilterConfig> filterConfigs = configs.get(PIGE.FILTER_CONFIGS); List<FilterConfig> userParam = null; List<FilterConfig> loanParam = null; if (searchConfigs != null) { for (FilterConfig fc : searchConfigs) { if (fc.getField().equals("params")) { logger.debug("Extraction du FilterConfig 'params'..."); BaseListFilterConfig blfc = (BaseListFilterConfig) fc; userParam = blfc.get(PIGE.USER_CONFIGS); logger.debug("Extraction de la liste 'user-param'..." + (userParam == null ? "N/D" : "OK")); loanParam = blfc.get(PIGE.LOAN_CONFIGS); logger.debug("Extraction de la liste 'loan-param'..." + (loanParam == null ? "N/D" : "OK")); break; } } } Criterion filterCriterion = null; Iterator<FilterConfig> itr = null; FilterConfig fc = null; if (loanParam != null) { itr = loanParam.iterator(); while (itr.hasNext()) { fc = itr.next(); if (fc instanceof BaseDateFilterConfig) { BaseDateFilterConfig dateFC = (BaseDateFilterConfig) fc; startDate = dateFC.get(PIGE.START_DATE, null); endDate = dateFC.get(PIGE.END_DATE, null); itr.remove(); break; } } FilterConfig matchModeConfig = new BaseBooleanFilterConfig(); matchModeConfig.setField(PIGE.MATCH_MODE); matchModeConfig.setValue(Boolean.FALSE); loanParam.add(matchModeConfig); filterCriterion = PigeHibernateUtil.buildFilterCriterion(loanParam); if (filterCriterion != null) { loansCriteria.add(filterCriterion); } if (startDate != null) { logger.debug("Restrictions sur la date d'chance: entre " + startDate.toString() + " et " + (endDate == null ? new Date() : endDate) + " inclusivement..."); loansCriteria.add(Restrictions.between(Loan.START_DATE_REF, startDate, (endDate == null ? new Date() : endDate))); } else if (endDate != null) { logger.debug("Restrictions sur la date d'chance: <= " + endDate.toString()); loansCriteria.add(Restrictions.le(Loan.START_DATE_REF, endDate)); } } if (filterConfigs != null && filterConfigs.size() > 0) { filterCriterion = PigeHibernateUtil.buildFilterCriterion(filterConfigs); if (filterCriterion != null) { loansCriteria.add(filterCriterion); } } usersCriteria = loansCriteria.createCriteria(Loan.USER_REF, "usr", Criteria.LEFT_JOIN); if (userParam != null) { String userScope = null; itr = userParam.iterator(); while (itr.hasNext()) { fc = itr.next(); if (fc.getField().equals("scope")) { userScope = (String) fc.getValue(); itr.remove(); break; } } if (userScope != null && !userScope.isEmpty() && !userScope.equals("*")) { logger.debug( "Restriction de la recherche sur un usager " + "spcifique: [" + userScope + "] ..."); usersCriteria.add(Restrictions.like(User.IDENTIFIER_REF, userScope, MatchMode.EXACT)); } else { logger.debug("Restriction de la recherche sur un ou des " + "usager spcifique..."); filterCriterion = PigeHibernateUtil.buildFilterCriterion(userParam); if (filterCriterion != null) { usersCriteria.add(filterCriterion); } } } loanCount = (Integer) loansCriteria.setProjection(Projections.rowCount()).uniqueResult(); offset = configs.getOffset(); limit = loanCount; if (limit > 0 && configs.getLimit() > 0) { limit = Math.min(configs.getLimit(), limit); } logger.debug("Paramtres d'extraction des donnes: dpart=" + offset + ", max=" + limit + "] ..."); loansCriteria.setProjection(null); loansCriteria.setResultTransformer(Criteria.ROOT_ENTITY); loans = (List) loansCriteria.addOrder(Order.asc("usr." + User.LOAN_NO_REF)).setFirstResult(offset) .setMaxResults(limit).list(); tx.commit(); logger.debug("Rcupration russie!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } if (loans == null) { loans = new ArrayList(); } return new BasePagingLoadResult(loans, offset, loanCount); }
From source file:ch.astina.hesperid.dao.hibernate.ObserverDAOHibernate.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* w w w .jav a2 s .c om*/ public List<ObserverParameter> getObserverParameters(Observer observer, Date from, Date until) { return session.createCriteria(ObserverParameter.class).add(Restrictions.eq("observer", observer)) .add(Restrictions.ge("updated", from)).add(Restrictions.le("updated", until)) .addOrder(Order.asc("updated")).list(); }
From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*from w w w .ja va2 s.c om*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { AssertUtils.hasText(propertyName, "propertyName?"); Criterion criterion = null; //?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LE: criterion = Restrictions.le(propertyName, propertyValue); break; case LT: criterion = Restrictions.lt(propertyName, propertyValue); break; case GE: criterion = Restrictions.ge(propertyName, propertyValue); break; case GT: criterion = Restrictions.gt(propertyName, propertyValue); } return criterion; }
From source file:cn.newtouch.hibernate.dao.StudentDAO.java
License:Open Source License
public static void main(String[] args) { try {/*from w w w. j a v a 2 s . c om*/ Session session = HibernateUtil.getSession(); String hql = " from Student"; List<Student> userList = session.createQuery(hql).list(); System.out.println("=====1=======" + userList.size()); Criteria criteria = session.createCriteria(Student.class); // criteria.add(Restrictions.eq("name", "HZZ")); // map criteria.add(Restrictions.allEq(new HashMap<String, String>())); // criteria.add(Restrictions.gt("id", new Long(1))); // criteria.add(Restrictions.ge("id", new Long(1))); // ? criteria.add(Restrictions.lt("id", new Long(1))); // ? criteria.add(Restrictions.le("id", new Long(1))); // xxxyyy criteria.add(Restrictions.between("id", new Long(1), new Long(2))); // ? criteria.add(Restrictions.like("name", "H")); // and? criteria.add(Restrictions.and(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); // or? criteria.add(Restrictions.or(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); userList = criteria.list(); System.out.println("=====2=======" + userList.size()); Student student = new Student(); student.setId(123456L); student.setName("hzz"); student.setAge(14); save(student); System.out.println("OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:cn.newtouch.util.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./* w w w. j a v a 2 s . co m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; // ?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LE: criterion = Restrictions.le(propertyName, propertyValue); break; case LT: criterion = Restrictions.lt(propertyName, propertyValue); break; case GE: criterion = Restrictions.ge(propertyName, propertyValue); break; case GT: criterion = Restrictions.gt(propertyName, propertyValue); } return criterion; }
From source file:cn.newtouch.util.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,.//ww w .ja v a 2 s . c o m */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; //?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LE: criterion = Restrictions.le(propertyName, propertyValue); break; case LT: criterion = Restrictions.lt(propertyName, propertyValue); break; case GE: criterion = Restrictions.ge(propertyName, propertyValue); break; case GT: criterion = Restrictions.gt(propertyName, propertyValue); } return criterion; }
From source file:cn.trymore.oa.service.system.impl.ServiceSystemLogImpl.java
License:Open Source License
@Override public PaginationSupport<ModelSystemLog> getPaginationByEntity(ModelSystemLog entity, PagingBean pagingBean) throws ServiceException { DetachedCriteria criteria = DetachedCriteria.forClass(ModelSystemLog.class); if (entity != null) { if (UtilString.isNotEmpty(entity.getExeOperation())) { criteria.add(Restrictions.eq("exeOperation", entity.getExeOperation())); }/* w w w.j a v a 2 s. c o m*/ if (entity.getDistrictId() != null && UtilString.isNotEmpty(entity.getDistrictId())) { criteria.createCriteria("user").createCriteria("district") .add(Restrictions.eq("id", entity.getDistrictId())); } if (entity.getStartTime() != null && UtilString.isNotEmpty(entity.getStartTime())) { criteria.add(Restrictions.ge("createtime", entity.getStartTime())); } if (entity.getEndTime() != null && UtilString.isNotEmpty(entity.getEndTime())) { criteria.add(Restrictions.le("createtime", entity.getEndTime())); } } // added by Jeccy.Zhao on 14/10/2012 criteria.addOrder(Order.desc("createtime")); return this.getAll(criteria, pagingBean); }
From source file:co.com.codesoftware.logica.contabilidad.ContabilidadLogica.java
/** * Funcion con la cual obtengo los movimientos contables de acuerdo a las * fechas y al tipo de documento//ww w . j a v a 2 s . c o m * * @param fechaIn * @param fechaFin * @param tipoDoc * @return */ public List<MoviContableEntity> consultarMovimientoscontable(Date fechaIn, Date fechaFin, String tipoDoc) { List<MoviContableEntity> rta = null; try { this.initOperation(); Criteria crit = this.sesion.createCriteria(MoviContableEntity.class); crit.setFetchMode("subcuenta", FetchMode.JOIN); crit.setFetchMode("tipoDocumento", FetchMode.JOIN); crit.setFetchMode("auxiliar", FetchMode.JOIN); if (!"-1".equalsIgnoreCase(tipoDoc)) { crit.add(Restrictions.eq("llave", tipoDoc)); } if (fechaIn != null || fechaFin != null) { if (fechaIn != null && fechaFin != null) { fechaFin.setHours(23); fechaFin.setMinutes(59); fechaFin.setSeconds(59); crit.add(Restrictions.between("fecha", fechaIn, fechaFin)); } else if (fechaIn != null) { crit.add(Restrictions.le("fecha", fechaIn)); } else if (fechaFin != null) { crit.add(Restrictions.gt("fecha", fechaFin)); } } rta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return rta; }
From source file:co.com.codesoftware.logica.contabilidad.ContabilidadLogica.java
public List<MoviContableEntity> consultarMovContXCuenta(Date fechaIn, Date fechaFin, String cuenta, String tipo, Integer tercero) {/*from w w w .ja v a 2s. c om*/ List<MoviContableEntity> rta = null; try { System.out.println("cuenta:" + cuenta); System.out.println("tipo:" + tipo); System.out.println("tercero:" + tercero); this.initOperation(); Criteria crit = this.sesion.createCriteria(MoviContableEntity.class); crit.setFetchMode("subcuenta", FetchMode.JOIN); crit.setFetchMode("tipoDocumento", FetchMode.JOIN); crit.setFetchMode("auxiliar", FetchMode.JOIN); if (cuenta != null && !"".equalsIgnoreCase(cuenta)) { crit.createAlias("subcuenta", "sbcu"); crit.add(Restrictions.like("sbcu.codigo", cuenta, MatchMode.ANYWHERE)); } //MO-001 if (tipo != null && !"".equalsIgnoreCase(tipo)) { crit.add(Restrictions.eq("tipoTercero", Integer.parseInt(tipo))); } if (tercero != null && tercero != -1) { crit.add(Restrictions.eq("tercero", tercero)); } //MO-001 if (fechaIn != null || fechaFin != null) { if (fechaIn != null && fechaFin != null) { fechaFin.setHours(23); fechaFin.setMinutes(59); fechaFin.setSeconds(59); crit.add(Restrictions.between("fecha", fechaIn, fechaFin)); } else if (fechaIn != null) { crit.add(Restrictions.le("fecha", fechaIn)); } else if (fechaFin != null) { crit.add(Restrictions.gt("fecha", fechaFin)); } } crit.addOrder(Order.desc("id")); rta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return rta; }