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:com.ipn.escom.ageinnn.evento.service.EventoService.java

public Evento findByDocenteAndEventoId(Docente docente, Integer eventoId) {
    Evento entrevista = null;//w ww.  j av a  2  s.  com
    try {
        session = Service.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        entrevista = (Evento) session.createCriteria(Evento.class).add(
                Restrictions.and(Restrictions.idEq(eventoId), Restrictions.eq("docenteId", docente.getId())))
                .uniqueResult();

        session.getTransaction().commit();

    } catch (Exception e) {
        session.getTransaction().rollback();
        throw e;
    }

    return entrevista;
}

From source file:com.ipn.escom.ageinnn.gestion.service.InscripcionService.java

public Inscripcion findByCursoAndMedicoResidente(Curso curso, MedicoResidente medicoResidente) {
    Inscripcion inscripcion;//from w  w w .  ja v  a 2  s  .c  om
    try {
        session = Service.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        inscripcion = (Inscripcion) session.createCriteria(Inscripcion.class)
                .add(Restrictions.and(Restrictions.eq("cursoId", curso.getId()),
                        Restrictions.eq("alumnoId", medicoResidente.getId())))
                .uniqueResult();

        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw e;
    }

    return inscripcion;
}

From source file:com.ipn.escom.ageinnn.usuario.service.UsuarioServiceImpl.java

public <T extends Usuario> T findByEmailAndToken(Class<T> clazz, String email, String token) {
    T login = null;/*from w w w.j  av  a 2  s . c o m*/
    List<T> loginList = new ArrayList<>();
    try {
        this.session = Service.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        loginList = session.createCriteria(clazz)
                .add(Restrictions.and(Restrictions.eq("email", email), Restrictions.eq("mailToken", token)))
                .list();
        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw e;
    }

    if (!loginList.isEmpty()) {
        login = loginList.get(0);
    }

    return login;
}

From source file:com.itfaculty.progress.dao.Impl.DoctorsDaoImpl.java

@Override
public Doctors logindoctor(Doctors doctors) {
    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Doctors.class);
    Criterion usernam = Restrictions.eq("doctorUsername", doctors.getDoctorUsername());
    Criterion passw = Restrictions.eq("doctorPassword", doctors.getDoctorPassword());
    LogicalExpression andExp = Restrictions.and(usernam, passw);
    cr.add(andExp);/*from w  w  w . ja v a  2s .  com*/
    Doctors result = (Doctors) cr.uniqueResult();
    return result;
}

From source file:com.itfaculty.progress.dao.Impl.LabassistantsDaoImpl.java

@Override
public Labassistants loginLabassistants(Labassistants labassistants) {
    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Labassistants.class);
    Criterion usernam = Restrictions.eq("labassistantUsername", labassistants.getLabassistantUsername());
    Criterion passw = Restrictions.eq("labassistantPassword", labassistants.getLabassistantPassword());
    LogicalExpression andExp = Restrictions.and(usernam, passw);
    cr.add(andExp);//from w  w  w  .  j  a va2  s .c  om
    Labassistants result = (Labassistants) cr.uniqueResult();
    return result;
}

From source file:com.itfaculty.progress.dao.Impl.PatientsDaoImpl.java

@Override
public Patients loginPatient(Patients patients) {
    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Patients.class);
    Criterion usernam = Restrictions.eq("patientUname", patients.getPatientUname());
    Criterion passw = Restrictions.eq("patientPassword", patients.getPatientPassword());
    LogicalExpression andExp = Restrictions.and(usernam, passw);
    cr.add(andExp);/*from  w w  w . j  a  va 2 s  . c  o m*/
    Patients result = (Patients) cr.uniqueResult();
    return result;
}

From source file:com.itfaculty.progress.dao.Impl.ReceptionistsDaoImpl.java

@Override
public Receptionists loginReceptionists(Receptionists receptionists) {
    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Receptionists.class);
    Criterion usernam = Restrictions.eq("receptionistUsername", receptionists.getReceptionistUsername());
    Criterion passw = Restrictions.eq("receptionistPassword", receptionists.getReceptionistPassword());
    LogicalExpression andExp = Restrictions.and(usernam, passw);
    cr.add(andExp);/*from w w  w .j  a  va 2 s .c o m*/
    Receptionists result = (Receptionists) cr.uniqueResult();
    return result;
}

From source file:com.itrus.ca.modules.cms.service.ArticleService.java

License:Open Source License

public Page<Article> find(Page<Article> page, Article article, boolean isDataScopeFilter) {
    // ??6??//w  ww  .  ja  va 2  s . c om
    Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByArticle");
    if (updateExpiredWeightDate == null
            || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) {
        articleDao.updateExpiredWeight();
        CacheUtils.put("updateExpiredWeightDateByArticle", DateUtils.addHours(new Date(), 6));
    }
    DetachedCriteria dc = articleDao.createDetachedCriteria();
    dc.createAlias("category", "category");
    dc.createAlias("category.site", "category.site");
    if (article.getCategory() != null && article.getCategory().getId() != null
            && !Category.isRoot(article.getCategory().getId())) {
        Category category = categoryDao.findOne(article.getCategory().getId());
        if (category != null) {
            dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()),
                    Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
            dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
            article.setCategory(category);
        } else {
            dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
        }
    } else {
        dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
    }
    if (StringUtils.isNotEmpty(article.getTitle())) {
        dc.add(Restrictions.like("title", "%" + EscapeUtil.escapeLike(article.getTitle()) + "%"));
    }
    if (StringUtils.isNotEmpty(article.getPosid())) {
        dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%"));
    }
    if (StringUtils.isNotEmpty(article.getImage()) && Article.YES.equals(article.getImage())) {
        dc.add(Restrictions.and(Restrictions.isNotNull("image"), Restrictions.ne("image", "")));
    }
    if (article.getCreateBy() != null && article.getCreateBy().getId() > 0) {
        dc.add(Restrictions.eq("createBy.id", article.getCreateBy().getId()));
    }
    if (isDataScopeFilter) {
        dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy");
        dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy"));
    }
    dc.add(Restrictions.eq(Article.DEL_FLAG, article.getDelFlag()));
    if (StringUtils.isBlank(page.getOrderBy())) {
        dc.addOrder(Order.desc("weight"));
        dc.addOrder(Order.desc("updateDate"));
    }
    return articleDao.find(page, dc);
}

From source file:com.jaspersoft.jasperserver.search.filter.ScheduleFilter.java

License:Open Source License

private Criterion getResourceCriterion(String alias, String uri) {
    int lastSlashPos = uri.lastIndexOf(Folder.SEPARATOR);

    String folderUri = uri.substring(0, lastSlashPos);
    String resourceName = uri.substring(lastSlashPos + 1);

    if (folderUri.length() == 0) {
        folderUri = Folder.SEPARATOR;//ww  w  .j  a  va2 s . co  m
    }

    return Restrictions.and(Restrictions.eq("name", resourceName), Restrictions.eq(alias + ".URI", folderUri));
}

From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object getByProperty(Object entity, String listType) {
    List<Call> list = new ArrayList<>();
    switch (listType) {
    case "Number":
        String number = (String) entity;
        session = getSessionFactory().getCurrentSession();

        Criteria criteria = session.createCriteria(Call.class, "call");
        criteria.add(Restrictions.eq("CallTo", number));
        list = criteria.list();/*from www .j a  v  a2s. c  om*/

        break;
    case "OrderId":
        Long orderId = (Long) entity;
        session = getSessionFactory().getCurrentSession();
        list.add((Call) session.get(Call.class, (Long) orderId));

        break;
    case "Sid":
        String sid = (String) entity;
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.add(Restrictions.eq("Sid", sid));
        list = criteria.list();

        break;
    case "DateCreated":
        String dateCreated = (String) entity;
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.add(Restrictions.like("DateCreated", dateCreated, MatchMode.START));
        list = criteria.list();

        break;
    case "PendingOnDate":
        String pendingOnDate = (String) entity;
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.add(Restrictions.or(
                Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                        Restrictions.like("TrackStatus", "did not", MatchMode.ANYWHERE)),
                Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                        Restrictions.like("TrackStatus", "Pressed 2", MatchMode.START)),
                Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                        Restrictions.like("Status", "failed", MatchMode.START)),
                Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                        Restrictions.like("Status", "no-answer", MatchMode.START))));
        list = criteria.list();

        break;
    default:
        System.err.println("Not a valid option");
        break;
    }
    return list;
}