Example usage for org.hibernate.criterion Projections rowCount

List of usage examples for org.hibernate.criterion Projections rowCount

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections rowCount.

Prototype

public static Projection rowCount() 

Source Link

Document

The query row count, ie.

Usage

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

License:Open Source License

@Override
public boolean isAudited(Class<?> type) {
    Criteria criteria = getSession().createCriteria(AuditEntity.class);
    criteria.add(Restrictions.eq("classIdentifier", type.getName()));
    criteria.setProjection(Projections.rowCount());
    Long rowCount = (Long) criteria.uniqueResult();
    return rowCount != 0;
}

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 w w. j  a  va  2 s.c o m*/

    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 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 av a  2  s.co m
    return totalCount.intValue() > 0;
}

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();//  w  w w . ja  v a 2 s  .co 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();// w w  w .ja  v a  2s  . c om
    return totalCount.intValue() > 0;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) {
    // Use WHERE EXIST to optimise query even further
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss");
    DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc");
    criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId()));
    sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id"));
    criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id"))));
    criteria.setProjection(Projections.rowCount());
    Boolean result = ((Long) criteria.uniqueResult()) > 0L;
    session.close();/*from   ww  w . j av  a2  s.  com*/

    return result;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Boolean hasBiospecimens(BioCollection bioCollection) {
    // Use WHERE EXIST to optimise query even further
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(BioCollection.class, "bc");
    DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Biospecimen.class, "b");
    criteria.add(Restrictions.eq("bc.id", bioCollection.getId()));
    sizeCriteria.add(Property.forName("bc.id").eqProperty("b.bioCollection.id"));
    criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("b.id"))));
    criteria.setProjection(Projections.rowCount());
    Boolean result = ((Long) criteria.uniqueResult()) > 0L;
    session.close();/*w  ww  . java2 s  . c o m*/

    return result;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public long getBioCollectionCount(BioCollection bioCollectionCriteria) {
    // Handle for study not in context
    if (bioCollectionCriteria.getStudy() == null) {
        return 0;
    }/*w  ww. j a  va 2  s.c  om*/
    Criteria criteria = buildBioCollectionCriteria(bioCollectionCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

/**
 * This count can be based on CustomFieldDisplay alone (i.e. does not need left join to BioCollectionCustomFieldData)
 *///w w w .  j a v a  2 s  . c o  m
public long getBioCollectionCustomFieldDataCount(BioCollection bioCollectionCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield");
    //      criteria.add(Restrictions.eq("cfield.study", bioCollectionCriteria.getStudy()));

    // Added to allow child studies to inherit parent defined custom fields
    List studyList = new ArrayList();
    studyList.add(bioCollectionCriteria.getStudy());
    if (bioCollectionCriteria.getStudy().getParentStudy() != null
            && bioCollectionCriteria.getStudy().getParentStudy() != bioCollectionCriteria.getStudy()) {
        studyList.add(bioCollectionCriteria.getStudy().getParentStudy());
    }
    criteria.add(Restrictions.in("cfield.study", studyList));
    criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

public long getBiospecimenCount(Biospecimen biospecimenCriteria) {
    // Handle for study not in context
    if (biospecimenCriteria.getStudy() == null) {
        return 0;
    }/*w  w  w .jav  a2  s.c  o  m*/
    Criteria criteria = buildBiospecimenCriteria(biospecimenCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount.intValue();
}