List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:cn.newtouch.hibernate.dao.StudentDAO.java
License:Open Source License
public static void main(String[] args) { try {//from w ww .j a v a 2 s. c o m 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 2s. 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,.//from w ww. j a v a 2 s . c om */ 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: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/*w w w . java2s . 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) {// w w w.j a v a 2s .c o m 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; }
From source file:co.com.siscomputo.gestiondocumental.logic.FiltroLogic.java
public ObjetoRetornaEntity documentosFiltrado(Integer idTipoDocumental, Integer idPlantilla, Integer idAccion, Date fecha1, Date fecha2) { ObjetoRetornaEntity retorna = new ObjetoRetornaEntity(); try {/*from w ww.ja va 2 s . c o m*/ String validaConexion = initOperation(); if (!"Ok".equalsIgnoreCase(validaConexion)) { retorna.setNumeroRespuesta(3); retorna.setTrazaRespuesta("Error de Conexin " + validaConexion); } else { //System.ot.println("F1: "+idTipoDocumental); //System.ot.println("F2: "+idPlantilla); //System.ot.println("F3: "+idAccion); System.out.println("F4: " + fecha1); //System.ot.println("F5: "+fecha2); Criteria criteria = sesion.createCriteria(DocumentoEntity.class); if (idTipoDocumental == 0) { //System.ot.println("TipoDocumental Nulo"); } else { //System.ot.println(""); criteria.add(Restrictions.eq("tipoDocumentalDocumento.idTipoDocumental", idTipoDocumental)); } if (idPlantilla == 0) { //System.ot.println("Plantilla Nulo"); } else { criteria.add(Restrictions.eq("plantilla.idPlantilla", idPlantilla)); } if (idAccion == 0) { //System.ot.println("accion nula"); } else { criteria.add(Restrictions.eq("accionDocumento.idAccion", idAccion)); } if (fecha1 == null || fecha2 != null) { System.out.println("Fecha1 Nula"); } else { /* SimpleDateFormat formas=new SimpleDateFormat("dd/MM/yyyy"); String faux=formas.format(fecha1); System.out.println("No nula1: "+fecha1); criteria.add(Restrictions.sqlRestriction("DOCU_FCRE>'"+faux+"'"));*/ criteria.add(Restrictions.gt("fechaDocumento", fecha1)); } if (fecha2 == null || fecha1 != null) { System.out.println("Fecha2 Nula"); } else { /* SimpleDateFormat formas=new SimpleDateFormat("dd-MM-yyyy"); String faux2=formas.format(fecha2); System.out.println("No nula2: "+fecha2); criteria.add(Restrictions.sqlRestriction("DOCU_FCRE<'"+faux2+"'"));*/ criteria.add(Restrictions.lt("fechaDocumento", fecha2)); } if (fecha1 != null && fecha2 != null) { criteria.add(Restrictions.between("fechaDocumento", fecha1, fecha2)); } retorna.setRetorna((ArrayList<Object>) criteria.list()); retorna.setTrazaRespuesta("Carga exitosa de documentos filtrados"); retorna.setNumeroRespuesta(99); //System.ot.println("UAB: "+criteria.list().size()); } } catch (Exception e) { e.printStackTrace(); retorna = new ObjetoRetornaEntity(); retorna.setNumeroRespuesta(0); retorna.setTrazaRespuesta(e.getMessage()); } finally { try { sesion.close(); } catch (HibernateException hibernateException) { hibernateException.printStackTrace(); } } return retorna; }
From source file:com.abiquo.server.core.enterprise.UserDAO.java
License:Open Source License
private Criteria createCriteria(final Enterprise enterprise, final Role role, final String[] filters, final String orderBy, final boolean desc, final boolean connected) { Criteria criteria = createCriteria(); if (enterprise != null) { criteria.add(sameEnterprise(enterprise)); }/*from ww w . j a v a2 s . c o m*/ if (role != null) { criteria.add(sameRole(role)); } if (!ArrayUtils.isEmpty(filters)) { for (String filter : filters) { if (!StringUtils.isEmpty(filter)) { criteria.add(filterBy(filter)); } } } if (!StringUtils.isEmpty(orderBy)) { Order order = Order.asc(orderBy); if (desc) { order = Order.desc(orderBy); } criteria.addOrder(order); } if (connected) { criteria.createCriteria("sessions").add(Restrictions.gt("expireDate", new Date())); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); } return criteria; }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??Criterion,.//from ww w .j ava 2 s . c o m */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object[] propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName should not be null!"); Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??// ww w . j ava2 s . c om */ private Criterion getCriterion(String propertyName, Object[] propertyValue, MatchType matchType) { Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, String.valueOf(propertyValue[0]), MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } else if (MatchType.LEN.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. * * @param criteria/*from w ww.ja va 2 s . co m*/ * @param parameterName * @param parameterValue * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object parameterValue, int comparator, MatchMode matchMode) { switch (comparator) { case SearchParameter.NOT_NULL_COMPARATOR: { criteria.add(Restrictions.isNotNull(parameterName)); break; } case SearchParameter.NULL_COMPARATOR: { criteria.add(Restrictions.isNull(parameterName)); break; } case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { if (parameterValue != null) { switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.like(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.like(parameterName, parameterValue)); } break; } case SearchParameter.NOT_LIKE_COMPARATOR: { SimpleExpression expression; if ((matchMode != null) && (parameterValue instanceof String)) { expression = Restrictions.like(parameterName, (String) parameterValue, matchMode); } else { expression = Restrictions.like(parameterName, parameterValue); } criteria.add(Restrictions.not(expression)); break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.ilike(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.ilike(parameterName, parameterValue)); } break; } case SearchParameter.NOT_INSENSITIVE_LIKE_COMPARATOR: { Criterion criterion; if ((matchMode != null) && (parameterValue instanceof String)) { criterion = Restrictions.ilike(parameterName, (String) parameterValue, matchMode); } else { criterion = Restrictions.ilike(parameterName, parameterValue); } criteria.add(Restrictions.not(criterion)); break; } case SearchParameter.EQUAL_COMPARATOR: { criteria.add(Restrictions.eq(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.ge(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_COMPARATOR: { criteria.add(Restrictions.gt(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.le(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_COMPARATOR: { criteria.add(Restrictions.lt(parameterName, parameterValue)); break; } case SearchParameter.IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.in(parameterName, (Collection) parameterValue)); } break; } case SearchParameter.NOT_IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.not(Restrictions.in(parameterName, (Collection) parameterValue))); } break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { criteria.add(Restrictions.ne(parameterName, parameterValue)); break; } } } else { criteria.add(Restrictions.isNull(parameterName)); } } } }