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

License:Open Source License

@Override
public long getPhenoDataSetCategoryCount(PhenoDataSetCategory phenoDataSetCategoryCriteria) {
    // Handle for study or function not in context
    if (phenoDataSetCategoryCriteria.getStudy() == null
            || phenoDataSetCategoryCriteria.getArkFunction() == null) {
        return 0;
    }/*  w  ww .  j  a v  a2  s .c  o m*/
    Criteria criteria = buildGeneralPhenoDataSetCategoryCritera(phenoDataSetCategoryCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

@Override
public boolean isPhenoDataSetCategoryUnique(String phenoDataSetCategoryName, Study study,
        PhenoDataSetCategory phenoDataSetCategoryToUpdate) {
    boolean isUnique = true;
    StatelessSession stateLessSession = getStatelessSession();
    Criteria criteria = stateLessSession.createCriteria(CustomFieldCategory.class);
    criteria.add(Restrictions.eq("name", phenoDataSetCategoryName));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkFunction", phenoDataSetCategoryToUpdate.getArkFunction()));
    criteria.setMaxResults(1);/*  w ww  .java 2 s. c o m*/

    PhenoDataSetCategory existingPhenoDataSetCategory = (PhenoDataSetCategory) criteria.uniqueResult();

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

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

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

License:Open Source License

public PhenoDataSetField getPhenoDataSetField(Long id) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetField.class);
    criteria.add(Restrictions.eq("id", id));
    criteria.setMaxResults(1);/*from ww w .  j a v a  2 s . c om*/
    return (PhenoDataSetField) criteria.uniqueResult();
}

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

License:Open Source License

public long getPhenoFieldCount(PhenoDataSetField phenofieldcriteria) {
    // Handle for study or function not in context
    if (phenofieldcriteria.getStudy() == null || phenofieldcriteria.getArkFunction() == null) {
        return 0;
    }//ww  w. ja v  a 2 s. c  o  m
    Criteria criteria = buildGeneralPhenoFieldCritera(phenofieldcriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

public PhenoDataSetFieldDisplay getPhenoDataSetFieldDisplayByPhenoDataSet(
        PhenoDataSetField pheDataSetFieldCriteria) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetField.id", pheDataSetFieldCriteria.getId()));
    criteria.setMaxResults(1);//  w  w w .j av a2 s  . c  o m
    return (PhenoDataSetFieldDisplay) criteria.uniqueResult();
}

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

License:Open Source License

public boolean isPhenoDataSetFieldUnqiue(String phenoFieldName, Study study,
        PhenoDataSetField phenoFieldToUpdate) {
    boolean isUnique = true;
    StatelessSession stateLessSession = getStatelessSession();
    Criteria criteria = stateLessSession.createCriteria(PhenoDataSetField.class);
    criteria.add(Restrictions.eq("name", phenoFieldName));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkFunction", phenoFieldToUpdate.getArkFunction()));
    criteria.setMaxResults(1);/* w w w. java  2  s .  c o m*/

    PhenoDataSetField existingField = (PhenoDataSetField) criteria.uniqueResult();

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

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

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

License:Open Source License

@Override
public PhenoDataSetFieldDisplay getPhenoDataSetFieldDisplayByPhenoDataSetFieldAndGroup(
        PhenoDataSetField phenoDataSetField, PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetField", phenoDataSetField));
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    criteria.setMaxResults(1);//from   w  ww .j  ava2 s  . c  o m
    return (PhenoDataSetFieldDisplay) criteria.uniqueResult();
}

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

License:Open Source License

@Override
public long getPhenoDataSetFieldGroupCount(PhenoDataSetGroup phenoDataSetGroup) {
    // Handle for study or function not in context
    if (phenoDataSetGroup.getStudy() == null || phenoDataSetGroup.getArkFunction() == null) {
        return 0L;
    }//from w ww . j a  v  a 2 s. c o m
    Criteria criteria = buildGenericPhenoDataSetFieldGroupCriteria(phenoDataSetGroup);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

@Override
public PickedPhenoDataSetCategory getPickedPhenoDataSetCategoryFromPhenoDataSetCategory(Study study,
        ArkFunction arkFunction, ArkUser arkUser, PhenoDataSetCategory phenoDataSetCategory) {
    Criteria criteria = getSession().createCriteria(PickedPhenoDataSetCategory.class);
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkUser", arkUser));
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    return (PickedPhenoDataSetCategory) criteria.uniqueResult();
}

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

License:Open Source License

@Override
public LinkPhenoDataSetCategoryField getLinkPhenoDataSetCategoryField(Study study, ArkFunction arkFunction,
        ArkUser arkUser, PhenoDataSetCategory phenoDataSetCategory, PhenoDataSetField phenoDataSetField) {
    Criteria criteria = getSession().createCriteria(LinkPhenoDataSetCategoryField.class);
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    criteria.add(Restrictions.eq("phenoDataSetField", phenoDataSetField));
    return (LinkPhenoDataSetCategoryField) criteria.uniqueResult();

}