Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

In this page you can find the example usage for org.hibernate Criteria add.

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

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

License:Open Source License

public ConsentType getConsentTypeByName(String name) {
    ConsentType consentType = null;//w  w  w  .  j a va  2s .  c  om
    Criteria criteria = getSession().createCriteria(ConsentType.class);
    criteria.add(Restrictions.eq("name", name));

    if (criteria.list().size() > 0) {
        consentType = (ConsentType) criteria.list().get(0);
    }
    return consentType;
}

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

License:Open Source License

public ConsentStatus getConsentStatusByName(String name) {
    ConsentStatus consentStatus = null;/*from   ww w . j ava 2  s .c  o  m*/
    Criteria criteria = getSession().createCriteria(ConsentStatus.class);
    criteria.add(Restrictions.eq("name", name));

    if (criteria.list().size() > 0) {
        consentStatus = (ConsentStatus) criteria.list().get(0);
    }
    return consentStatus;
}

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

License:Open Source License

private VitalStatus getVitalStatus(Long id) {
    Criteria criteria = getSession().createCriteria(VitalStatus.class);

    if (id != null) {
        criteria.add(Restrictions.eq("id", id));
    }//from w w  w  .  j a  v  a2  s  . c  o m

    return (VitalStatus) criteria.list().get(0);
}

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

License:Open Source License

public MaritalStatus getMaritalStatusNyName(String name) {
    Criteria criteria = getSession().createCriteria(MaritalStatus.class);

    if (name != null) {
        criteria.add(Restrictions.eq("name", name));
    }/* www. j  av a 2  s  .c  o  m*/

    return (MaritalStatus) criteria.list().get(0);
}

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

License:Open Source License

public GenderType getGenderType(Long id) {
    Criteria criteria = getSession().createCriteria(GenderType.class);

    if (id != null) {
        criteria.add(Restrictions.eq("id", id));
    }/*from w  w w.  j  av a2 s . c o m*/

    return (GenderType) criteria.list().get(0);
}

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

License:Open Source License

public TitleType getTitleType(Long id) {
    Criteria criteria = getSession().createCriteria(TitleType.class);

    if (id != null) {
        criteria.add(Restrictions.eq("id", id));
    }//from w w  w  .  j  av  a2 s.c o  m

    return (TitleType) criteria.list().get(0);
}

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

License:Open Source License

public SubjectStatus getSubjectStatusByName(String name) {
    Criteria criteria = getSession().createCriteria(SubjectStatus.class);

    if (name != null) {
        criteria.add(Restrictions.eq("name", name));
    }// www .ja  v a 2s  . c  o  m

    List<SubjectStatus> subjectStatus = criteria.list();

    // TODO - this should just be not permitted at db level...code shouldnt be checking for poor data - particularly on something which is more enum
    // like than data like
    if (subjectStatus.size() > 0) {
        if (subjectStatus.size() > 1) {
            log.error("Backend database has non-unique Status names, returned the first one");
        }
        return (subjectStatus.get(0));
    } else
        return null;
}

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

License:Open Source License

protected SubjectUidSequence getSubjectUidSequence(Study study) {
    // log.info("Getting uid seq entity for study " + study.getName());
    // Stateless sessions should be used to avoid locking the record for future update
    // by getSession(), which relies on the "open session filter" mechanism
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(SubjectUidSequence.class);
    criteria.add(Restrictions.eq(Constants.SUBJECTUIDSEQ_STUDYNAMEID, study.getName()));
    criteria.setMaxResults(1);/*  www  .  ja va2 s  .co  m*/
    SubjectUidSequence result = (SubjectUidSequence) criteria.uniqueResult();
    session.close();
    log.warn("and got entity with lock = " + result.getInsertLock() + " for study " + study.getName());
    return result;
}

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

License:Open Source License

public Long getSubjectCount(Study study) {
    Long subjectCount = new Long(0);
    if (study.getId() != null) {
        Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
        criteria.add(Restrictions.eq("study", study));

        List<LinkSubjectStudy> listOfSubjects = (List<LinkSubjectStudy>) criteria.list();
        subjectCount = new Long(listOfSubjects.size());
    }//from w ww.  ja  va 2  s.co m

    return subjectCount;
}

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

License:Open Source License

public LinkSubjectStudy getLinkSubjectStudy(Long id) throws EntityNotFoundException {

    Criteria linkSubjectStudyCriteria = getSession().createCriteria(LinkSubjectStudy.class);
    linkSubjectStudyCriteria.add(Restrictions.eq(Constants.ID, id));
    List<LinkSubjectStudy> listOfSubjects = linkSubjectStudyCriteria.list();
    if (listOfSubjects != null && listOfSubjects.size() > 0) {
        return listOfSubjects.get(0);
    } else {/*from  ww  w .  ja  v a  2  s .c o  m*/
        throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found.");
    }
}