Example usage for org.hibernate.criterion Restrictions between

List of usage examples for org.hibernate.criterion Restrictions between

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions between.

Prototype

public static Criterion between(String propertyName, Object low, Object high) 

Source Link

Document

Apply a "between" constraint to the named property

Usage

From source file:search_prop.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w w  .  ja  v  a 2  s. c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        String[] bhkGroup = request.getParameterValues("bhkgroup");
        String[] typeGroup = request.getParameterValues("typegroup");

        System.out.println("the types are:" + typeGroup[0]);
        System.out.println("the bhks are:" + bhkGroup[0]);

        String stateid = request.getParameter("state");
        String cityid = request.getParameter("city");
        String areaid = request.getParameter("area");
        //            String minp = request.getParameter("minprice");
        //            String maxp = request.getParameter("maxprice");
        //            String minsq = request.getParameter("minsqfeet");
        //            String maxsq = request.getParameter("maxsqfeet");
        //            

        //Edited
        int minp = Integer.parseInt(request.getParameter("minprice"));
        int maxp = Integer.parseInt(request.getParameter("maxprice"));
        int minsq = Integer.parseInt(request.getParameter("minsqfeet"));
        int maxsq = Integer.parseInt(request.getParameter("maxsqfeet"));

        String state = "";
        Criteria cr1 = ss.createCriteria(StateMaster.class);
        cr1.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr1.list();
        System.out.println("----------" + ar.size());
        if (ar.isEmpty()) {

        } else {
            state = ar.get(0).getSName();
            System.out.println("-------" + state);
        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        System.out.println(minp + " " + maxp + " " + minsq + " " + maxsq);

        Criteria cr = ss.createCriteria(PropDetail.class);
        cr.add(Restrictions.in("pBhk", bhkGroup));
        cr.add(Restrictions.in("pType", typeGroup));
        cr.add(Restrictions.eq("pState", state));
        cr.add(Restrictions.eq("pCity", city));
        cr.add(Restrictions.eq("pArea", area));
        cr.add(Restrictions.between("pPrice", minp, maxp));
        cr.add(Restrictions.between("pFloor", minsq, maxsq));

        ArrayList<PropDetail> pd = (ArrayList<PropDetail>) cr.list();

        /*   for(PropDetail p: pd)
         {
         out.print(p.getPId()+" type:"+p.getPType()+" bhk:"+p.getPBhk());
         out.println(" ");
         }
         */
        if (pd.isEmpty()) {
            out.print("no such property");
            String msg = "Sorry, No results found.";
            request.setAttribute("error", msg);
        } else {
            request.setAttribute("proplist", pd);
        }
        RequestDispatcher rd = request.getRequestDispatcher("getstate?id=9");
        rd.forward(request, response);

    } catch (HibernateException e) {
        out.println("There was some error with the taken action.");
        System.out.print(e.getMessage());
    }
}

From source file:apm.modules.sys.service.LogService.java

License:Open Source License

public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = dao.createDetachedCriteria();

    String createById = ObjectUtils.toString(paramMap.get("createById"));
    if (StringUtils.isNotEmpty(createById)) {
        dc.add(Restrictions.eq("createBy.id", createById));
    }//from   ww w .  j a  va  2  s  .  co m

    String uri = ObjectUtils.toString(paramMap.get("uri"));
    if (StringUtils.isNotBlank(uri)) {
        dc.add(Restrictions.like("uri", "%" + uri + "%"));
    }

    String exception = ObjectUtils.toString(paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
        dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
        beginDate = DateUtils.setDays(new Date(), 1);
        paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
        endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
        paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("createDate"));
    return dao.find(page, dc);
}

From source file:at.ac.tuwien.ifs.tita.dao.time.EffortDao.java

License:Apache License

/** {@inheritDoc} */
public List<Effort> getTimeEffortsMonthlyView(Integer year, Integer month, TiTAUser user) {
    Calendar start = Calendar.getInstance();
    Calendar end = Calendar.getInstance();
    start.set(year, month, 1);//ww  w .  ja  v a2s  .co  m
    end.set(year, month, start.getActualMaximum(Calendar.DAY_OF_MONTH));

    return findByCriteriaOrdered(
            new Criterion[] { Restrictions.between("date", start.getTime(), end.getTime()),
                    Restrictions.eq("deleted", false), Restrictions.eq("user", user) },
            new Order[] { Property.forName("date").asc() }, new String[] {});
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

private List<Long> applyConsentStatusFilters(DataExtractionVO allTheData, Search search,
        List<Long> idsToInclude) {

    //for(Long l : idsToInclude) {
    //   log.info("including: " + l);
    //}/*from ww  w .j a  v a2 s  .  co m*/
    boolean hasConsentFilters = false;
    if (search.getQueryFilters().isEmpty()) {
        return idsToInclude;
    } else {
        for (QueryFilter filter : search.getQueryFilters()) {
            if (filter.getConsentStatusField() != null) {
                hasConsentFilters = true;
            }
        }
    }
    Criteria filter = getSession().createCriteria(Consent.class, "c");
    filter.add(Restrictions.eq("c.study.id", search.getStudy().getId()));
    filter.createAlias("c.linkSubjectStudy", "lss");
    if (!idsToInclude.isEmpty()) {
        filter.add(Restrictions.in("lss.id", idsToInclude));
    }
    filter.createAlias("c.studyComponentStatus", "cscs");
    filter.createAlias("c.studyComp", "csc");

    if (!hasConsentFilters) {

        for (QueryFilter qf : search.getQueryFilters()) {
            if (qf.getConsentStatusField() != null) {
                switch (qf.getOperator()) {
                case EQUAL:
                    filter.add(Restrictions.eq(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case BETWEEN:
                    filter.add(Restrictions.between(getConsentFilterFieldName(qf), qf.getValue(),
                            qf.getSecondValue()));
                    break;
                case GREATER_THAN:
                    filter.add(Restrictions.gt(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case GREATER_THAN_OR_EQUAL:
                    filter.add(Restrictions.ge(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case IS_EMPTY:
                    filter.add(Restrictions.isEmpty(getConsentFilterFieldName(qf)));
                    break;
                case IS_NOT_EMPTY:
                    filter.add(Restrictions.isNotEmpty(getConsentFilterFieldName(qf)));
                    break;
                case LESS_THAN:
                    filter.add(Restrictions.lt(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case LESS_THAN_OR_EQUAL:
                    filter.add(Restrictions.le(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case LIKE:
                    filter.add(Restrictions.like(getConsentFilterFieldName(qf), qf.getValue(),
                            MatchMode.ANYWHERE));
                    break;
                case NOT_EQUAL:
                    filter.add(Restrictions.ne(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                default:
                    break;
                }
            }
        }
    }
    filter.setProjection(
            Projections.distinct(Projections.projectionList().add(Projections.property("lss.id"))));

    List<Long> consentStatusIDs = filter.list();

    Collection<Consent> csData = Collections.EMPTY_LIST;

    if (!consentStatusIDs.isEmpty()) {
        Criteria consentData = getSession().createCriteria(Consent.class, "c");
        consentData.add(Restrictions.eq("c.study.id", search.getStudy().getId()));
        consentData.createAlias("c.linkSubjectStudy", "lss");
        consentData.add(Restrictions.in("lss.id", consentStatusIDs));
        csData = consentData.list();
    }

    HashMap<String, ExtractionVO> hashOfConsentStatusData = allTheData.getConsentStatusData();

    ExtractionVO valuesForThisLss = new ExtractionVO();
    HashMap<String, String> map = null;
    LinkSubjectStudy previousLss = null;
    int count = 0;
    //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO
    for (Consent data : csData) {
        if (previousLss == null) {
            map = new HashMap<String, String>();
            previousLss = data.getLinkSubjectStudy();
            count = 0;
        } else if (data.getLinkSubjectStudy().getId().equals(previousLss.getId())) {
            //then just put the data in
            count++;
        } else { //if its a new LSS finalize previous map, etc
            valuesForThisLss.setKeyValues(map);
            valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
            hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss);
            previousLss = data.getLinkSubjectStudy();
            map = new HashMap<String, String>();//reset
            valuesForThisLss = new ExtractionVO();
            count = 0;
        }
        if (data.getStudyComp().getName() != null) {
            map.put(count + "_Study Component Name", data.getStudyComp().getName());
        }
        if (data.getStudyComponentStatus() != null) {
            map.put(count + "_Study Component Status", data.getStudyComponentStatus().getName());
        }
        if (data.getConsentDate() != null) {
            map.put(count + "_Consent Date", data.getConsentDate().toString());
        }
        if (data.getConsentedBy() != null) {
            map.put(count + "_Consented By", data.getConsentedBy());
        }
    }

    //finalize the last entered key value sets/extraction VOs
    if (map != null && previousLss != null) {
        valuesForThisLss.setKeyValues(map);
        valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
        hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss);
    }

    //can probably now go ahead and add these to the dataVO...even though inevitable further filters may further axe this list or parts of it.
    allTheData.setConsentStatusData(hashOfConsentStatusData);
    if (hasConsentFilters) {
        return consentStatusIDs;
    } else {
        return idsToInclude;
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Consent> searchConsent(ConsentVO consentVO) throws EntityNotFoundException, ArkSystemException {

    Criteria criteria = getSession().createCriteria(Consent.class);
    if (consentVO != null) {
        criteria.add(Restrictions.eq("study.id", consentVO.getConsent().getStudy().getId()));

        // must only get consents for subject in context
        criteria.add(Restrictions.eq("linkSubjectStudy", consentVO.getConsent().getLinkSubjectStudy()));

        if (consentVO.getConsent().getStudyComp() != null) {
            criteria.add(Restrictions.eq("studyComp", consentVO.getConsent().getStudyComp()));
        }/* w ww .j a v  a2 s. co m*/

        if (consentVO.getConsent().getStudyComponentStatus() != null) {
            criteria.add(
                    Restrictions.eq("studyComponentStatus", consentVO.getConsent().getStudyComponentStatus()));
        }

        if (consentVO.getConsent().getConsentedBy() != null) {
            criteria.add(Restrictions.ilike("consentedBy", consentVO.getConsent().getConsentedBy(),
                    MatchMode.ANYWHERE));
        }

        if (consentVO.getConsent().getConsentStatus() != null) {
            criteria.add(Restrictions.eq("consentStatus", consentVO.getConsent().getConsentStatus()));
        }

        if (consentVO.getConsent().getConsentDate() != null) {
            criteria.add(Restrictions.between("consentDate", consentVO.getConsent().getConsentDate(),
                    consentVO.getConsentDateEnd()));
        }

        if (consentVO.getConsent().getConsentType() != null) {
            criteria.add(Restrictions.eq("consentType", consentVO.getConsent().getConsentType()));
        }

    }
    List<Consent> list = criteria.list();
    return list;
}

From source file:br.com.financeiro.dao.LancamentoDAOHibernate.java

@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.ge("data", dataFim));
    }/*from  w ww  .j  a  v a2s  .c  o  m*/

    criteria.add(Restrictions.eq("conta", conta));
    criteria.addOrder(Order.asc("data"));
    return criteria.list();
}

From source file:br.com.map.marcelo.dao.VendaDaoImp.java

@Override
public List<Venda> listarPorPeriodo(Calendar dataInicial, Calendar dataFinal) throws DAOException {
    manager = getEntityManager();/*from w w  w .ja  v  a2 s . c  o m*/
    List<Venda> lista = null;
    try {
        Criteria criteria = getCriteria();
        criteria.add(Restrictions.between("dataVenda", dataInicial, dataFinal));
        lista = criteria.list();
    } catch (Exception e) {
        e.printStackTrace();
        throw new DAOException(e.getMessage());
    } finally {
        manager.close();
    }
    return lista;
}

From source file:br.com.map.marcelo.dao.VendaDaoImp.java

@Override
public double aputadoMes(Calendar dataInicial, Calendar dataFinal) throws DAOException {
    manager = getEntityManager();/*from  w w w.  j  a  v  a  2 s  . c om*/
    double valor = 0;
    try {
        Criteria criteria = getCriteria();
        criteria.add(Restrictions.between("dataVenda", dataInicial, dataFinal));
        criteria.setProjection(Projections.sum("precoTotal"));
        if (criteria.uniqueResult() != null) {
            valor = (double) criteria.uniqueResult();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new DAOException(e.getMessage());
    } finally {
        manager.close();
    }
    return valor;
}

From source file:br.com.muranodesign.dao.impl.CalendarioDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Calendario> listarFeriadosSemana(int dia, int mes) {
    Criteria criteria = getSession().createCriteria(Calendario.class);

    Calendar dataInicio = Calendar.getInstance();
    dataInicio.set(Calendar.MONTH, mes);
    dataInicio.set(Calendar.DATE, dia);
    dataInicio.set(Calendar.WEEK_OF_MONTH, dataInicio.get(Calendar.WEEK_OF_MONTH));
    dataInicio.set(Calendar.DAY_OF_WEEK, dataInicio.getFirstDayOfWeek());
    Calendar dataFim = Calendar.getInstance();
    dataFim.set(Calendar.MONTH, mes);
    dataFim.set(Calendar.DATE, dataInicio.get(Calendar.DATE) + 6);

    criteria.add(Restrictions.or(Restrictions.ge("feriado", 1), Restrictions.eq("aula", 0)));

    criteria.add(Restrictions.or(/*from  w w  w. ja v a 2s  .  com*/
            (Restrictions.or(Restrictions.between("dataInicio", dataInicio.getTime(), dataFim.getTime()),
                    Restrictions.between("dataFim", dataInicio.getTime(), dataFim.getTime()))),
            Restrictions.and(Restrictions.lt("dataInicio", dataInicio.getTime()),
                    Restrictions.gt("dataFim", dataFim.getTime()))));
    criteria.addOrder(Order.asc("dataInicio"));

    List<Calendario> result = criteria.list();

    return result;

}

From source file:br.com.muranodesign.dao.impl.ChamadaDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Chamada> listBetween(int idAluno, Date startDate, Date endDate) {
    Criteria criteria = getSession().createCriteria(Chamada.class);
    criteria.add(Restrictions.between("data", startDate, endDate));
    criteria.createAlias("aluno", "aluno");
    criteria.add(Restrictions.eq("aluno.idAluno", idAluno));
    return criteria.list();
}