List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:co.com.codesoftware.logica.inventario.PedidoLogica.java
/** * Consulta de pedidos por los filtros de fecha, usuario y estado * * @param estado/* w w w . j a v a2 s . co m*/ * @param idUsuario * @param fInicial * @param fFinal * @return */ public List<PedidoEntity> consultaPedidoXFiltros(String estado, Integer idUsuario, Date fInicial, Date fFinal) { List<PedidoEntity> respuesta = null; try { initOperation(); Criteria crit = sesion.createCriteria(PedidoEntity.class).createAlias("usuario", "us") .add(Restrictions.ge("fecha", fInicial)).add(Restrictions.lt("fecha", fFinal)) .setFetchMode("sede", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN) .setFetchMode("cliente", FetchMode.JOIN).setFetchMode("usuario.persona", FetchMode.JOIN) .setFetchMode("usuario.perfil", FetchMode.JOIN) //.add(Restrictions.between("fecha", fInicial, fFinal)) .add(Restrictions.eq("us.id", idUsuario)); if (!"".equalsIgnoreCase(estado)) { crit.add(Restrictions.eq("estado", estado)); } respuesta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
From source file:co.com.codesoftware.logica.inventario.SolicitudLogica.java
/** * metodo que consulta las solicitudes por los filtros seleccionados * * @param fechaInicial/* w w w . j a va 2s . com*/ * @param fechaFinal * @param estado * @param usuario * @param sede * @return */ public List<SolicitudEntity> consultaSolicitudesXFiltro(Date fechaInicial, Date fechaFinal, String estado, Integer usuario, Integer sede) { System.out.println(fechaInicial); System.out.println(fechaFinal); System.out.println(estado); System.out.println(sede); System.out.println(usuario); List<SolicitudEntity> respuesta = null; try { initOperation(); Criteria crit = sesion.createCriteria(SolicitudEntity.class); if (fechaInicial != null && fechaFinal != null) { crit.add(Restrictions.ge("fecha", fechaInicial)); fechaFinal.setHours(23); fechaFinal.setMinutes(59); fechaFinal.setSeconds(59); crit.add(Restrictions.lt("fecha", fechaFinal)); } if (estado != null && !"".equalsIgnoreCase(estado)) { crit.add(Restrictions.eq("estado", estado)); } if (usuario != null && usuario != 0) { crit.createAlias("usuario", "usu").add(Restrictions.eq("usu.id", usuario)); } if (sede != null && sede != 0) { crit.createAlias("sede", "sede").add(Restrictions.eq("sede.id", sede)); } crit.addOrder(Order.desc("id")); respuesta = crit.setFetchMode("sede", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN).list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
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 {//w w w. ja v a 2 s .c om 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.abssh.util.GenericDao.java
License:Apache License
/** * ??Criterion,./*from w ww . j ava 2s .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
/** * ??//from ww w.java 2 s . c o m */ 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 . j av a 2 s .c o 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)); } } } }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code> * represents either an array of <code>String</code> or another object. The different values in the * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the * search.// w ww . j a v a 2 s. c o m * * @param criteria * @param parameterName * @param parameterValues * @param searchIfNull * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator, MatchMode matchMode) { if (parameterValues != null) { Disjunction disjunction = null; Conjunction conjunction = null; switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.like(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( Restrictions.ilike(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ilike(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.eq(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ge(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.gt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.le(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.lt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.IN_COMPARATOR: { criteria.add(Restrictions.in(parameterName, parameterValues)); break; } case SearchParameter.NOT_IN_COMPARATOR: { criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues))); break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { conjunction = Restrictions.conjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { conjunction.add(Restrictions.ne(parameterName, parameterValues[index])); } else { conjunction.add(Restrictions.isNotNull(parameterName)); } } break; } } if (disjunction != null) { criteria.add(disjunction); } if (conjunction != null) { criteria.add(conjunction); } } else { switch (comparator) { case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.bean.PropertyUserBean.java
public List<Property> getGenerateListProperty() { Dao dao = new Dao(); Users u = (Users) SessionUtils.getSession().getAttribute("login"); if (u != null) { LogicalExpression logic = null;/*from w w w. j av a 2 s . c o m*/ Criterion cr = Restrictions.eq("users", u); if (publish != null && !publish.equals("")) { Criterion pub = Restrictions.eq("proPublish", Boolean.parseBoolean(publish)); logic = Restrictions.and(cr, pub); } else { Criterion pub = Restrictions.isNotNull("proPublish"); logic = Restrictions.and(cr, pub); } Order o = Order.desc("proPublishDate"); if (fromDate != null) { Criterion from = Restrictions.gt("proCreateDate", fromDate); logic = Restrictions.and(logic, from); } if (toDate != null) { Criterion to = Restrictions.lt("proCreateDate", toDate); logic = Restrictions.and(logic, to); } if (cat != 0) { PropertyType t = new PropertyType(cat); Criterion ca = Restrictions.eq("propertyType", t); logic = Restrictions.and(logic, ca); } listProperty = dao.getByCondition(Property.class, logic, o); } return listProperty; }
From source file:com.bloatit.data.queries.DaoAbstractQuery.java
License:Open Source License
/** * Creates a criterion on a {@link Comparable} element. * <p>/*from w w w . j a v a2 s . c o m*/ * For example: <code> * createNbRestriction(GREATER, "amount", 12) * </code> Will select elements with amount > 12. * </p> * * @param cmp the comparator * @param element the countable element name. * @param nb the number on which we try to compare the <code>element</code> * value. * @return the criterion */ protected final Criterion createNbCriterion(final Comparator cmp, final String element, final Object nb) { switch (cmp) { case EQUAL: return Restrictions.eq(element, nb); case LESS: return Restrictions.lt(element, nb); case LESS_EQUAL: return Restrictions.le(element, nb); case GREATER: return Restrictions.gt(element, nb); case GREATER_EQUAL: return Restrictions.ge(element, nb); default: return Restrictions.eq(element, nb); } }
From source file:com.bloatit.data.queries.DaoOfferQuery.java
License:Open Source License
/** * Select only the expired offers */ public void hasExpired() { add(Restrictions.lt("expirationDate", new Date())); }