List of usage examples for org.hibernate.criterion Restrictions like
public static SimpleExpression like(String propertyName, String value, MatchMode matchMode)
From source file:cn.newtouch.util.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,.//from 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:co.com.codesoftware.logic.ProductoLogic.java
/** * Funcion que consulta a la base de datos los productos mediante los * filtros y por defecto consulta el estado activo * * @param codigo/*from w ww . j a v a2s . c o m*/ * @param nombre * @param descripcion * @return */ public List<ProductoEntity> consultaProductos(String codigo, String nombre, String descripcion) { List<ProductoEntity> respuesta = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(ProductoEntity.class); if (codigo != null && !"".equalsIgnoreCase(codigo)) { crit.add(Restrictions.like("codigo", codigo, MatchMode.ANYWHERE)); } if (nombre != null && !"".equalsIgnoreCase(nombre)) { crit.add(Restrictions.like("nombre", nombre, MatchMode.ANYWHERE)); } if (descripcion != null && !"".equalsIgnoreCase(descripcion)) { crit.add(Restrictions.like("descripcion", descripcion, MatchMode.ANYWHERE)); } crit.add(Restrictions.eq("estado", "A")); respuesta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
From source file:co.com.codesoftware.logic.ProductoLogic.java
/** * Funcion que consulta los prodiuctos por los tres filtros * * @param categoria/*from w w w . j ava 2 s . c o m*/ * @param subcategoria * @param marca * @return */ public List<ProductoEntity> consultaProductosCatSubMarc(Integer categoria, String subcategoria, String marca) { List<ProductoEntity> respuesta = null; try { CategoriaEntity categoriaEntity = new CategoriaEntity(); categoriaEntity.setId(categoria); this.initOperation(); Criteria crit = sesion.createCriteria(ProductoEntity.class); if (subcategoria != null && !"".equalsIgnoreCase(subcategoria)) { crit.createAlias("referencia", "r") .add(Restrictions.like("r.descripcion", subcategoria, MatchMode.ANYWHERE)); } if (marca != null && "".equalsIgnoreCase(marca)) { crit.createAlias("marca", "m").add(Restrictions.like("nombre", marca, MatchMode.ANYWHERE)); } crit.add(Restrictions.eq("estado", "A")); crit.add(Restrictions.eq("categoria", categoriaEntity)); respuesta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
From source file:co.com.codesoftware.logic.ProductoLogic.java
/** * Funcion la cual busca un producto por medio de su codigo externo * * @param codExterno//from w w w. j a v a 2 s . co m * @return */ public List<ProductoEntity> consultaProductosXCodigoExt(String codExterno) { List<ProductoEntity> respuesta = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(ProductoEntity.class) .add(Restrictions.like("codigoExt", codExterno, MatchMode.ANYWHERE).ignoreCase()) .setFetchMode("referencia", FetchMode.JOIN).setFetchMode("marca", FetchMode.JOIN) .setFetchMode("categoria", FetchMode.JOIN).setFetchMode("subcuenta", FetchMode.JOIN); respuesta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
From source file:co.com.codesoftware.logic.SubCuentaLogic.java
/** * Funcion que consulta las subcuentas por un filtro en particular ya sea codigo * o nombre//from w w w . j a v a 2 s . c o m * @param filtro * @return */ public List<SubCuentaEntity> consultaSubCuentaFiltro(String filtro) { List<SubCuentaEntity> resultado = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(SubCuentaEntity.class); Validaciones val = new Validaciones(); if (val.validaNumero(filtro)) { crit.add(Restrictions.like("codigo", filtro, MatchMode.ANYWHERE)); } else { crit.add(Restrictions.like("nombre", filtro, MatchMode.ANYWHERE)); } resultado = crit.list(); } catch (Exception e) { e.printStackTrace(); } return resultado; }
From source file:co.com.codesoftware.logica.admin.UsuarioLogica.java
/** * metodo que consulta los usuarios por permiso * @param permiso/*from w ww .j a v a 2s .c o m*/ * @return */ public List<UsuarioEntity> consultaUsuariosXPermiso(String permiso) { List<UsuarioEntity> respuesta = new ArrayList<>(); try { initOperation(); respuesta = sesion.createCriteria(UsuarioEntity.class).createAlias("perfil", "pf") .add(Restrictions.like("pf.permisos", permiso, MatchMode.ANYWHERE)) .add(Restrictions.eq("estado", "A")).list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
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. j a 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; }
From source file:co.com.codesoftware.logica.inventario.ProductoLogica.java
/** * Funcion con la cual obtengo todos los productos del sistema que tengan * precio dentro de una sede//www.ja v a 2 s .com * * @param idSede Integer Sede la cual se tendra como referencia * @param criterio * @return */ public List<PrecioProductoEntity> obtieneProductosConPrecioXSedeYCrit(Integer idSede, String criterio) { List<PrecioProductoEntity> rta = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(PrecioProductoEntity.class); crit.createAlias("idSede", "sede").add(Restrictions.eq("sede.id", idSede)); crit.createAlias("producto", "prod") .add(Restrictions.like("prod.descripcion", criterio, MatchMode.ANYWHERE).ignoreCase()); crit.add(Restrictions.eq("estado", "A")); crit.setFetchMode("producto", FetchMode.JOIN); crit.setFetchMode("producto.referencia", FetchMode.JOIN); crit.setFetchMode("producto.marca", FetchMode.JOIN); crit.setFetchMode("producto.categoria", FetchMode.JOIN); crit.setFetchMode("producto.subcuenta", FetchMode.JOIN); crit.addOrder(Order.asc("producto.id")); rta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return rta; }
From source file:co.com.codesoftware.logica.receta.RecetaLogica.java
/** * funcion que consulta las recetas por criterio * @param sede//from w w w . ja v a 2 s .co m * @param criterio * @return */ public List<PrecioRecetaEntity> getRecetasXCriterio(Integer sede, String criterio) { List<PrecioRecetaEntity> receta = null; try { initOperation(); receta = sesion.createCriteria(PrecioRecetaEntity.class).createAlias("receta", "rec") .add(Restrictions.like("rec.nombre", criterio, MatchMode.ANYWHERE).ignoreCase()) .add(Restrictions.eq("estado", "A")).add(Restrictions.eq("idSede", sede)) .setFetchMode("receta", FetchMode.JOIN).list(); } catch (Exception e) { e.printStackTrace(); } return receta; }
From source file:com.abiquo.server.core.cloud.VirtualDatacenterDAO.java
License:Open Source License
public Collection<VirtualDatacenter> findByEnterpriseAndDatacenterFilter(final Enterprise enterprise, final Datacenter datacenter, final User user, final FilterOptions filterOptions) { Collection<Criterion> restrictions = new ArrayList<Criterion>(); if (enterprise != null) { restrictions.add(sameEnterprise(enterprise)); }// w w w. j av a 2s . c o m if (datacenter != null) { restrictions.add(sameDatacenter(datacenter)); } if (user != null) { restrictions.add(availableToUser(user)); } if (filterOptions != null) { restrictions.add(Restrictions.like(VirtualDatacenter.NAME_PROPERTY, filterOptions.getFilter(), MatchMode.ANYWHERE)); } return findVirtualDatacentersByCriterions(restrictions, filterOptions); }