Example usage for org.hibernate.criterion Restrictions and

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

Introduction

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

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:br.com.Monopoly.control.dao.AmigoDAO.java

public Amigo buscarAmizade(Usuario usuario1, Usuario usuario2) {
    entity = (Amigo) criteria.add(Restrictions.or(
            Restrictions.and(Restrictions.eq("id.remetente", usuario1),
                    Restrictions.eq("id.convidado", usuario2)),
            Restrictions.and(Restrictions.eq("id.remetente", usuario2),
                    Restrictions.eq("id.convidado", usuario1))))
            .uniqueResult();/*  ww  w  .  ja  v a2  s.co m*/
    closeSession();
    return entity;
}

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  .  j  a va2s .c  o m
            (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.OCTur.control.DAO.PacoteDAO.java

public List<Pacote> pegarPorCidade(Cidade cidade, Date inicio, Date fim, boolean e) {
    List<Hotel> hoteis = new HotelDAO().pegarPorCidade(cidade);
    List<Voo> voos = new VooDAO().pegarPorDestino(cidade);
    Criterion[] criterios = new Criterion[2];
    if (!hoteis.isEmpty()) {
        criterios[0] = Restrictions.in("hotel", hoteis);
    }/*from w  ww .  ja va  2s.  c  om*/
    if (!voos.isEmpty()) {
        criterios[1] = Restrictions.in("voo", voos);
    }
    if (hoteis.isEmpty() && voos.isEmpty()) {
        closeSession();
        return entitys;
    }
    if (e) {
        criteria.add(Restrictions.and(Restrictions.eq("inicio", inicio), Restrictions.eq("fim", fim)));
    } else {
        criteria.add(Restrictions.or(Restrictions.eq("inicio", inicio), Restrictions.eq("fim", fim)));
    }
    entitys = criteria.add(Restrictions.or(criterios)).list();
    closeSession();
    return entitys;
}

From source file:br.com.OCTur.control.DAO.PacoteDAO.java

public List<Pacote> pegarPorInicioFim(Date inicio, Date fim, boolean selected) {
    if (selected) {
        criteria.add(Restrictions.and(Restrictions.eq("inicio", inicio), Restrictions.eq("fim", fim)));
    } else {/* w ww .j  a  v  a2s  .c om*/
        criteria.add(Restrictions.or(Restrictions.eq("inicio", inicio), Restrictions.eq("fim", fim)));
    }
    entitys = criteria.list();
    closeSession();
    return entitys;
}

From source file:br.com.OCTur.control.DAO.ReservaDAO.java

public List<Reserva> pegarPorQuartoInicioFim(Quarto quarto, Date inicio, Date fim) {
    entitys = criteria.add(Restrictions.eq("quarto", quarto))
            .add(Restrictions.or(/*from ww  w  .j  a v  a2  s  .  c  o m*/
                    Restrictions.and(Restrictions.le("inicio", inicio), Restrictions.ge("fim", inicio)),
                    Restrictions.between("inicio", inicio, fim), Restrictions.between("fim", inicio, fim)))
            .list();
    closeSession();
    return entitys;
}

From source file:br.com.SistemaOCTur.dao.EventoDAO.java

public boolean validar(Evento evento) {
    entitys = criteria.add(Restrictions.eq("salao", evento.getSalao()))
            .add(Restrictions.or(Restrictions.between("inicio", evento.getInicio(), evento.getFim()),
                    Restrictions.between("fim", evento.getInicio(), evento.getFim()),
                    Restrictions.or(/*from  w  ww.j a va  2  s .c om*/
                            Restrictions.and(Restrictions.ge("inicio", evento.getInicio()),
                                    Restrictions.le("fim", evento.getInicio())),
                            Restrictions.and(Restrictions.le("inicio", evento.getFim()),
                                    Restrictions.ge("fim", evento.getFim())))))
            .list();
    session.close();
    return entitys.isEmpty();
}

From source file:br.com.SistemaOCTur.dao.EventoDAO.java

public Evento pegarPorSalaoDia(Salao salao, Date time) {
    entity = (Evento) criteria.add(Restrictions.eq("salao", salao))
            .add(Restrictions.and(Restrictions.le("inicio", time), Restrictions.ge("fim", time)))
            .uniqueResult();//from   w w w  .j a v  a  2s  .  c o  m
    session.close();
    return entity;
}

From source file:br.com.webbudget.domain.model.repository.financial.FixedMovementRepository.java

License:Open Source License

/**
 *
 * @return//from w ww . j a  va2s .co m
 */
@Override
public List<FixedMovement> listAutoLaunch() {

    final Criteria criteria = this.createCriteria();

    criteria.add(Restrictions.and(Restrictions.eq("autoLaunch", true),
            Restrictions.eq("fixedMovementStatusType", FixedMovementStatusType.ACTIVE)));

    return criteria.list();
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public List<CpConfiguracao> consultarConfiguracoesDesde(Date desde) {
    Criteria c = HibernateUtil.getSessao().createCriteria(CpConfiguracao.class);
    LogicalExpression confsAtivas = Restrictions.and(Restrictions.ge("hisDtIni", desde),
            Restrictions.isNull("hisDtFim"));
    LogicalExpression confsInativas = Restrictions.and(Restrictions.ge("hisDtFim", desde),
            Restrictions.isNotNull("hisDtFim"));
    c.add(Restrictions.or(confsAtivas, confsInativas));
    return c.list();
}

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 {//  w w w  .  j  av  a2  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();
}