Ejemplo n.º 1
0
  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;
  }
  @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();
  }
Ejemplo n.º 3
0
 public Teacher findByFullName(String name, String firstName) {
   Criteria criteria;
   Transaction tx;
   Teacher teacher;
   Session session = ProductionSessionFactory.getDefault().getCurrentSession();
   tx = session.beginTransaction();
   try {
     criteria =
         session
             .createCriteria(persistentClass)
             .add(
                 Restrictions.and(
                     Restrictions.eq("name", name), Restrictions.eq("vorname", firstName)));
     teacher = (Teacher) criteria.uniqueResult();
   } finally {
     tx.commit();
   }
   return teacher;
 }