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 boolean personHasPreferredMailingAddress(Person person, Long currentAddressId) {

    boolean hasPreferredMailing = false;

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

    // YesNo yes = getYesNo("Yes");
    criteria.add(Restrictions.eq("person.id", person.getId()));
    criteria.add(Restrictions.eq("preferredMailingAddress", true));
    if (currentAddressId != null) {
        criteria.add(Restrictions.ne("id", currentAddressId));
    }/* w ww. j a  v a 2s. c om*/

    List list = criteria.list();
    if (list.size() > 0) {
        hasPreferredMailing = true;
    }
    return hasPreferredMailing;
}

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

License:Open Source License

public String getPreviousLastname(Person person) {
    PersonLastnameHistory personLastameHistory = new PersonLastnameHistory();

    // Only get previous lastname if person in context
    if (person.getId() != null && person.getLastName() != null) {
        Criteria criteria = getSession().createCriteria(PersonLastnameHistory.class);
        criteria.add(Restrictions.eq(au.org.theark.core.Constants.PERSON_SURNAME_HISTORY_PERSON, person));
        criteria.addOrder(Order.desc("id"));
        List pastNamesList = criteria.list();
        if (!pastNamesList.isEmpty()) {
            if (pastNamesList.size() > 0)
                personLastameHistory = (PersonLastnameHistory) pastNamesList.get((pastNamesList.size() - 1));
        }//from  www  .j av  a  2  s.c  om
    }

    return personLastameHistory.getLastName();
}

From source file:au.org.theark.study.model.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(au.org.theark.core.Constants.PERSON_SURNAME_HISTORY_PERSON, person));
    }// www .  j a  v a2  s  . c o  m

    return criteria.list();
}

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

License:Open Source License

public List<SubjectFile> searchSubjectFile(SubjectFile subjectFile)
        throws EntityNotFoundException, ArkSystemException {
    Criteria criteria = getSession().createCriteria(SubjectFile.class);
    if (subjectFile != null) {

        if (subjectFile.getId() != null) {
            criteria.add(Restrictions.eq("id", subjectFile.getId()));
        }/*from   w  w w  .j  a va2s.  c  om*/

        if (subjectFile.getLinkSubjectStudy() != null) {
            criteria.add(Restrictions.eq("linkSubjectStudy", subjectFile.getLinkSubjectStudy()));
        }

        if (subjectFile.getStudyComp() != null) {
            criteria.add(Restrictions.eq("studyComp", subjectFile.getStudyComp()));
        }

        if (subjectFile.getFilename() != null) {
            criteria.add(Restrictions.ilike("filename", subjectFile.getFilename(), MatchMode.ANYWHERE));
        }
    }
    criteria.addOrder(Order.desc("id"));

    @SuppressWarnings("unchecked")
    List<SubjectFile> list = criteria.list();
    return list;
}

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

License:Open Source License

public LinkSubjectStudy getSubjectLinkedToStudy(Long personId, Study study)
        throws EntityNotFoundException, ArkSystemException {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    Person person = getPerson(personId);
    criteria.add(Restrictions.eq("person", person));
    criteria.add(Restrictions.eq("study", study));
    criteria.setMaxResults(1);/*from  ww  w . j a v a 2 s  .  c  o m*/
    return (LinkSubjectStudy) criteria.uniqueResult();
}

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

License:Open Source License

/**
 * Determines if study component with a given name is already present for a Study.
 * /*from  ww w .  j  av  a 2 s . c  o m*/
 * @param studyComponentName
 * @param study
 * @return
 */
public boolean isStudyComponentPresent(String studyComponentName, Study study) {
    boolean isPresent = false;
    Criteria criteria = getSession().createCriteria(StudyComp.class);
    criteria.add(Restrictions.eq("name", studyComponentName));
    criteria.add(Restrictions.eq("study", study));
    if (criteria.list() != null && criteria.list().size() > 0) {
        isPresent = true;
    }
    return isPresent;
}

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

License:Open Source License

public boolean isStudyCompUnique(String studyComponentName, Study study, StudyComp studyComponentToUpdate) {

    boolean isUnique = true;
    StatelessSession stateLessSession = getStatelessSession();
    Criteria criteria = stateLessSession.createCriteria(StudyComp.class);
    criteria.add(Restrictions.eq("name", studyComponentName));
    criteria.add(Restrictions.eq("study", study));
    criteria.setMaxResults(1);/*from  ww  w .java  2  s.  c  om*/

    StudyComp existingComponent = (StudyComp) criteria.uniqueResult();

    if ((studyComponentToUpdate.getId() != null && studyComponentToUpdate.getId() > 0)) {

        if (existingComponent != null && !studyComponentToUpdate.getId().equals(existingComponent.getId())) {
            isUnique = false;
        }
    } else {
        if (existingComponent != null) {
            isUnique = false;
        }
    }
    stateLessSession.close();
    return isUnique;

}

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

License:Open Source License

/**
 * The count can be based on CustomFieldDisplay only instead of a left join with it using SubjectCustomFieldData
 *///from  w w  w . j av a 2 s .  c o m
public long getSubjectCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cfield.customFieldType", "cfieldType", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("cfield.study", linkSubjectStudyCriteria.getStudy()));
    criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction));
    criteria.add(Restrictions.or(Restrictions.isNull("cfield.customFieldType"),
            Restrictions.eq("cfieldType.name", "SUBJECT")));
    criteria.setProjection(Projections.rowCount());

    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

/**
 * The count can be based on CustomFieldDisplay only instead of a left join with it using FamilyCustomFieldData
 *///from w  w  w  .ja va 2s  .  com
public long getFamilyCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cfield.customFieldType", "cfieldType", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("cfield.study", linkSubjectStudyCriteria.getStudy()));
    criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction));
    criteria.add(Restrictions.eq("cfieldType.name", "FAMILY"));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

public boolean isStudyComponentHasAttachments(StudyComp studyComp) {

    boolean isFlag = false;
    Criteria criteria = getStatelessSession().createCriteria(SubjectFile.class);
    criteria.add(Restrictions.eq("studyComp", studyComp));
    criteria.setProjection(Projections.rowCount());
    Long i = (Long) criteria.uniqueResult();
    if (i > 0L) {
        isFlag = true;/*from ww w .  j  a v a 2s . co m*/
    }
    return isFlag;
}