public Map<String, Object> lista(Map<String, Object> params) { log.debug("Buscando lista de facturas con params {}", params); if (params == null) { params = new HashMap<>(); } if (!params.containsKey("max")) { params.put("max", 10); } else { params.put("max", Math.min((Integer) params.get("max"), 100)); } if (params.containsKey("pagina")) { Long pagina = (Long) params.get("pagina"); Long offset = (pagina - 1) * (Integer) params.get("max"); params.put("offset", offset.intValue()); } if (!params.containsKey("offset")) { params.put("offset", 0); } Criteria criteria = currentSession().createCriteria(FacturaAlmacen.class); Criteria countCriteria = currentSession().createCriteria(FacturaAlmacen.class); if (params.containsKey("almacen")) { criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); } if (params.containsKey("filtro")) { String filtro = (String) params.get("filtro"); Disjunction propiedades = Restrictions.disjunction(); propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE)); criteria.add(propiedades); countCriteria.add(propiedades); } if (params.containsKey("order")) { String campo = (String) params.get("order"); if (params.get("sort").equals("desc")) { criteria.addOrder(Order.desc(campo)); } else { criteria.addOrder(Order.asc(campo)); } } else { criteria.createCriteria("estatus").addOrder(Order.asc("prioridad")); } criteria.addOrder(Order.desc("fechaModificacion")); if (!params.containsKey("reporte")) { criteria.setFirstResult((Integer) params.get("offset")); criteria.setMaxResults((Integer) params.get("max")); } params.put("facturas", criteria.list()); countCriteria.setProjection(Projections.rowCount()); params.put("cantidad", (Long) countCriteria.list().get(0)); return params; }
private T orderDirection(boolean ascending) { int i = ensureOrderIndex(); Order order = this.orderEntries.get(i); if (order.isAscending() != ascending) { // only swap out the Order statement if it is different: String name = order.getPropertyName(); Order newOrder = ascending ? Order.asc(name) : Order.desc(name); this.orderEntries.set(i, newOrder); } return (T) this; }
public List<User> getUserValidate(String piority, Integer page) { Criteria criteria = getSession().createCriteria(User.class); criteria.add(Restrictions.eq("validateStu", 0)); criteria.add(Restrictions.like("piority", "%" + piority + "%")); criteria.addOrder(Order.asc("dateCreate")); page = (page - 1) * 10; criteria.setFirstResult(page); criteria.setMaxResults(10); List<User> list = (List<User>) criteria.list(); closeSession(); return list; }
public Plantel getPlantelById() { Session session = HibernateUtil.getSessionFactory().openSession(); Plantel plantel = null; ProjectionList plist = Projections.projectionList(); plist.add(Projections.property("p.nombre").as("nombre")); Criteria criteria = session .createCriteria(Plantel.class, "p") .setProjection(plist) .setResultTransformer(new AliasToBeanResultTransformer(Plantel.class)) .addOrder(Order.asc("nombre")); plantel = (Plantel) criteria.uniqueResult(); session.close(); return plantel; }
@SuppressWarnings("unchecked") @Override public List<Lancamento> listar(Conta conta, Date dataInicio, Date dataFim) { Criteria criteria = this.session.createCriteria(Lancamento.class); if (dataInicio != null && dataFim != null) { criteria.add(Restrictions.between("data", dataInicio, dataFim)); } else if (dataInicio != null) { criteria.add(Restrictions.ge("data", dataInicio)); } else if (dataFim != null) { criteria.add(Restrictions.le("data", dataFim)); } criteria.add(Restrictions.eq("conta", conta)); criteria.addOrder(Order.asc("data")); return criteria.list(); }
/** * 设置分页参数到Criteria对象,辅助函数. * * @param c Hibernate Criteria * @param pageRequest 分页请求参数 * @return {@link org.hibernate.Criteria} */ protected Criteria setPageRequestToCriteria(Criteria c, PageRequest pageRequest) { Assert.isTrue(pageRequest.getPageSize() > 0, "分页大小必须大于0"); c.setFirstResult(pageRequest.getOffset()); c.setMaxResults(pageRequest.getPageSize()); if (pageRequest.isOrderBySetted()) { for (PageRequest.Sort sort : pageRequest.getSort()) { Order order = null; if (sort.getDir().equals(PageRequest.Sort.ASC)) { order = Order.asc(sort.getProperty()); } else { order = Order.desc(sort.getProperty()); } c.addOrder(order); } } return c; }
public static Integer findPiority(String pior, Integer status) { Integer sizePioruty = 0; StringBuffer piorityBuffer = new StringBuffer(); Criteria criteria = getSession().createCriteria(User.class); criteria.add(Restrictions.like("piority", pior + "%")); criteria.add(Restrictions.eq("status", status)); criteria.add(new LengthExpression("piority", pior.length() + 3)); criteria.addOrder(Order.asc("piority")); List<User> list = (List<User>) criteria.list(); sizePioruty = list.size(); if ((list.size() > 0 && status == 3) || (status == 2 && list.size() > 0)) { piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 3) + ""); piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 2) + ""); piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 1) + ""); sizePioruty = Integer.parseInt(piorityBuffer.toString()) + 1; } if (list.size() <= 0 && status == 2) { sizePioruty++; } if (list.size() <= 0 && status == 3) { sizePioruty++; } return sizePioruty; }
/** @return an {@link Order} that sorts ascending by this field's value */ public Order asc() { return Order.asc(this); }
public T orderBy(Property property) { Order order = Order.asc( property.getName()); // ascending by default - they can call descending() to reverse return add(order); }
public Map<String, Object> lista(Map<String, Object> params) { log.debug("Buscando lista de asociado con params {}", params); if (params == null) { params = new HashMap<>(); } if (!params.containsKey("max")) { params.put("max", 10); } else { params.put("max", Math.min((Integer) params.get("max"), 100)); } if (params.containsKey("pagina")) { Long pagina = (Long) params.get("pagina"); Long offset = (pagina - 1) * (Integer) params.get("max"); params.put("offset", offset.intValue()); } if (!params.containsKey("offset")) { params.put("offset", 0); } if (!params.containsKey("asociacion")) { params.put("asociados", new ArrayList()); params.put("cantidad", 0L); return params; } Criteria criteria = currentSession().createCriteria(Asociado.class); Criteria countCriteria = currentSession().createCriteria(Asociado.class); if (params.containsKey("asociacion")) { log.debug("valor de asociacion" + params.get("asociacion")); criteria .createCriteria("asociacion") .add(Restrictions.eq("id", ((Asociacion) params.get("asociacion")).getId())); countCriteria .createCriteria("asociacion") .add(Restrictions.eq("id", ((Asociacion) params.get("asociacion")).getId())); } if (params.containsKey("filtro")) { String filtro = (String) params.get("filtro"); Disjunction propiedades = Restrictions.disjunction(); propiedades.add(Restrictions.ilike("username", filtro, MatchMode.ANYWHERE)); propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE)); propiedades.add(Restrictions.ilike("apellido", filtro, MatchMode.ANYWHERE)); criteria.add(propiedades); countCriteria.add(propiedades); } if (params.containsKey("order")) { String campo = (String) params.get("order"); if (params.get("sort").equals("desc")) { criteria.addOrder(Order.desc(campo)); } else { criteria.addOrder(Order.asc(campo)); } } if (!params.containsKey("reporte")) { criteria.setFirstResult((Integer) params.get("offset")); criteria.setMaxResults((Integer) params.get("max")); } params.put("asociados", criteria.list()); countCriteria.setProjection(Projections.rowCount()); params.put("cantidad", (Long) countCriteria.list().get(0)); return params; }