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.core.dao.StudyDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public LinkSubjectStudy getSubjectByUID(String subjectUID, Study study) throws EntityNotFoundException {

    Criteria linkSubjectStudyCriteria = getSession().createCriteria(LinkSubjectStudy.class);
    linkSubjectStudyCriteria.add(Restrictions.eq("subjectUID", subjectUID));
    linkSubjectStudyCriteria.add(Restrictions.eq("study", study));
    List<LinkSubjectStudy> listOfSubjects = linkSubjectStudyCriteria.list();
    if (listOfSubjects != null && listOfSubjects.size() > 0) {
        return listOfSubjects.get(0);
    } else {/*from   w  ww  . ja  va 2  s. co  m*/
        throw new EntityNotFoundException("There is no subject with the given UID " + subjectUID.toString());
    }
}

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

License:Open Source License

/**
 * returns a the subject (linksubjectystudy) IF there is one, else returns null
 * //from www .  j  a  v a  2  s .  c om
 * Note this is actively fetching person
 * 
 * @param subjectUID
 * @param study
 * @return LinkSubjectStudy
 */
public LinkSubjectStudy getSubjectByUIDAndStudy(String subjectUID, Study study) {
    //log.warn("about to create query right now");
    Criteria linkSubjectStudyCriteria = getSession().createCriteria(LinkSubjectStudy.class);
    linkSubjectStudyCriteria.add(Restrictions.eq("subjectUID", subjectUID));
    linkSubjectStudyCriteria.add(Restrictions.eq("study", study));
    return (LinkSubjectStudy) linkSubjectStudyCriteria.uniqueResult();
}

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

License:Open Source License

public Country getCountry(Long id) {
    Criteria criteria = getSession().createCriteria(Country.class);
    criteria.add(Restrictions.eq("id", id));
    return (Country) criteria.list().get(0);
}

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

License:Open Source License

public Country getCountry(String countryCode) {
    Criteria criteria = getSession().createCriteria(Country.class);
    criteria.add(Restrictions.eq("countryCode", countryCode));
    return (Country) criteria.list().get(0);
}

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

License:Open Source License

public List<State> getStates(Country country) {

    if (country == null) {
        country = getCountry(Constants.DEFAULT_COUNTRY_CODE);
    }/*from   w w w  .j  a  v  a 2  s . com*/
    Criteria criteria = getSession().createCriteria(State.class);
    criteria.add(Restrictions.eq("country", country));
    criteria.addOrder(Order.asc("name"));
    return criteria.list();
}

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

License:Open Source License

public List<StudyComp> getStudyComponentByStudy(Study study) {
    Criteria criteria = getSession().createCriteria(StudyComp.class);
    criteria.add(Restrictions.eq("study", study));
    return criteria.list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public boolean isSubjectConsentedToComponent(StudyComp studyComponent, Person person, Study study) {
    boolean isConsented = false;
    Criteria criteria = getSession().createCriteria(Consent.class);
    criteria.add(Restrictions.eq("studyComp", studyComponent));
    criteria.add(Restrictions.eq("study", study));
    criteria.createAlias("linkSubjectStudy", "lss");
    criteria.add(Restrictions.eq("lss.person", person));
    List list = criteria.list();/*from  w  w w.j a  va2s . com*/
    if (list != null && list.size() > 0) {
        isConsented = true;
    }
    return isConsented;
}

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

License:Open Source License

public String getPreviousLastname(Person person) {
    Criteria criteria = getSession().createCriteria(PersonLastnameHistory.class);

    if (person.getId() != null) {
        criteria.add(Restrictions.eq(Constants.PERSON_SURNAME_HISTORY_PERSON, person));
    }// w  ww . j  a v  a 2s  .  co m
    criteria.addOrder(Order.asc("id"));
    PersonLastnameHistory personLastameHistory = new PersonLastnameHistory();

    List<PersonLastnameHistory> results = criteria.list();
    if (results.size() > 0) {

        // what this is saying is get the second-last last-name to display
        // as "previous lastname"
        personLastameHistory = (PersonLastnameHistory) results.get(results.size() - 1);
    } // else it doesnt have a previous...only a current

    return personLastameHistory.getLastName();
}

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

License:Open Source License

public List<PersonLastnameHistory> getLastnameHistory(Person person) {
    Criteria criteria = getSession().createCriteria(PersonLastnameHistory.class);

    if (person.getId() != null) {
        criteria.add(Restrictions.eq(Constants.PERSON_SURNAME_HISTORY_PERSON, person));
    }//from   w  ww  .  ja v  a 2  s . c o  m

    return criteria.list();
}

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

License:Open Source License

public LinkSubjectStudy getSubject(Long personId, Study study) throws EntityNotFoundException {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("person.id", personId));
    criteria.add(Restrictions.eq("study", study));
    LinkSubjectStudy subject = (LinkSubjectStudy) criteria.uniqueResult();
    if (subject == null) {
        throw new EntityNotFoundException("The Subject does not exist in the system");
    }//  w w  w .ja v  a 2s  .c  om
    return subject;
}