Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

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

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

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

License:Open Source License

@Override
public List<StudyComp> getDifferentStudyComponentsInConsentForSubject(Study study,
        LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getSession().createCriteria(Consent.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("studyComp"));
    criteria.setProjection(projectionList);
    criteria.addOrder(Order.asc("id"));
    List<StudyComp> fieldsList = criteria.list();
    return fieldsList;
}

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();//  www . ja v a2  s .  c  o  m

    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();/*from   ww w.  ja  va 2  s  .co 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;
    }// ww w  .  j  a  v a 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)
 *///from  w ww  .ja v a 2  s .co  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. ja v  a  2 s .co m*/
    Criteria criteria = buildBiospecimenCriteria(biospecimenCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount.intValue();
}

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

License:Open Source License

public long getBiospecimenCount(LimsVO limsVo) {
    Criteria criteria = buildBiospecimenCriteria(limsVo);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount.intValue();
}

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

License:Open Source License

public long getBiospecimenCustomFieldDataCount(Biospecimen biospecimenCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield");

    // Allow child studies to inherit parent defined custom fields
    List studyList = new ArrayList();
    studyList.add(biospecimenCriteria.getStudy());
    if (biospecimenCriteria.getStudy().getParentStudy() != null
            && biospecimenCriteria.getStudy().getParentStudy() != biospecimenCriteria.getStudy()) {
        studyList.add(biospecimenCriteria.getStudy().getParentStudy());
    }//from   ww w . jav  a2  s  .  c o m

    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 Double getQuantityAvailable(Biospecimen biospecimen) {
    Criteria criteria = getSession().createCriteria(BioTransaction.class);
    criteria.add(Restrictions.eq("biospecimen", biospecimen));
    criteria.setProjection(Projections.sum("quantity"));
    Double sum = (Double) criteria.uniqueResult();
    return sum;/*from   w w w  . j ava2 s.c o m*/
}

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

License:Open Source License

public boolean studyHasBiospecimens(Study study) {
    Criteria criteria = getSession().createCriteria(Biospecimen.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.setProjection(Projections.count("id"));
    Long count = (Long) criteria.uniqueResult();
    return count > 0;
}