@Override
  public Criterion toCriterion(SearchQueryPart searchQueryPart) {

    if (!canHandleSearchQueryPart(searchQueryPart)) {
      LOGGER.error("Can't handle QueryPart : " + searchQueryPart);
      return null;
    }

    SearchableField searchableField = searchQueryPart.getSearchableField();
    List<String> valueList = searchQueryPart.getValueList();
    Object parsedValueMin =
        searchQueryPart.getParsedValue(valueList.get(0), searchableField.getRelatedFields().get(0));

    switch (searchQueryPart.getOp()) {
      case EQ:
        return Restrictions.and(
            Restrictions.le(searchableField.getRelatedFields().get(0), parsedValueMin),
            Restrictions.ge(searchableField.getRelatedFields().get(1), parsedValueMin));
      case BETWEEN:
        Object parsedValueMax =
            searchQueryPart.getParsedValue(
                valueList.get(1), searchableField.getRelatedFields().get(1));
        return Restrictions.or(
            Restrictions.and(
                Restrictions.ge(searchableField.getRelatedFields().get(0), parsedValueMin),
                Restrictions.le(searchableField.getRelatedFields().get(0), parsedValueMax)),
            Restrictions.and(
                Restrictions.ge(searchableField.getRelatedFields().get(1), parsedValueMin),
                Restrictions.le(searchableField.getRelatedFields().get(1), parsedValueMax)));
      default:
        LOGGER.fatal("Impossible to interpret " + searchQueryPart);
        return null;
    }
  }
Exemplo n.º 2
0
  @Override
  public Long verificarConflitoHorario(Horario model) {
    Criteria criteria = getSession().createCriteria(Horario.class);

    // Removendo da pesquisa o proprio registro quando for edição
    if (model.getId() != null && !model.getId().equals(0)) {
      List<Integer> listaIds = new ArrayList<Integer>();
      listaIds.add(model.getId());
      criteria.add(Restrictions.not(Restrictions.in("id", listaIds)));
    }

    criteria.add(Restrictions.eq("curso.id", model.getCurso().getId()));
    criteria.add(
        Restrictions.or(
            Restrictions.or(
                Restrictions.between(
                    "datHoraInicio", model.getDatHoraInicio(), model.getDatHoraFim()),
                Restrictions.between(
                    "datHoraFim", model.getDatHoraInicio(), model.getDatHoraFim())),
            Restrictions.and(
                Restrictions.and(
                    Restrictions.le("datHoraInicio", model.getDatHoraInicio()),
                    Restrictions.ge("datHoraFim", model.getDatHoraInicio())),
                Restrictions.and(
                    Restrictions.le("datHoraInicio", model.getDatHoraFim()),
                    Restrictions.ge("datHoraFim", model.getDatHoraFim())))));
    criteria.setProjection(Projections.rowCount());

    Long result = (Long) criteria.list().get(0);
    return result;
  }
  @SuppressWarnings("unchecked")
  public List<ValorTercero_v> buscarEnValoresTerceByFiltros(
      FiltroValTercerosBean filtro, String campoOrder, boolean orderByAsc) {

    Criteria criteria = getSession().createCriteria(getEntityClass());

    if (filtro.getAdministracionId() != null)
      criteria.add(Restrictions.eq("administracionId", filtro.getAdministracionId()));
    if (filtro.getBancoId() != null && filtro.getBancoId() > 0)
      criteria.add(Restrictions.eq("bancoId", filtro.getBancoId()));
    if (filtro.getCuentaId() != null && filtro.getCuentaId() > 0)
      criteria.add(Restrictions.eq("cuentaId", filtro.getCuentaId()));
    if (filtro.getTipoEntidadId() != null && filtro.getTipoEntidadId() > 0)
      criteria.add(Restrictions.eq("tipoEntidadId", filtro.getTipoEntidadId()));
    if (filtro.getEntidadId() != null && filtro.getEntidadId() > 0)
      criteria.add(Restrictions.eq("entidadId", filtro.getEntidadId()));
    if (filtro.getMonedaId() != null && filtro.getMonedaId() > 0)
      criteria.add(Restrictions.eq("monedaId", filtro.getMonedaId()));
    if (StringUtils.isNotBlank(filtro.getNumeroFormateado()))
      criteria.add(
          Restrictions.like("numeroFormateado", filtro.getNumeroFormateado(), MatchMode.ANYWHERE)
              .ignoreCase());

    if (filtro.isEnCartera())
      criteria.add(Restrictions.eq("tipomovimiento", Constants.TIPODOCUMENTO_VALORTERCE_INGRESO));
    if (filtro.isDepositados())
      criteria.add(Restrictions.eq("tipomovimiento", Constants.TIPODOCUMENTO_VALORTERCE_EGRESO));

    if (filtro.getImporteDesde() != null && filtro.getImporteHasta() != null) {
      criteria.add(
          Restrictions.between("importeValor", filtro.getImporteDesde(), filtro.getImporteHasta()));
    } else if (filtro.getImporteDesde() != null) {
      criteria.add(Restrictions.ge("importeValor", filtro.getImporteDesde()));
    } else if (filtro.getImporteHasta() != null) {
      criteria.add(Restrictions.le("importeValor", filtro.getImporteHasta()));
    }
    if (StringUtils.isNotBlank(filtro.getFechaVencimientoDesde()))
      criteria.add(
          Restrictions.ge(
              "fechaVencimiento", DateUtil.convertStringToDate(filtro.getFechaVencimientoDesde())));
    if (StringUtils.isNotBlank(filtro.getFechaVencimientoHasta()))
      criteria.add(
          Restrictions.le(
              "fechaVencimiento", DateUtil.convertStringToDate(filtro.getFechaVencimientoHasta())));

    /* Agrega el orden */
    setOrderBy(criteria, campoOrder, orderByAsc);

    List<ValorTercero_v> list = criteria.list();

    return list;
  }
Exemplo n.º 4
0
  @Override
  public List<Log> list(ListLogRequest logParam, int pageIndex, int pageSize) {

    DetachedCriteria criteria = DetachedCriteria.forClass(Log.class);

    // TODO 添加大小不敏感
    if (StringUtils.isNotBlank(logParam.getLoginName())) {
      criteria.add(Restrictions.like("loginName", "%" + logParam.getLoginName() + "%"));
    }

    if (logParam.getOperationUsers() != null && logParam.getOperationUsers().length > 0) {
      criteria.add(Restrictions.in("loginName", logParam.getOperationUsers()));
    }
    if (StringUtils.isNotBlank(logParam.getModule())) {
      criteria.add(Restrictions.eq("module", logParam.getModule()));
    }
    if (StringUtils.isNotBlank(logParam.getOperation())) {
      criteria.add(Restrictions.eq("operation", logParam.getOperation()));
    }

    if (logParam.getStartDate() != null) {
      criteria.add(Restrictions.ge("createdOn", logParam.getStartDate()));
    }
    if (logParam.getEndDate() != null) {
      criteria.add(Restrictions.le("createdOn", logParam.getEndDate()));
    }
    criteria.addOrder(Order.desc("createdOn"));

    List result = (List<Log>) findByCriteria(criteria, pageIndex, pageSize);

    return result;
  }
Exemplo n.º 5
0
  @Override
  public int count(ListLogRequest logParam) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Log.class);

    if (StringUtils.isNotBlank(logParam.getLoginName())) {
      criteria.add(Restrictions.eq("loginName", "%" + logParam.getLoginName() + "%"));
    }

    if (logParam.getOperationUsers() != null && logParam.getOperationUsers().length > 0) {
      criteria.add(Restrictions.in("loginName", logParam.getOperationUsers()));
    }

    if (StringUtils.isNotBlank(logParam.getModule())) {
      criteria.add(Restrictions.eq("module", logParam.getModule()));
    }
    if (StringUtils.isNotBlank(logParam.getOperation())) {
      criteria.add(Restrictions.eq("operation", logParam.getOperation()));
    }

    if (logParam.getStartDate() != null) {
      criteria.add(Restrictions.ge("createdOn", logParam.getStartDate()));
    }
    if (logParam.getEndDate() != null) {
      criteria.add(Restrictions.le("createdOn", logParam.getEndDate()));
    }
    return this.countByCriteria(criteria);
  }
Exemplo n.º 6
0
 public BudgetItem getBudgetItem(Date date, Account account) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BudgetItem.class);
   criteria.add(Restrictions.eq("account", account));
   criteria.add(
       Restrictions.and(Restrictions.le("startDate", date), Restrictions.ge("endDate", date)));
   return (BudgetItem) criteria.uniqueResult();
 }
Exemplo n.º 7
0
  /**
   * Tìm kiếm nhanh
   *
   * @param c Tiêu chí tìm kiếm
   * @return Danh sách các điện thoại thỏa tiêu chí tìm kiếm
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(QuickSearchCriteria c) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (c.getIdHangDienThoai() > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", c.getIdHangDienThoai());
      criteria.add(manufacture);
    }

    if (c.getTenDienThoai() != null) {
      Criterion name = Restrictions.like("ten", "%" + c.getTenDienThoai() + "%");
      criteria.add(name);
    }

    if (c.getGiaTu() >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", c.getGiaTu());
      criteria.add(minPrice);
    }

    if (c.getGiaDen() >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", c.getGiaDen());
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
Exemplo n.º 8
0
  public List<Ticket> findTicketsForShift(
      Date startDate, Date endDate, Shift shit, String userType, Terminal terminal) {
    Session session = null;
    try {
      session = getSession();
      Criteria criteria = session.createCriteria(getReferenceClass());
      criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, startDate));
      criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, endDate));
      criteria.add(Restrictions.eq(Ticket.PROP_SHIFT, shit));
      criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE));
      criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));

      if (userType != null) {
        criteria.createAlias(Ticket.PROP_OWNER, "u");
        criteria.add(Restrictions.eq("u.type", userType));
      }
      if (terminal != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));
      }

      return criteria.list();
    } finally {
      closeSession(session);
    }
  }
Exemplo n.º 9
0
 @SuppressWarnings("unchecked")
 @Override
 public List<Sales> getPendingSalesBetween(Date startDate, Date endDate) throws Exception {
   Session session = HibernateUtil.startSession();
   Criteria criteria = session.createCriteria(Sales.class);
   criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
   List<Sales> sales = new ArrayList<Sales>();
   try {
     Date lowerBound = DateTool.getTomorrowDate(DateTool.getDateWithoutTime(startDate));
     Date upperBound = DateTool.getDateWithoutTime(endDate);
     sales =
         criteria
             .add(Restrictions.ge("date", lowerBound))
             .add(Restrictions.lt("date", upperBound))
             .add(Restrictions.eq("valid", true))
             .add(Restrictions.isNull("inventorySheetData"))
             .addOrder(Order.desc("date"))
             .list();
   } catch (HibernateException ex) {
     ex.printStackTrace();
   } finally {
     session.close();
   }
   return sales;
 }
Exemplo n.º 10
0
  public ArrayList<Election> getElectionByConstituency(Long constituency) {
    Session session = null;

    ArrayList<Election> eleclist = new ArrayList<Election>();
    Criteria ctr, tempctr;
    try {
      session = getSessionFactory().openSession();
      ctr = session.createCriteria(Locations.class);
      ctr.add(Restrictions.eq("constituency", constituency));
      for (int i = 0; ctr.list().size() > 0 && i < ctr.list().size(); i++) {
        tempctr = session.createCriteria(Election.class);
        tempctr.add(Restrictions.eq("validity", Election.NOTDONE));
        tempctr.add(Restrictions.idEq(((Locations) ctr.list().get(i)).getElecid()));
        tempctr.add(Restrictions.le("start", new Timestamp(new Date().getTime())));
        tempctr.add(Restrictions.ge("end", new Timestamp(new Date().getTime())));
        if (tempctr.list().size() > 0) eleclist.add((Election) tempctr.list().get(0));
      }

    } catch (HibernateException e) {
      System.err.println("Error: file: LocationsDAO method: getNumOfCOnsti()");
    } finally {
      if (session != null) session.close();
    }

    return eleclist;
  }
Exemplo n.º 11
0
  public List<Ticket> findTicketsForLaborHour(
      Date startDate, Date endDate, int hour, String userType, Terminal terminal) {
    Session session = null;
    try {
      session = getSession();
      Criteria criteria = session.createCriteria(getReferenceClass());
      criteria.add(Restrictions.ge(Ticket.PROP_ACTIVE_DATE, startDate));
      criteria.add(Restrictions.le(Ticket.PROP_ACTIVE_DATE, endDate));
      criteria.add(Restrictions.eq(Ticket.PROP_CREATION_HOUR, Integer.valueOf(hour)));
      // criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE));
      // criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));

      if (userType != null) {
        criteria.createAlias(Ticket.PROP_OWNER, "u");
        criteria.add(Restrictions.eq("u.type", userType));
      }
      if (terminal != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));
      }

      return criteria.list();
    } finally {
      closeSession(session);
    }
  }
Exemplo n.º 12
0
  /** 按属性条件参数创建Criterion,辅助函数. */
  protected Criterion buildCriterion(
      final String propertyName, final Object propertyValue, final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName不能为空");
    Criterion criterion = null;
    // 根据MatchType构造criterion
    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;
  }
Exemplo n.º 13
0
  @Override
  public String input() throws Exception {
    this.sysUser = service.getUser(userid);
    set("sysUser", sysUser);

    // 也显示全国律协的以及系统层级的

    System.out.println("===================" + sysUser.getCityid());
    this.datavisible.setProvinceid(sysUser.getProvinceid());
    this.datavisible.setCityid(sysUser.getCityid());
    this.datavisible.setOfficeid(sysUser.getOfficeid());

    this.datavisible.getVisibleDatas(this.getLoginUser(), true);

    SysRole sysrole = this.getLoginUser().getSysRole();
    if (sysrole != null) {
      BasicService bs = (BasicService) this.getBean("basicService");
      DetachedCriteria dc = DetachedCriteria.forClass(SysRole.class);
      Criterion c1 = null;
      if (sysrole.getCansamegrade()) c1 = Restrictions.ge("gradeid", sysrole.getGradeid());
      else c1 = Restrictions.gt("gradeid", sysrole.getGradeid());
      Criterion c2 = Restrictions.eq("roleid", sysrole.getRoleid());
      dc.add(Restrictions.or(c1, c2));
      allroles = bs.findAllByCriteria(dc);

    } else { // 没角色的话,显示所有的角色
      SysRoleService roleService = (SysRoleService) this.getBean("sysRoleService");
      allroles = roleService.getRoles();
    }

    return INPUT;
  }
  @Override
  public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(AccountCreditNote.class);

    if (isNotEmpty(filterModel.getSerial())) {
      crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getReference())) {
      crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
      crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
      crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
      crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getAccount() != null) {
      crit.add(Restrictions.le("this.account", filterModel.getAccount()));
    }

    crit.addOrder(Order.desc("serial"));
    crit.addOrder(Order.desc("date"));

    return crit;
  }
Exemplo n.º 15
0
  @Override
  public List<Notice> list(String status, LocalDate fromDate, LocalDate toDate, String dongName)
      throws OperationalException {

    try {

      List<Criterion> criteriaList = new ArrayList<>();

      if (!StringUtils.isBlank(status) && !status.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq(STATUS, status));
      }
      if (!StringUtils.isBlank(dongName) && !dongName.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq("dongName", dongName));
      }
      if (fromDate != null) {
        LocalTime time = LocalTime.MIDNIGHT;
        LocalDateTime fromtime = LocalDateTime.of(fromDate, time);
        criteriaList.add(Restrictions.ge(CREATIONDATE, fromtime));
      }
      if (toDate != null) {
        LocalTime time = LocalTime.of(23, 59, 59);
        LocalDateTime totime = LocalDateTime.of(toDate, time);
        criteriaList.add(Restrictions.le(CREATIONDATE, totime));
      }
      criteriaList.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      return super.findByCriteria(Notice.class, criteriaList, Order.desc(CREATIONDATE));

    } catch (Exception e) {
      LOGGER.error("list: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
Exemplo n.º 16
0
 // TODO add fromData-toDate
 public IncomeBalance findAccountPeriod(Account account, Date date) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(IncomeBalance.class);
   criteria.add(Restrictions.eq("account", account));
   criteria.add(
       Restrictions.and(Restrictions.ge("startDate", date), Restrictions.le("endDate", date)));
   return (IncomeBalance) criteria.uniqueResult();
 }
  @Override
  @SuppressWarnings("unchecked")
  public List<ProgramInstance> get(
      Program program,
      Collection<Integer> orgunitIds,
      Date startDate,
      Date endDate,
      Integer min,
      Integer max) {
    Criteria criteria =
        getCriteria(
                Restrictions.eq("program", program),
                Restrictions.ge("enrollmentDate", startDate),
                Restrictions.le("enrollmentDate", endDate))
            .createAlias("entityInstance", "entityInstance")
            .createAlias("entityInstance.organisationUnit", "organisationUnit")
            .add(Restrictions.in("organisationUnit.id", orgunitIds))
            .addOrder(Order.asc("entityInstance.id"));

    if (min != null) {
      criteria.setFirstResult(min);
    }

    if (max != null) {
      criteria.setMaxResults(max);
    }

    return criteria.list();
  }
Exemplo n.º 18
0
  /**
   * Tìm kiếm nhanh
   *
   * @param idHangDienThoai id của HangDienThoai.
   * @param ten tên DienThoai.
   * @param giaTu giá chặn dưới.
   * @param giaDen giá chặn trên.
   * @return Danh sách DienThoai thỏa tiêu chí tìm kiếm.
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(int idHangDienThoai, String ten, double giaTu, double giaDen) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (idHangDienThoai > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", idHangDienThoai);
      criteria.add(manufacture);
    }

    if (ten != null) {
      Criterion name = Restrictions.like("ten", "%" + ten + "%");
      criteria.add(name);
    }

    if (giaTu >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", giaTu);
      criteria.add(minPrice);
    }

    if (giaDen >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", giaDen);
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
Exemplo n.º 19
0
  @SuppressWarnings("unchecked")
  public List<Pedido> filtrados(PedidoFilter filtro) {
    Session session = this.manager.unwrap(Session.class);

    Criteria criteria =
        session
            .createCriteria(Pedido.class)
            // fazemos uma associação (join) com cliente e nomeamos como "c"
            .createAlias("cliente", "c")
            // fazemos uma associação (join) com vendedor e nomeamos como "v"
            .createAlias("vendedor", "v");

    if (filtro.getNumeroDe() != null) {
      // id deve ser maior ou igual (ge = greater or equals) a filtro.numeroDe
      criteria.add(Restrictions.ge("id", filtro.getNumeroDe()));
    }

    if (filtro.getNumeroAte() != null) {
      // id deve ser menor ou igual (le = lower or equal) a filtro.numeroDe
      criteria.add(Restrictions.le("id", filtro.getNumeroAte()));
    }

    if (filtro.getDataCriacaoDe() != null) {
      criteria.add(Restrictions.ge("dataCriacao", filtro.getDataCriacaoDe()));
    }

    if (filtro.getDataCriacaoAte() != null) {
      criteria.add(Restrictions.le("dataCriacao", filtro.getDataCriacaoAte()));
    }

    if (!filtro.getNomeCliente().equals("")) {
      // acessamos o nome do cliente associado ao pedido pelo alias "c", criado anteriormente
      criteria.add(Restrictions.ilike("c.nome", filtro.getNomeCliente(), MatchMode.ANYWHERE));
    }

    if (!filtro.getNomeVendedor().equals("")) {
      // acessamos o nome do vendedor associado ao pedido pelo alias "v", criado anteriormente
      criteria.add(Restrictions.ilike("v.nome", filtro.getNomeVendedor(), MatchMode.ANYWHERE));
    }

    if (filtro.getStatuses() != null && filtro.getStatuses().length > 0) {
      // adicionamos uma restrição "in", passando um array de constantes da enum StatusPedido
      criteria.add(Restrictions.in("status", filtro.getStatuses()));
    }

    return criteria.addOrder(Order.asc("id")).list();
  }
Exemplo n.º 20
0
  @SuppressWarnings("rawtypes")
  public List<Criterion> restrict(Object[]... values) {

    List<Criterion> criterions = new ArrayList<Criterion>();
    switch (valueOf(type)) {
      case IN:
        for (Object[] value : values)
          criterions.add(Restrictions.in((String) value[0], (Collection) value[1]));

        break;
      case NOTIN:
        for (Object[] value : values)
          criterions.add(
              Restrictions.not(Restrictions.in((String) value[0], (Collection) value[1])));
        break;
      case EQ:
        for (Object[] value : values) criterions.add(Restrictions.eq((String) value[0], value[1]));
        break;
      case NOTEQ:
        for (Object[] value : values) criterions.add(Restrictions.ne((String) value[0], value[1]));
        break;
      case GE:
        for (Object[] value : values) criterions.add(Restrictions.ge((String) value[0], value[1]));
        break;
      case LE:
        for (Object[] value : values) criterions.add(Restrictions.le((String) value[0], value[1]));
        break;
      case BETWEEN:
        for (Object[] value : values)
          criterions.add(Restrictions.between((String) value[0], value[1], value[2]));
        break;
      case GT:
        for (Object[] value : values) criterions.add(Restrictions.gt((String) value[0], value[1]));
        break;
      case LT:
        for (Object[] value : values) criterions.add(Restrictions.lt((String) value[0], value[1]));
        break;
      case AND:
        for (Object[] value : values)
          criterions.add(Restrictions.and((Criterion) value[0], (Criterion) value[1]));
        break;
      case OR:
        for (Object[] value : values)
          criterions.add(Restrictions.or((Criterion) value[0], (Criterion) value[1]));
        break;
      case NULL:
        for (Object[] value : values) criterions.add(Restrictions.isNull((String) value[0]));
        break;
      case NOTNULL:
        for (Object[] value : values) criterions.add(Restrictions.isNotNull((String) value[0]));
        break;
      case LIKE:
        for (Object[] value : values)
          criterions.add(Restrictions.like((String) value[0], value[1]));
        break;
    }
    return criterions;
  }
Exemplo n.º 21
0
 /**
  * 设置ge(>=)查询条件
  *
  * @param keyname
  * @param keyvalue1
  * @param keyvalue2
  */
 public void ge(String keyname, Object keyvalue) {
   if (keyvalue != null && keyvalue != "") {
     criterionList.addPara(Restrictions.ge(keyname, keyvalue));
     if (flag) {
       this.put(keyname, keyvalue);
     }
     flag = true;
   }
 }
Exemplo n.º 22
0
 @Override
 public List<Orders> getOrdersByPeriodDate(Date date1, Date date2) {
   return sessionFactory
       .getCurrentSession()
       .createCriteria(Orders.class)
       .add(Restrictions.ge("date", date1))
       .add(Restrictions.lt("date", date2))
       .list();
 }
 @SuppressWarnings("unchecked")
 public List<AssignableDay> getByGroupPeriod(Group group, LocalDate startDate, LocalDate endDate) {
   return currentSession()
       .createCriteria(AssignableDay.class)
       .add(Restrictions.eq("group.id", group.getId()))
       .add(Restrictions.ge("date", startDate))
       .add(Restrictions.le("date", endDate))
       .list();
 }
 @Override
 @SuppressWarnings("unchecked")
 public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated(
     boolean active, Date lastUpdated) {
   return getCriteria()
       .add(Restrictions.ge("lastUpdated", lastUpdated))
       .add(Restrictions.eq("active", active))
       .list();
 }
Exemplo n.º 25
0
 private Criteria getGamesCriteria(Session session, Long clientId, Long userId) {
   Criteria criteria = session.createCriteria(SavedGame.class);
   criteria.addOrder(Order.desc("stop"));
   criteria.add(Restrictions.ge("start", CentralHolder.gamesDateSelector.getStartDate()));
   criteria.add(Restrictions.le("stop", CentralHolder.gamesDateSelector.getEndDate()));
   if (clientId != null) criteria.add(Restrictions.eq("client.id", clientId));
   if (userId != null) criteria.add(Restrictions.eq("user.id", userId));
   return criteria;
 }
Exemplo n.º 26
0
  @Override
  public Condition buildCondition(
      String conditionField, ConditionType conditionType, Iterator argsIterator) {
    Condition condition = new Condition();

    condition.setField(conditionField);

    switch (conditionType) {
      case Between:
        condition.setConstraint(
            Restrictions.between(conditionField, argsIterator.next(), argsIterator.next()));
        break;

      case Equal:
        condition.setConstraint(Restrictions.eq(conditionField, argsIterator.next()));
        break;

      case GreaterThan:
        condition.setConstraint(Restrictions.gt(conditionField, argsIterator.next()));
        break;

      case GreaterThanEqual:
        condition.setConstraint(Restrictions.ge(conditionField, argsIterator.next()));
        break;

      case IsNotNull:
        condition.setConstraint(Restrictions.isNotNull(conditionField));
        break;

      case IsNull:
        condition.setConstraint(Restrictions.isNull(conditionField));
        break;

      case LessThan:
        condition.setConstraint(Restrictions.lt(conditionField, argsIterator.next()));
        break;

      case LessThanEqual:
        condition.setConstraint(Restrictions.le(conditionField, argsIterator.next()));
        break;

      case NotEqual:
        condition.setConstraint(Restrictions.ne(conditionField, argsIterator.next()));
        break;

      case NotWithin:
        condition.setConstraint(
            Restrictions.not(Restrictions.in(conditionField, (Collection) argsIterator.next())));
        break;

      case Within:
        condition.setConstraint(Restrictions.in(conditionField, (Collection) argsIterator.next()));
        break;
    }

    return condition;
  }
Exemplo n.º 27
0
 public List<Alquiler> getAlquileresSocioEntreFechas(
     Socio socio, Date fechaInicial, Date fechaFin) {
   Session session = HibernateUtils.getSession();
   Criteria criteria = session.createCriteria(Alquiler.class);
   criteria.add(Restrictions.ge("fechaAlquiler", fechaInicial));
   if (fechaFin != null) {
     criteria.add(Restrictions.le("fechaAlquiler", fechaFin));
   }
   return criteria.list();
 }
  @Override
  @SuppressWarnings("unchecked")
  public Collection<OrganisationUnit> getBetweenByLastUpdated(
      Date lastUpdated, int first, int max) {
    Criteria criteria = getCriteria().add(Restrictions.ge("lastUpdated", lastUpdated));
    criteria.setFirstResult(first);
    criteria.setMaxResults(max);

    return criteria.list();
  }
Exemplo n.º 29
0
 /**
  * Determina la categoria a la cual pertenece la edad suministrada
  *
  * @param edad edad del jugador
  * @return Categoria que contiene la edad suministrada, en caso de no existir se retorna null
  */
 public Categoria buscarPorEdad(int edad) {
   Session session = this.getSession();
   org.hibernate.Transaction tx = session.beginTransaction();
   Criteria c =
       session
           .createCriteria(Categoria.class)
           .add(Restrictions.le("edadInferior", edad))
           .add(Restrictions.ge("edadSuperior", edad))
           .add(Restrictions.eq("estatus", 'A'));
   return (Categoria) c.uniqueResult();
 }
Exemplo n.º 30
0
  /**
   * 设置between(之间)查询条件
   *
   * @param keyname
   * @param keyvalue1
   * @param keyvalue2
   */
  public void between(String keyname, Object keyvalue1, Object keyvalue2) {
    Criterion c = null; // 写入between查询条件

    if (!keyvalue1.equals(null) && !keyvalue2.equals(null)) {
      c = Restrictions.between(keyname, keyvalue1, keyvalue2);
    } else if (!keyvalue1.equals(null)) {
      c = Restrictions.ge(keyname, keyvalue1);
    } else if (!keyvalue2.equals(null)) {
      c = Restrictions.le(keyname, keyvalue2);
    }
    criterionList.add(c);
  }