Example usage for org.hibernate Criteria list

List of usage examples for org.hibernate Criteria list

Introduction

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

Prototype

public List list() throws HibernateException;

Source Link

Document

Get the results.

Usage

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));
    }// w w w.jav a 2  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));
    }/*  w  w w  .j av 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

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.  jav  a  2s .co m*/

    return subjectCount;
}

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

License:Open Source License

public Collection<SubjectStatus> getSubjectStatus() {

    Example example = Example.create(new SubjectStatus());
    Criteria criteria = getSession().createCriteria(SubjectStatus.class).add(example);
    return criteria.list();

}

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 {//  w w w. j  av  a2 s  . co m
        throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found.");
    }
}

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

License:Open Source License

/**
 * Look up a Person based on the supplied Long ID that represents a Person primary key. This id is the primary key of the Person table that can
 * represent a subject or contact.//from w ww  .  ja  v  a 2s.c  o m
 * 
 * @param personId
 * @return
 * @throws EntityNotFoundException
 * @throws ArkSystemException
 */
public Person getPerson(Long personId) throws EntityNotFoundException, ArkSystemException {

    Criteria personCriteria = getSession().createCriteria(Person.class);
    personCriteria.add(Restrictions.eq(Constants.ID, personId));
    List<Person> listOfPerson = personCriteria.list();
    if (listOfPerson != null && listOfPerson.size() > 0) {
        return listOfPerson.get(0);
    } else {
        throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found.");
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Phone> getPersonPhoneList(Long personId) throws ArkSystemException {
    Criteria phoneCriteria = getSession().createCriteria(Phone.class);
    phoneCriteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId));
    List<Phone> personPhoneList = phoneCriteria.list();
    //log.info("Number of phones fetched " + personPhoneList.size() + "  Person Id" + personId.intValue());

    if (personPhoneList.isEmpty()) {
        log.error("this person has no phone;  " + personId);
        // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found.");
    }//  w w w.j  a  va2s .  c  o m
    //log.info("Number of phone items retrieved for person Id " + personId + " " + personPhoneList.size());
    return personPhoneList;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Phone> getPersonPhoneList(Long personId, Phone phone) throws ArkSystemException {

    Criteria phoneCriteria = getSession().createCriteria(Phone.class);

    if (personId != null) {
        phoneCriteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId));
    }//from  ww  w.j a va  2s. co  m

    if (phone != null) {

        if (phone.getId() != null) {
            phoneCriteria.add(Restrictions.eq(Constants.PHONE_ID, phone.getId()));
        }

        if (phone.getPhoneNumber() != null) {
            phoneCriteria.add(Restrictions.ilike(Constants.PHONE_NUMBER, phone.getPhoneNumber()));
        }

        if (phone.getPhoneType() != null) {
            phoneCriteria.add(Restrictions.eq(Constants.PHONE_TYPE, phone.getPhoneType()));
        }

        if (phone.getAreaCode() != null) {
            phoneCriteria.add(Restrictions.eq(Constants.AREA_CODE, phone.getAreaCode()));
        }
        phoneCriteria.setFetchMode("silentMode", FetchMode.JOIN);

    }

    List<Phone> personPhoneList = phoneCriteria.list();
    //log.info("Number of phones fetched " + personPhoneList.size() + "  Person Id" + personId.intValue());

    //if (personPhoneList.isEmpty()) {
    // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found.");
    //   log.info(" personId " + personId + " had no phones.  No drama");
    //   }
    return personPhoneList;
}

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

License:Open Source License

/**
 * Looks up all the addresses for a person.
 * /*from  w  ww.  ja  v  a  2s  . c  om*/
 * @param personId
 * @param address
 * @return List<Address>
 * @throws EntityNotFoundException
 * @throws ArkSystemException
 */
@SuppressWarnings("unchecked")
public List<Address> getPersonAddressList(Long personId, Address address) throws ArkSystemException {

    Criteria criteria = getSession().createCriteria(Address.class);

    if (personId != null) {
        criteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId));
    }

    if (address != null) {
        // Add criteria for address
        if (address.getStreetAddress() != null) {
            criteria.add(Restrictions.ilike(Constants.STREET_ADDRESS, address.getStreetAddress(),
                    MatchMode.ANYWHERE));
        }

        if (address.getCountry() != null) {
            criteria.add(Restrictions.eq(Constants.COUNTRY_NAME, address.getCountry()));
        }

        if (address.getPostCode() != null) {
            criteria.add(Restrictions.eq(Constants.POST_CODE, address.getPostCode()));
        }

        if (address.getCity() != null) {
            criteria.add(Restrictions.ilike(Constants.CITY, address.getCity()));
        }

        if (address.getState() != null) {
            criteria.add(Restrictions.eq(Constants.STATE_NAME, address.getState()));
        }

        if (address.getAddressType() != null) {
            criteria.add(Restrictions.eq(Constants.ADDRESS_TYPE, address.getAddressType()));
        }
    }

    List<Address> personAddressList = criteria.list();

    // if (personAddressList.isEmpty()) {
    // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found.");
    // log.info("person " + personId + " does not have any addresses");
    // }
    return personAddressList;
}

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

License:Open Source License

public List<Consent> searchConsent(Consent consent) throws EntityNotFoundException, ArkSystemException {
    Criteria criteria = getSession().createCriteria(Consent.class);
    if (consent != null) {
        criteria.add(Restrictions.eq("study.id", consent.getStudy().getId()));

        if (consent.getStudyComp() != null) {
            criteria.add(Restrictions.eq("studyComp", consent.getStudyComp()));
        }/*from   w  w w.  ja  v  a2s  . co  m*/

        if (consent.getStudyComponentStatus() != null) {
            criteria.add(Restrictions.eq("studyComponentStatus", consent.getStudyComponentStatus()));
        }

        if (consent.getConsentedBy() != null) {
            criteria.add(Restrictions.ilike("consentedBy", consent.getConsentedBy(), MatchMode.ANYWHERE));
        }

        if (consent.getConsentStatus() != null) {
            criteria.add(Restrictions.eq("consentStatus", consent.getConsentStatus()));
        }

        if (consent.getConsentDate() != null) {
            criteria.add(Restrictions.eq("consentDate", consent.getConsentDate()));
        }

        if (consent.getConsentType() != null) {
            criteria.add(Restrictions.eq("consentType", consent.getConsentType()));
        }
    }

    return criteria.list();
}