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.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public long getCFDLinkedToQuestionnaireCount(PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

/**
 * The method checks if the given questionnaire's fields have data linked to it.
 * //from  w w w . j  a v a 2 s .com
 * @param customFieldGroup
 */
public void isDataAvailableForQuestionnaire(CustomFieldGroup customFieldGroup) {

    Criteria criteria = getSession().createCriteria(CustomField.class, "cf");
    criteria.createAlias("customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldDisplay
    criteria.createAlias("cfd.customFieldGroup", "cfg", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldGroup
    criteria.add(Restrictions.eq("cf.study", customFieldGroup.getStudy()));

    ArkFunction function = iArkCommonService
            .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_DATA_DICTIONARY);
    criteria.add(Restrictions.eq("cf.arkFunction", function));
    criteria.add(Restrictions.eq("cfg.id", customFieldGroup.getId()));

    DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "pd");
    // Join CustomFieldDisplay and PhenoData on ID FK
    fieldDataCriteria.add(Property.forName("cfd.id").eqProperty("pd." + "customFieldDisplay.id"));
    criteria.add(
            Subqueries.exists(fieldDataCriteria.setProjection(Projections.property("pd.customFieldDisplay"))));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("cfg.name"), "questionnaire");
    projectionList.add(Projections.property("cf.name"), "fieldName");
    projectionList.add(Projections.property("cf.description"), "description");

}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public QuestionnaireStatus getPhenoCollectionStatusByName(String statusName) {
    Criteria criteria = getSession().createCriteria(QuestionnaireStatus.class);
    criteria.add(Restrictions.eq("name", statusName).ignoreCase());
    QuestionnaireStatus result = (QuestionnaireStatus) criteria.uniqueResult();
    return result;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public java.util.Collection<Upload> searchUpload(Upload upload) {
    Criteria criteria = getSession().createCriteria(Upload.class);

    if (upload.getId() != null) {
        criteria.add(Restrictions.eq(au.org.theark.phenotypic.web.Constants.UPLOAD_ID, upload.getId()));
    }//from   w ww. j a v  a 2  s . c o m

    if (upload.getStudy() != null) {
        criteria.add(Restrictions.eq(au.org.theark.phenotypic.web.Constants.UPLOAD_STUDY, upload.getStudy()));
    }

    if (upload.getArkFunction() != null) {
        criteria.add(Restrictions.eq("arkFunction", upload.getArkFunction()));
    }

    if (upload.getFileFormat() != null) {
        criteria.add(Restrictions.ilike(au.org.theark.phenotypic.web.Constants.UPLOAD_FILE_FORMAT,
                upload.getFileFormat()));
    }

    if (upload.getDelimiterType() != null) {
        criteria.add(Restrictions.ilike(au.org.theark.phenotypic.web.Constants.UPLOAD_DELIMITER_TYPE,
                upload.getDelimiterType()));
    }

    if (upload.getFilename() != null) {
        criteria.add(Restrictions.ilike(au.org.theark.phenotypic.web.Constants.UPLOAD_FILENAME,
                upload.getFilename()));
    }

    criteria.addOrder(Order.desc(au.org.theark.phenotypic.web.Constants.UPLOAD_ID));
    java.util.Collection<Upload> uploadCollection = criteria.list();

    return uploadCollection;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public Collection<CustomFieldGroup> getCustomFieldGroupList(Study study) {
    Criteria criteria = getSession().createCriteria(CustomFieldGroup.class);
    criteria.add(Restrictions.eq("study", study));
    Collection<CustomFieldGroup> result = criteria.list();
    return result;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public List<PhenoDataSetGroup> getPhenoDataSetGroupsByLinkSubjectStudy(LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("questionnaire"), "questionnaire");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetCollection.class));
    List<PhenoDataSetCollection> phenoDataSetCollections = (List<PhenoDataSetCollection>) criteria.list();
    List<PhenoDataSetGroup> phenoDataSetGroups = new ArrayList<PhenoDataSetGroup>();
    for (PhenoDataSetCollection phenoDataSetCollection : phenoDataSetCollections) {
        phenoDataSetGroups.add(phenoDataSetCollection.getQuestionnaire());
    }//from  w w w.j a  v  a 2  s . c o m
    return phenoDataSetGroups;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public CustomFieldGroup getCustomFieldGroupByNameAndStudy(String name, Study study) {
    Criteria criteria = getSession().createCriteria(CustomFieldGroup.class);
    criteria.add(Restrictions.eq("name", name));
    criteria.add(Restrictions.eq("study", study));

    CustomFieldGroup result = null;/*from  w ww. j  a v a2s  . c  om*/
    result = (CustomFieldGroup) criteria.uniqueResult();
    return result;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public List<PhenoDataSetCollection> getSubjectMatchingPhenoCollections(LinkSubjectStudy subject,
        PhenoDataSetGroup phenoDataSetGroup, Date recordDate) {
    log.info("subject " + subject.getSubjectUID());
    log.info("phenoDataSetGroup " + phenoDataSetGroup.getName());
    log.info("date: " + recordDate);
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.add(Restrictions.eq("linkSubjectStudy", subject));
    criteria.add(Restrictions.eq("questionnaire", phenoDataSetGroup));
    Calendar cal = Calendar.getInstance();
    cal.setTime(recordDate);//ww  w  . j  a  v a2  s  .c om

    //Removing the "Time" section of the Dates as that's not important in this context
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    Date low = cal.getTime();
    cal.add(Calendar.DATE, 1);
    Date high = cal.getTime();
    criteria.add(Restrictions.lt("recordDate", high));
    criteria.add(Restrictions.ge("recordDate", low));

    return criteria.list();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public PhenoDataSetCategory getPhenoDataSetCategory(Long id) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetCategory.class);
    criteria.add(Restrictions.eq("id", id));
    criteria.setMaxResults(1);/*ww w . ja v  a  2 s.c om*/
    return (PhenoDataSetCategory) criteria.uniqueResult();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetCategory> getAvailableAllCategoryList(Study study, ArkFunction arkFunction)
        throws ArkSystemException {
    Criteria criteria = getSession().createCriteria(PhenoDataSetCategory.class);
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("study", study));
    List<PhenoDataSetCategory> phenoDataSetCategoryList = (List<PhenoDataSetCategory>) criteria.list();
    return phenoDataSetCategoryList;
}