Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

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

Prototype

public Object uniqueResult() throws HibernateException;

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

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

License:Open Source License

private String getPhenoCollectionName(String collectionID) {
    Criteria c = getSession().createCriteria(PhenoDataSetCollection.class, "p");
    c.add(Restrictions.eq("p.id", Long.parseLong(collectionID)));

    PhenoDataSetCollection pc = (PhenoDataSetCollection) c.uniqueResult();
    return pc.getQuestionnaire().getName();
}

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 w w w  .j a v a2  s  . co m*/
 * 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 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");
    }//from   w w w . ja v a 2 s.co m
    return subject;
}

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

License:Open Source License

public long getStudySubjectCount(SubjectVO subjectVO) {
    // Handle for study not in context
    // GEORGE - 30/1/15 Removed handle to allow for global search. Need to test to see if this fails anywhere.
    //      if (subjectVO.getLinkSubjectStudy().getStudy() == null) {
    //         return 0;
    //      }//from w ww .j av a2s  . c om

    Criteria criteria = buildGeneralSubjectCriteria(subjectVO);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount.intValue();
}

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

License:Open Source License

public ArkFunctionType getArkFunctionType(String reportType) {
    Criteria criteria = getSession().createCriteria(ArkFunctionType.class);
    criteria.add(Restrictions.eq("name", reportType));
    criteria.setMaxResults(1);//from   w  w  w  .  j ava  2 s .  c om
    return (ArkFunctionType) criteria.uniqueResult();
}

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

License:Open Source License

public Boolean studyHasSubjects(Study study) {
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    session.close();/*from   w  w  w.  j a v  a  2 s .c o  m*/
    return totalCount.intValue() > 0;
}

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

License:Open Source License

public String getDelimiterTypeNameByDelimiterChar(char delimiterCharacter) {
    String delimiterTypeName = null;
    Criteria criteria = getSession().createCriteria(DelimiterType.class);
    criteria.add(Restrictions.eq("delimiterCharacter", delimiterCharacter));
    criteria.setProjection(Projections.property("name"));
    delimiterTypeName = (String) criteria.uniqueResult();
    return delimiterTypeName;
}

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

License:Open Source License

public DelimiterType getDelimiterTypeByDelimiterChar(char delimiterCharacter) {
    Criteria criteria = getSession().createCriteria(DelimiterType.class);
    criteria.add(Restrictions.eq("delimiterCharacter", delimiterCharacter));
    return (DelimiterType) criteria.uniqueResult();
}

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

License:Open Source License

public Boolean studyHasBiospecimen(Study study) {
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(Biospecimen.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    session.close();/*from  w  w w .j a v a  2  s. c  o  m*/
    return totalCount.intValue() > 0;
}

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

License:Open Source License

public Boolean studyHasBioCollection(Study study) {
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(BioCollection.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    session.close();/*  ww w. jav a  2s. c om*/
    return totalCount.intValue() > 0;
}