Example usage for org.hibernate.criterion Restrictions eq

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

Introduction

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

Prototype

public static SimpleExpression eq(String propertyName, Object value) 

Source Link

Document

Apply an "equal" constraint to the named property

Usage

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));
    }//  w  w  w.  j  a  va  2  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 www.ja v a2  s. c om

    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));
    }//ww w .  j a va 2 s .  co  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);//  ww w.  ja v a  2 s .  c  om
    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  www .j  av a2  s . com*/

    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   w ww  .  ja  v  a  2 s. c o  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 .  java  2 s .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  .jav  a 2 s  .  co  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 v a2s . com

    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   ww  w  .  ja v a2s .  c o  m*/
 * @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;
}