@Override
 @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
 public List<VisitingSolts> getAllActiveVisitingSlotsExpired() throws Exception {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(VisitingSolts.class);
   criteria.add(
       Restrictions.conjunction()
           .add(Restrictions.lt("endTime", Calendar.getInstance().getTime()))
           .add(Restrictions.lt("activeStatus", ActiveStatus.ACTIVE)));
   return criteria.list();
 }
  private Criteria buildCondition(Retirement r, String ks, String js, String eq, String type) {
    Criteria c = getSession().createCriteria(Retirement.class);
    if (r != null) {
      if (r.getSfsc() != null && r.getSfsc().length() > 0)
        c.add(Restrictions.eq("sfsc", r.getSfsc()));
      else c.add(Restrictions.eq("sfsc", Constants.HASNO));
      if (r.getSfzh() != null && r.getSfzh().length() > 0)
        c.add(Restrictions.eq("sfzh", r.getSfzh()));
      if (r.getXm() != null && r.getXm().length() > 0)
        c.add(Restrictions.like("xm", r.getXm(), MatchMode.ANYWHERE));
      if (r.getGzzh() != null && r.getGzzh().length() > 0)
        c.add(Restrictions.eq("gzzh", r.getGzzh()));
      if (r.getXb() != null && r.getXb().length() > 0) c.add(Restrictions.eq("xb", r.getXb()));
      if (r.getDwb() != null && r.getDwb().getId() != null)
        c.add(Restrictions.eq("dwb", r.getDwb()));
      if (r.getLxb() != null && r.getLxb().getId() != null)
        c.add(Restrictions.eq("lxb", r.getLxb()));
      if (r.getZjb() != null && r.getZjb().getId() != null)
        c.add(Restrictions.eq("zjb", r.getZjb()));
      if (r.getZwb() != null && r.getZwb().getId() != null)
        c.add(Restrictions.eq("zwb", r.getZwb()));
      if (r.getMzb() != null && r.getMzb().getId() != null)
        c.add(Restrictions.eq("mzb", r.getMzb()));
      if (r.getZzmm() != null && r.getZzmm().getId() != null)
        c.add(Restrictions.eq("zzmm", r.getZzmm()));
      if (r.getJg() != null && r.getJg().length() > 0) c.add(Restrictions.eq("jg", r.getJg()));

      if (r.getCsrq() != null && r.getCsrq().length() > 0)
        c.add(Restrictions.eq("csrq", r.getCsrq())); // 类型为空表是查出生日期,不为空是查是否为党员

      if (StringUtils.isNotEmpty(ks) || StringUtils.isNotBlank(js)) {
        if (StringUtils.isNotEmpty(ks) && StringUtils.isNotBlank(js)) {
          c.add(Restrictions.and(Restrictions.gt("csrq", js), Restrictions.lt("csrq", ks)));
        }
        if (StringUtils.isNotEmpty(ks)) {
          c.add(Restrictions.lt("csrq", ks));
        }
        if (StringUtils.isNotEmpty(js)) {
          c.add(Restrictions.gt("csrq", js));
        }
      }
      if (StringUtils.isNotBlank(eq)) {
        c.add(Restrictions.like("csrq", "%" + eq + "%"));
      }

      if (r.getParty() != null && r.getParty().getId() != null)
        c.add(Restrictions.eq("party", r.getParty()));
    }
    c.addOrder(Order.asc("sfzh")).addOrder(Order.desc("csrq"));
    return c;
  }
Exemplo n.º 3
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.º 4
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.º 5
0
 /*
  *  check budgetitem start date and end date overlap
  *
  */
 public boolean isBudgetItemOverlap(Account account, Date startDate, Date endDate) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BudgetItem.class);
   criteria.add(Restrictions.eq("account", account));
   criteria.add(
       Restrictions.and(
           Restrictions.lt("startDate", endDate), Restrictions.gt("endDate", startDate)));
   return criteria.list().isEmpty() ? false : true;
 }
Exemplo n.º 6
0
 /**
  * Check if given date range is overlap with existing fiscal years (StartA <= EndB) and (EndA >=
  * StartB)
  *
  * @param from
  * @param to
  * @return
  */
 @SuppressWarnings("unchecked")
 public List<FiscalYear> getOverlapFiscalYears(Integer fiscalYearId, Date from, Date to) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(FiscalYear.class);
   criteria.add(
       Restrictions.and(Restrictions.lt("startDate", to), Restrictions.gt("endDate", from)));
   criteria.add(Restrictions.ne("status", GeneralStatus.DELETED));
   return criteria.list();
 }
Exemplo n.º 7
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.º 8
0
 /**
  * 设置lt(<)查询条件
  *
  * @param keyname
  * @param keyvalue1
  * @param keyvalue2
  */
 public void lt(String keyname, Object keyvalue) {
   if (keyvalue != null && keyvalue != "") {
     criterionList.addPara(Restrictions.lt(keyname, keyvalue));
     if (flag) {
       this.put(keyname, keyvalue);
     }
     flag = true;
   }
 }
Exemplo n.º 9
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.º 10
0
 public <T> List<T> listFired(final Function<? super Timer, T> transform)
     throws SwfMetadataException {
   return listByExample(
       Timer.exampleWithOwner(null),
       Predicates.alwaysTrue(),
       Restrictions.lt("timeoutTimestamp", new Date()),
       Collections.<String, String>emptyMap(),
       transform);
 }
Exemplo n.º 11
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();
 }
 public MyQuery getAllOutStateSreach() {
   DetachedCriteria dc = DetachedCriteria.forClass(CheckworkAbsence.class);
   String date = TimeUtil.getTheTimeStr(TimeUtil.getNowTime());
   dc.add(Restrictions.gt("endTime", TimeUtil.getTimeByStr(date, "yyyy-MM-dd HH:mm:ss")));
   dc.add(Restrictions.lt("beginTime", TimeUtil.getTimeByStr(date, "yyyy-MM-dd HH:mm:ss")));
   dc.addOrder(Order.desc("signDate"));
   MyQuery myQuery = new MyQueryImpl();
   myQuery.setDetachedCriteria(dc);
   return myQuery;
 }
  public String execute() {
    int to = rows * page;
    int from = to - rows;
    DetachedCriteria criteria = DetachedCriteria.forClass(Cliente.class);

    // Si el campo de busqueda es diferente de nulo
    if (searchField != null) {
      if (searchField.equals("idcliente")) {
        if (searchOper.equals("eq")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.eq("idcliente", searchValue));
        } else if (searchOper.equals("lt")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.lt("idcliente", searchValue));

        } else if (searchOper.equals("gt")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.gt("idcliente", searchValue));
        }
      } else if (searchField.equals("nombre")) {
        // contains
        if (searchOper.equals("cn")) {
          criteria.add(Restrictions.like("nombre", "%" + searchString + "%"));
        }
      } else if (searchField.equals("banco.nombre")) {
        criteria.createAlias("banco", "b");
        if (searchOper.equals("eq")) {
          criteria.add(Restrictions.eq("b.nombre", searchString));
        }
      }
    }

    // Count Customers
    records = clienteService.countByCriteria(criteria);

    // Reset count Projection
    criteria.setProjection(null);
    criteria.setResultTransformer(Criteria.ROOT_ENTITY);

    if (sidx != null && !sidx.equals("")) {
      if (sord.equals("asc")) {
        criteria.addOrder(Order.asc(sidx));
      } else {
        criteria.addOrder(Order.desc(sidx));
      }
    }

    gridModel = clienteService.findByCriteria(criteria, from, rows);

    if (to > records) to = records;

    total = (int) Math.ceil((double) records / (double) rows);

    return "success";
  }
Exemplo n.º 14
0
 @SuppressWarnings("unchecked")
 public List<IncomeReceiptItem> getListIncomeReceiptItemByDate(String startDate, String endDate) {
   Date dStartDate = DateUtils.getDateFromStr(startDate);
   Date dEndDate = DateUtils.getDateFromStr(endDate);
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(IncomeReceiptItem.class);
   criteria.add(
       Restrictions.and(
           Restrictions.le("receiptDate", dStartDate),
           Restrictions.lt("receiptDate", DateUtils.addDate(dEndDate, 1))));
   return criteria.list();
 }
Exemplo n.º 15
0
 @SuppressWarnings("unchecked")
 public List<Prenotazione> getStanzeOccupate(long start, long end) {
   // definisci un nuovo criterio
   Criteria criteria = createCriteria();
   // criteria.add(Restrictions.lt("to",  new Date(start)));
   criteria.add(
       Restrictions.and(
           Restrictions.gt("to", new Date(start)), Restrictions.lt("from", new Date(end))));
   // criteria.add(Restrictions.gt("from", new Date(end)));
   return criteria.list();
 }
Exemplo n.º 16
0
  /** See Interface for functional description. */
  @Override
  public List<StagingFile> findExpiredStagingFiles() throws SqlDatabaseSystemException {

    try {
      final DetachedCriteria criteria = DetachedCriteria.forClass(StagingFile.class);
      criteria.add(Restrictions.lt("expiryTs", System.currentTimeMillis()));
      return getHibernateTemplate().findByCriteria(criteria);
    } catch (final DataAccessException e) {
      throw new SqlDatabaseSystemException(e);
    }
  }
Exemplo n.º 17
0
 @SuppressWarnings("unchecked")
 @Override
 public List<Notice> findOldestOrderByTime(
     String name, Object value, int endid, int offset, boolean joinInfo) {
   Criteria criteria = getCurrentSession().createCriteria(persistentClass);
   setFetchMode(criteria, joinInfo);
   criteria.add(Restrictions.eq(name, value));
   criteria.add(Restrictions.lt("id", endid));
   criteria.setMaxResults(offset);
   setOrderBy(criteria, ADDTIME, true);
   return criteria.list();
 }
Exemplo n.º 18
0
 @Override
 public int countVisitRecord(String userName, Timestamp begin, Timestamp end) {
   Session session = getSession();
   Criteria criteria = session.createCriteria(VisitRecord.class);
   if (StringUtils.isNotBlank(userName)) {
     criteria.add(Restrictions.eq("userName", userName));
   }
   criteria.add(Restrictions.ge("recordTime", begin));
   criteria.add(Restrictions.lt("recordTime", end));
   criteria.setProjection(Projections.rowCount());
   Number n = (Number) criteria.uniqueResult();
   return n.intValue();
 }
  /**
   * See Interface for functional description.
   *
   * @see UserAccountDaoInterface #retrieveExpiredUserLoginData(long)
   */
  @Override
  @SuppressWarnings("unchecked")
  public List<UserLoginData> retrieveExpiredUserLoginData(final long timestamp)
      throws SqlDatabaseSystemException {

    final DetachedCriteria criteria = DetachedCriteria.forClass(UserLoginData.class);
    criteria.add(Restrictions.lt("expiryts", timestamp));
    try {
      return getHibernateTemplate().findByCriteria(criteria);
    } catch (final DataAccessException e) {
      throw new SqlDatabaseSystemException(e);
    }
  }
Exemplo n.º 20
0
 static void addFilterOnPrefixedDate(Criteria crit, String op, Date date, String dateAttribute) {
   if (op.startsWith("=")) {
     crit.add(Restrictions.eq(dateAttribute, date));
   } else if (op.startsWith("<=")) {
     crit.add(Restrictions.le(dateAttribute, date));
   } else if (op.startsWith(">=")) {
     crit.add(Restrictions.ge(dateAttribute, date));
   } else if (op.startsWith("<")) {
     crit.add(Restrictions.lt(dateAttribute, date));
   } else if (op.startsWith(">")) {
     crit.add(Restrictions.gt(dateAttribute, date));
   }
 }
Exemplo n.º 21
0
 @Override
 public List<VisitRecord> listVisitRecord(
     String userName, Timestamp begin, Timestamp end, int start, int limit) {
   Session session = getSession();
   Criteria criteria = session.createCriteria(VisitRecord.class);
   if (StringUtils.isNotBlank(userName)) {
     criteria.add(Restrictions.eq("userName", userName));
   }
   criteria.add(Restrictions.ge("recordTime", begin));
   criteria.add(Restrictions.lt("recordTime", end));
   criteria.addOrder(Order.desc("recordTime"));
   criteria.setFirstResult(start);
   criteria.setMaxResults(limit);
   return criteria.list();
 }
Exemplo n.º 22
0
  @SuppressWarnings("unchecked")
  public List<IncomeReceipt> getListIncomeReceiptByDate(
      String startDate, String endDate, boolean includeVoided) {
    Date dStartDate = DateUtils.getDateFromStr(startDate);
    Date dEndDate = DateUtils.getDateFromStr(endDate);

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(IncomeReceipt.class);

    criteria.add(
        Restrictions.and(
            Restrictions.ge("receiptDate", dStartDate),
            Restrictions.lt("receiptDate", DateUtils.addDate(dEndDate, 1))));

    if (!includeVoided) criteria.add(Restrictions.eq("voided", false));

    return criteria.list();
  }
Exemplo n.º 23
0
  @SuppressWarnings("unchecked")
  public List<Reveal> find(Map<Pair<String, Condition>, Object> map) {
    List<Reveal> reveals = null;
    Transaction tx = null;
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {
      tx = session.getTransaction();
      Criteria c = session.createCriteria(Reveal.class);
      c.add(Restrictions.eq("old", false));

      for (Pair<String, Condition> key : map.keySet()) {
        String field = key.getFirst();
        Condition condition = key.getSecond();
        Object value = map.get(key);

        switch (condition) {
          case LIKE:
            if (value instanceof String) c.add(Restrictions.ilike(field, value));
            else c.add(Restrictions.eq(field, value));
            break;
          case NOT_LIKE:
            if (value instanceof String) c.add(Restrictions.not(Restrictions.ilike(field, value)));
            else c.add(Restrictions.ne(field, value));
            break;
          case GREATER_THAN:
            c.add(Restrictions.gt(field, value));
            break;
          case LOWER_THAN:
            c.add(Restrictions.lt(field, value));
            break;
        }
      }

      c.addOrder(Order.desc("time"));
      c.setMaxResults(100);
      reveals = (List<Reveal>) c.list();
    } catch (HibernateException e) {
      e.printStackTrace();
      if (tx != null && tx.isActive()) tx.rollback();
    }
    return reveals;
  }
Exemplo n.º 24
0
  /**
   * Criteria 查询方式
   *
   * @param name
   * @return
   */
  public static List<User> criteriaQuery(String name) {
    Session session = null;
    try {

      session = HibernateXmlCfgContext.getSession();

      Criteria criteria = session.createCriteria(User.class);
      criteria.add(Restrictions.eq("name", name));
      criteria.add(Restrictions.lt("birthday", new Date())); // 可以加上多个约束条件

      //			hibernate 分页
      criteria.setFirstResult(0);
      criteria.setMaxResults(10);

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

      return list;
    } finally {
      if (session != null) session.close();
    }
  }
Exemplo n.º 25
0
  protected Criterion buildPropertyFilterCriterion(
      final String propertyName, final Object propertyValue, final MatchType matchType) {
    Criterion criterion = null;
    try {

      if (MatchType.EQ.equals(matchType)) {
        criterion = Restrictions.eq(propertyName, propertyValue);
      } else if (MatchType.LIKE.equals(matchType)) {
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
      } else if (MatchType.LE.equals(matchType)) {
        criterion = Restrictions.le(propertyName, propertyValue);
      } else if (MatchType.LT.equals(matchType)) {
        criterion = Restrictions.lt(propertyName, propertyValue);
      } else if (MatchType.GE.equals(matchType)) {
        criterion = Restrictions.ge(propertyName, propertyValue);
      } else if (MatchType.GT.equals(matchType)) {
        criterion = Restrictions.gt(propertyName, propertyValue);
      }
    } catch (Exception e) {
      throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
  }
Exemplo n.º 26
0
  public ActionForward agregarPermisoUsuario(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    System.out.println("Agregar permiso usuario");
    String dia, rutPersona, horaInicial, horaFinal, minutoInicial, minutoFinal;
    int oficina, permiso;
    DynaActionForm dynamic = (DynaActionForm) form;

    rutPersona = dynamic.getString("rutPersona");
    dia = dynamic.getString("diaIngreso");

    horaInicial = dynamic.getString("horaInicial");
    minutoInicial = dynamic.getString("minutoInicial");

    horaFinal = dynamic.getString("horaFinal");
    minutoFinal = dynamic.getString("minutoFinal");

    permiso = (Integer) dynamic.get("idPermiso");
    oficina = (Integer) dynamic.get("idOficina");

    if (Integer.parseInt(horaInicial) > Integer.parseInt(horaFinal)) {

      ActionErrors errors = new ActionErrors();
      errors.add("errorHoras", new ActionMessage("error.horas.asignar"));
      saveErrors(request, errors);
      return mapping.findForward("FailureValidate");
    }

    MuniPersonasDAO muniPersonaDAO = new MuniPersonasDAO();
    if (muniPersonaDAO.findByCriteriaObject(
            MuniPersonas.class, Restrictions.eq("rutPersona", rutPersona))
        == null) {

      ActionErrors errors = new ActionErrors();
      errors.add("errorRut", new ActionMessage("error.rut"));
      saveErrors(request, errors);

      return mapping.findForward("FailureValidate");
    }

    int hora = Integer.parseInt(horaInicial + minutoInicial);
    int hora_2 = Integer.parseInt(horaFinal + minutoFinal);

    MuniReglaIngresoDAO muniReglaIngresoDAO = new MuniReglaIngresoDAO();

    // Veo si la regla se encuentra entre las horas previamente establecidas
    MuniReglaIngreso muniIngreso =
        (MuniReglaIngreso)
            muniReglaIngresoDAO.findByCriteriaObject(
                MuniReglaIngreso.class,
                Restrictions.eq("diaIngreso", dia),
                Restrictions.eq("idOficina", oficina),
                Restrictions.eq("rutPersona", rutPersona),
                Restrictions.lt("horaInicial", hora),
                Restrictions.gt("horaFinal", hora));

    MuniReglaIngreso muniSalida =
        (MuniReglaIngreso)
            muniReglaIngresoDAO.findByCriteriaObject(
                MuniReglaIngreso.class,
                Restrictions.eq("diaIngreso", dia),
                Restrictions.eq("idOficina", oficina),
                Restrictions.eq("rutPersona", rutPersona),
                Restrictions.lt("horaInicial", hora_2),
                Restrictions.gt("horaFinal", hora_2));

    MuniReglaIngreso muni = new MuniReglaIngreso();

    // Compruebo si corresponde al mismo registro, comparando la hora de
    // entrada en ambos registros.
    // if (muniSalida.getHoraInicial() != muniIngreso.getHoraInicial()) {
    // System.out.println("Distinto clase de registro...");
    // } else {

    if (muniIngreso != null && muniSalida != null) {
      // En esta sección se ve si existe entre las horas

      int horaF = muniIngreso.getHoraFinal();

      muniIngreso.setHoraFinal(hora);
      muniReglaIngresoDAO.update(muniIngreso);

      muniIngreso.setHoraInicial(hora);
      muniIngreso.setHoraFinal(hora_2);
      muniReglaIngresoDAO.create(muniIngreso);

      muniIngreso.setHoraInicial(hora_2);
      muniIngreso.setHoraFinal(horaF);
      muniReglaIngresoDAO.create(muniIngreso);
      logger.info("Creada la nueva configuración horaria");
    } else if (muniIngreso != null) {
      muniIngreso.setHoraFinal(hora);
      muniReglaIngresoDAO.update(muniIngreso);

      muniIngreso.setHoraInicial(hora);
      muniIngreso.setHoraFinal(hora_2);
      muniReglaIngresoDAO.create(muniIngreso);

    } else {

      if (muniSalida == null) {

        muniReglaIngresoDAO.deleteByCriteriaObject(
            Restrictions.eq("diaIngreso", dia),
            Restrictions.eq("idOficina", oficina),
            Restrictions.eq("rutPersona", rutPersona),
            Restrictions.lt("horaInicial", hora_2),
            Restrictions.gt("horaFinal", hora));

        muni.setHoraInicial(hora);
        muni.setHoraFinal(hora_2);
        muni.setRutPersona(rutPersona);
        muni.setDiaIngreso(dia);
        muni.setIdOficina(oficina);
        muni.setIdPermiso(permiso);
        muniReglaIngresoDAO.create(muni);
        return mapping.findForward("Success");
      }

      int horaF = muniSalida.getHoraFinal();
      logger.info("Agregado nuevo registro");
      muniReglaIngresoDAO.delete(muniSalida);

      muniSalida.setHoraInicial(hora);
      muniSalida.setHoraFinal(hora_2);
      muniReglaIngresoDAO.update(muniSalida);

      muniSalida.setHoraInicial(hora_2);
      muniSalida.setHoraFinal(horaF);
      muniReglaIngresoDAO.create(muniSalida);
    }
    // }
    return mapping.findForward("Success");
  }
Exemplo n.º 27
0
 /*
  * (non-Javadoc)
  * @see org.exitsoft.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object)
  */
 public Criterion build(String propertyName, Object value) {
   return Restrictions.lt(propertyName, value);
 }
Exemplo n.º 28
0
  public static void main(String[] args) throws SQLException, FileNotFoundException {
    StudentDaoImp dao = new StudentDaoImp();

    // Add some students
    StudentsUtils.createStudents();

    // Hibernate functions
    System.out.println("---------------------------All students-----------------------------");
    Criteria crit = HibernateUtils.getSessionFactory().openSession().createCriteria(Student.class);
    crit.setMaxResults(50);
    List<Student> studs = crit.list();
    printAll(studs);

    System.out.println("----------------------------BETWEEN 18 and 25 -------------------------");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createCriteria(Student.class)
            .add(Restrictions.between("age", 18l, 25l))
            .list();
    printAll(studs);

    System.out.println("--------------------------BEGIN WITH A---------------------------------");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createCriteria(Student.class)
            .add(Restrictions.ilike("name", "a%"))
            .list();
    printAll(studs);

    System.out.println("--------------------------Only 5----------------------------------------");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createCriteria(Student.class)
            .setMaxResults(5)
            .list();
    printAll(studs);

    System.out.println("--------------------------Begin with 'I' or age less than 23");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createCriteria(Student.class)
            .add(
                Restrictions.or(
                    Restrictions.lt("age", Long.valueOf(23)), Restrictions.like("name", "I%")))
            .list();
    printAll(studs);

    System.out.println("--------------------------DESC ORDER BY AGE--------------------------");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createCriteria(Student.class)
            .addOrder(Order.desc("age"))
            .list();
    printAll(studs);

    // -----------------------------------------------------------------------------------------------------------------------

    // SQL
    System.out.println("--------------------------ALL STUDENTS---------------------------------");
    studs =
        HibernateUtils.getSessionFactory()
            .openSession()
            .createSQLQuery("select * from student")
            .addEntity(Student.class)
            .list();
    printAll(studs);

    // Delete all students
    System.out.println("---------------------------DELETE STUDENTS ---------------------------");
    StudentsUtils.deleteStudents();
  }
Exemplo n.º 29
0
 public EntityFilter lt(String name, Object value) {
   criterias.add(Restrictions.lt(name, value));
   return this;
 }
Exemplo n.º 30
0
  protected Criteria buildTaskInstanceExtensionSearchCriteria(
      String taskName,
      String assetType,
      Long[] assetPrimaryKeys,
      Date dueDateGT,
      Date dueDateLT,
      Boolean completed,
      Boolean searchByUserRoles,
      boolean andOperator,
      ServiceContext serviceContext)
      throws SystemException {

    Criteria criteria = _session.createCriteria(TaskInstanceExtensionImpl.class);

    criteria.createAlias("taskInstance", "taskInstance");

    criteria.add(Restrictions.eq("companyId", serviceContext.getCompanyId()));

    if (Validator.isNotNull(taskName)
        || Validator.isNotNull(assetType)
        || (dueDateGT != null)
        || (dueDateLT != null)) {

      Junction junction = null;

      if (andOperator) {
        junction = Restrictions.conjunction();
      } else {
        junction = Restrictions.disjunction();
      }

      if (Validator.isNotNull(taskName)) {
        String[] taskNameKeywords = StringUtil.split(taskName, StringPool.SPACE);

        for (String taskNameKeyword : taskNameKeywords) {
          junction.add(Restrictions.like("taskInstance.name", "%" + taskNameKeyword + "%"));
        }
      }

      if (Validator.isNotNull(assetType)) {
        String[] assetTypeKeywords = StringUtil.split(assetType, StringPool.SPACE);

        for (String assetTypeKeyword : assetTypeKeywords) {
          junction.add(
              Restrictions.like(
                  "workflowContext", "%\"entryType\":\"%" + assetTypeKeyword + "%\"%"));
        }
      }

      if (Validator.isNotNull(assetPrimaryKeys)) {
        for (Long assetPrimaryKey : assetPrimaryKeys) {
          junction.add(
              Restrictions.like(
                  "workflowContext", "%\"entryClassPK\":\"%" + assetPrimaryKey + "%\"%"));
        }
      }

      if (dueDateGT != null) {
        junction.add(Restrictions.ge("taskInstance.dueDate", dueDateGT));
      }

      if (dueDateLT != null) {
        junction.add(Restrictions.lt("taskInstance.dueDate", dueDateGT));
      }

      criteria.add(junction);
    }

    addSearchByUserRolesCriterion(criteria, searchByUserRoles, serviceContext);

    if (completed != null) {
      if (completed.booleanValue()) {
        criteria.add(Restrictions.isNotNull("taskInstance.end"));
      } else {
        criteria.add(Restrictions.isNull("taskInstance.end"));
      }
    }

    return criteria;
  }