Example usage for org.hibernate.criterion Restrictions le

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

Introduction

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

Prototype

public static SimpleExpression le(String propertyName, Object value) 

Source Link

Document

Apply a "less than or equal" constraint to the named property

Usage

From source file:br.os.rh.turno.TurnoDAO.java

public Turno verificaTurno() {
    setSessao(HibernateUtil.getSessionFactory().openSession());
    setTransacao(getSessao().beginTransaction());
    Turno turno = null;/* w  w  w.j  av  a 2s.  co  m*/

    String fHora = "HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(fHora);
    Date hour = new Date();

    turno = (Turno) getSessao().createCriteria(Turno.class).add(Restrictions.ge("horaInicio", hour))
            .add(Restrictions.le("horaFim", hour)).uniqueResult();
    getSessao().close();

    return turno;

}

From source file:br.os.rh.turno.TurnoDAO.java

public Turno verificaTurno(Date hour) {
    setSessao(HibernateUtil.getSessionFactory().openSession());
    setTransacao(getSessao().beginTransaction());
    Turno turno = null;//from  ww  w  .j ava  2s  .c  o m

    turno = (Turno) getSessao().createCriteria(Turno.class).add(Restrictions.ge("horaInicio", hour))
            .add(Restrictions.le("horaFim", hour)).uniqueResult();
    getSessao().close();
    return turno;

}

From source file:br.ufg.calendario.dao.EventoDao.java

@Transactional(readOnly = true)
public int rowCount(Map<String, Object> filters) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Evento.class);
    for (String key : filters.keySet()) {
        if (key.equals("assunto")) {
            criteria.add(Restrictions.like(key, filters.get(key).toString(), MatchMode.ANYWHERE).ignoreCase());
        }/* w ww . jav a 2 s .  com*/
        if (key.equals("periodo")) {
            Map periodo = (Map) filters.get(key);
            criteria.add(Restrictions.and(Restrictions.ge("inicio", periodo.get("inicio")))
                    .add(Restrictions.le("termino", periodo.get("termino"))));
        }

        if (key.equals("calendario")) {
            criteria.createAlias("calendario", "c");
            criteria.add(Restrictions.eq("c.ano", ((Calendario) filters.get(key)).getAno()));
        }
        if (key.equals("termo")) {
            criteria.add(Restrictions.or(
                    Restrictions.like("assunto", filters.get(key).toString(), MatchMode.ANYWHERE).ignoreCase(),
                    Restrictions.like("descricao", filters.get(key).toString(), MatchMode.ANYWHERE)
                            .ignoreCase()));
        }
        if (key.equals("interessado")) {
            System.out.println("implementar filtro interessado");
        }
        if (key.equals("regional")) {
            System.out.println("implementar filtro regional");
        }
    }
    return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
}

From source file:br.ufmg.hc.telessaude.diagnostico.dominio.dao.ExameDAOLocal.java

public List<Exame> consultar(Integer id, String nomePaciente, Date inicio, Date fim) throws DAOException {
    ArrayList<Criterion> restrict = new ArrayList();
    if (id != null) {
        restrict.add(Restrictions.eq("id", id));
    } else {//from w  ww.  j  av a  2s  .c  o m
        if (nomePaciente != null && !nomePaciente.isEmpty()) {
            restrict.add(Restrictions.ilike("pc.nome", nomePaciente, MatchMode.ANYWHERE));
        }
        if (inicio != null) {
            restrict.add(Restrictions.ge("datainclusao", inicio));
        }
        if (fim != null) {
            restrict.add(Restrictions.le("datainclusao", fim));
        }
    }
    try {
        final DetachedCriteria crit = DetachedCriteria.forClass(c);
        final Criteria criteria = crit.getExecutableCriteria(HibernateUtil.currentSession());

        crit.createAlias("paciente", "pc");
        crit.createAlias("status", "st");

        criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("pc.nome")).add(Projections.property("pc.datanascimento"))
                .add(Projections.property("datainclusao")).add(Projections.property("st.nome")));

        criteria.addOrder(Order.desc("datainclusao"));

        for (final Criterion cri : restrict) {
            criteria.add(cri);
        }

        final List<Object[]> arrays = criteria.list();
        final List<Exame> exames = new ArrayList<>();

        for (Object[] array : arrays) {
            final Exame exame = new Exame(Integer.parseInt(String.valueOf(array[0])));
            exame.setPaciente(new Paciente());
            exame.getPaciente().setNome(String.valueOf(array[1]));
            exame.getPaciente().setDatanascimento((Date) array[2]);
            exame.setDatainclusao((Date) array[3]);
            exame.setStatus(new Status());
            exame.getStatus().setNome(String.valueOf(array[4]));

            exames.add(exame);
        }

        return exames;

    } catch (HibernateException ex) {
        throw new DAOException(ex.getMessage());
    }

}

From source file:by.telecom.subscriberapp.DAO.LogDaoImpl.java

@Override
public List<Log> getByParameter(String name, Date dateStart, Date dateEnd, String type, String comment,
        String sort, String orderType) {
    Session session = null;// w w  w.j  a  v a  2s.c  om
    List<Log> logs = new ArrayList<Log>();
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Criteria criteria = session.createCriteria(Log.class).add(Restrictions.ge("date", dateStart))
                .add(Restrictions.le("date", dateEnd)).add(Restrictions.like("type", "%" + type + "%"))
                .add(Restrictions.like("comment", "%" + comment + "%"));
        Order order = Order.asc(sort);
        if (orderType.equals("desc"))
            order = Order.desc(sort);
        if (sort.equals("name"))
            criteria = criteria.createCriteria("user").add(Restrictions.like("name", "%" + name + "%"))
                    .addOrder(order);
        else
            criteria = criteria.addOrder(order).createCriteria("user")
                    .add(Restrictions.like("name", "%" + name + "%"));

        logs = criteria.list();
        session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace(System.out);
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return logs;
}

From source file:ca.myewb.controllers.common.EventList.java

License:Open Source License

public Collection<EventModel> listVisibleEventsBetweenDates(Date start, Date end, GroupChapterModel chapter)
        throws HibernateException {
    Criteria criteria = hibernateSession.createCriteria(EventModel.class);

    LogicalExpression singleDayEvents = Restrictions.and(Restrictions.ge("startDate", start),
            Restrictions.le("endDate", end));
    LogicalExpression endsToday = Restrictions.and(Restrictions.lt("startDate", start),
            Restrictions.and(Restrictions.ge("endDate", start), Restrictions.le("endDate", end)));
    LogicalExpression startsToday = Restrictions.and(
            Restrictions.and(Restrictions.ge("startDate", start), Restrictions.le("startDate", end)),
            Restrictions.gt("endDate", end));
    LogicalExpression ongoing = Restrictions.and(Restrictions.lt("startDate", start),
            Restrictions.gt("endDate", end));

    criteria.add(Restrictions.or(singleDayEvents,
            Restrictions.or(endsToday, Restrictions.or(startsToday, ongoing))));

    if (chapter == null) {
        if (!currentUser.isAdmin()) {
            criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true)));
        } else {//from www  . j  a v a 2  s.c  om
            List<GroupModel> adminGroups = Helpers.getNationalRepLists(true, true);
            adminGroups.add(Helpers.getGroup("Exec"));
            adminGroups.add(Helpers.getGroup("ProChaptersExec"));

            criteria.add(Restrictions.in("group", adminGroups));
        }
    } else {
        criteria.add(Restrictions.in("group", Permissions.visibleGroupsInChapter(currentUser, chapter)));
    }

    criteria.addOrder(Order.asc("startDate"));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return new SafeHibList<EventModel>(criteria).list();
}

From source file:ca.myewb.frame.Cron.java

License:Open Source License

private static void doMembershipExpiry(Logger log, Session session) throws Exception {
    // expiry/*  w  ww  . ja v a2  s  .co  m*/
    log.info("----- Expiry");

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    Criteria crit = session.createCriteria(UserModel.class);
    crit.add(Restrictions.isNotNull("email"));
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.le("expiry", calendar.getTime()));

    Iterator it = crit.list().iterator();

    while (it.hasNext()) {
        UserModel u = (UserModel) it.next();
        log.info(u.getFirstname() + " " + u.getLastname() + ": " + u.getEmail());

        u.expire();

        VelocityContext mailCtx = new VelocityContext();
        mailCtx.put("helpers", new Helpers());
        mailCtx.put("name", u.getFirstname());

        Template template = Velocity.getTemplate("emails/expiry.vm");
        StringWriter writer = new StringWriter();
        template.merge(mailCtx, writer);

        EmailModel.sendEmail(u.getEmail(), writer.toString());
    }
}

From source file:ca.myewb.frame.Cron.java

License:Open Source License

private static void createSessionEndEmails(Logger log, Session session) throws Exception {
    List<ApplicationSessionModel> sessions = new SafeHibList<ApplicationSessionModel>(
            session.createCriteria(ApplicationSessionModel.class).add(Restrictions.le("closeDate", new Date()))
                    .add(Restrictions.eq("emailSent", false))
                    .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)).list();
    for (Iterator iter = sessions.iterator(); iter.hasNext();) {
        ApplicationSessionModel s = (ApplicationSessionModel) iter.next();

        EmailModel.sendEmail(//from  ww  w.j  av a2 s.c  om
                Helpers.getSystemEmail(), s.getApplicantEmails(true), "[" + Helpers.getEnShortName()
                        + "-applications] Application Session " + s.getName() + " has closed",
                s.getCloseEmailText(), Helpers.getEnShortName() + "-applications");

        s.croned();

        log.info("Created close session email for " + s.getName());
    }
}

From source file:ca.myewb.model.ApplicationSessionModel.java

License:Open Source License

public static List<ApplicationSessionModel> getOpenApplicationSessions() {
    SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(HibernateUtil
            .currentSession().createCriteria(ApplicationSessionModel.class)
            .add(Restrictions.le("openDate", new Date())).add(Restrictions.gt("closeDate", new Date())));
    return openSessions.list();
}

From source file:ca.myewb.model.ApplicationSessionModel.java

License:Open Source License

public static List<ApplicationSessionModel> getClosedApplicationSessions() {
    SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(
            HibernateUtil.currentSession().createCriteria(ApplicationSessionModel.class)
                    .add(Restrictions.le("closeDate", new Date())));
    return openSessions.list();

}