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.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();/*w ww . ja va2 s .  c  o  m*/
    return totalCount.intValue() > 0;
}

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

License:Open Source License

public List<Study> getStudiesForUser(ArkUser arkUser, Study study) {

    Criteria criteria = getSession().createCriteria(ArkUserRole.class);
    criteria.createAlias("arkStudy", "arkStudy");

    criteria.add(Restrictions.eq("arkUser", arkUser));// Represents the user
    // either who is
    // logged in or one
    // that is provided
    if (study.getId() != null) {
        criteria.add(Restrictions.eq("arkStudy.id", study.getId()));
    }//  www .  j a  v  a 2 s .co  m

    if (study.getName() != null) {
        criteria.add(Restrictions.ilike("arkStudy.name", study.getName(), MatchMode.ANYWHERE));
    }
    criteria.setProjection(Projections.distinct(Projections.property("study")));
    List<Study> studies = (List<Study>) criteria.list();
    return studies;

}

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

License:Open Source License

public FileFormat getFileFormatByName(String name) {
    FileFormat fileFormat = null;//from  ww w  . j  a v a 2  s.  c  om
    Criteria criteria = getSession().createCriteria(FileFormat.class);
    criteria.add(Restrictions.eq("name", name));

    List<FileFormat> results = criteria.list();
    if (results.size() > 0) {
        fileFormat = (FileFormat) results.get(0);
    }
    return fileFormat;
}

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

License:Open Source License

public List<Upload> searchUploads(Upload uploadCriteria) {
    Criteria criteria = getSession().createCriteria(Upload.class);
    // Must be constrained on the arkFunction
    criteria.add(Restrictions.eq("arkFunction", uploadCriteria.getArkFunction()));

    if (uploadCriteria.getId() != null) {
        criteria.add(Restrictions.eq("id", uploadCriteria.getId()));
    }/*  w ww.  j  ava 2 s  .  com*/

    if (uploadCriteria.getStudy() != null) {
        criteria.add(Restrictions.eq("study", uploadCriteria.getStudy()));
    }

    if (uploadCriteria.getFileFormat() != null) {
        criteria.add(Restrictions.ilike("fileFormat", uploadCriteria.getFileFormat()));
    }

    if (uploadCriteria.getDelimiterType() != null) {
        criteria.add(Restrictions.ilike("delimiterType", uploadCriteria.getDelimiterType()));
    }

    if (uploadCriteria.getFilename() != null) {
        criteria.add(Restrictions.ilike("filename", uploadCriteria.getFilename()));
    }

    criteria.addOrder(Order.desc("id"));
    List<Upload> resultsList = criteria.list();

    return resultsList;
}

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

License:Open Source License

public List<Upload> searchUploadsForBio(Upload uploadCriteria) {
    Criteria criteria = getSession().createCriteria(Upload.class);
    // - due to nature of table design...we need to specify it like this
    // ideally we might want to just have arkmodule in the upload table?
    // criteria.add(Restrictions.eq("arkFunction",
    // uploadCriteria.getArkFunction()));

    ArkFunction biospecArkFunction = getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN);
    //ArkFunction biocollArkFunction = getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_COLLECTION);
    ArkFunction biocollArkFunction = getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD);

    List<ArkFunction> arkFunctionsForBio = new ArrayList<ArkFunction>();
    arkFunctionsForBio.add(biospecArkFunction);
    arkFunctionsForBio.add(biocollArkFunction);

    criteria.add(Restrictions.in("arkFunction", arkFunctionsForBio));

    if (uploadCriteria.getId() != null) {
        criteria.add(Restrictions.eq("id", uploadCriteria.getId()));
    }//from ww  w. j  a  v  a 2  s  .  c  om

    if (uploadCriteria.getStudy() != null) {
        criteria.add(Restrictions.eq("study", uploadCriteria.getStudy()));
    }

    if (uploadCriteria.getFileFormat() != null) {
        criteria.add(Restrictions.ilike("fileFormat", uploadCriteria.getFileFormat()));
    }

    if (uploadCriteria.getDelimiterType() != null) {
        criteria.add(Restrictions.ilike("delimiterType", uploadCriteria.getDelimiterType()));
    }

    if (uploadCriteria.getFilename() != null) {
        criteria.add(Restrictions.ilike("filename", uploadCriteria.getFilename()));
    }

    criteria.addOrder(Order.desc("id"));
    List<Upload> resultsList = criteria.list();

    return resultsList;
}

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

License:Open Source License

public List<Upload> searchUploadsForBiospecimen(Upload uploadCriteria, List studyListForUser) {
    Criteria criteria = getSession().createCriteria(Upload.class);
    // - due to nature of table design...we need to specify it like this
    // ideally we might want to just have arkmodule in the upload table?
    // criteria.add(Restrictions.eq("arkFunction",
    // uploadCriteria.getArkFunction()));

    ArkFunction biospecArkFunction = getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN);

    List<ArkFunction> arkFunctionsForBio = new ArrayList<ArkFunction>();
    arkFunctionsForBio.add(biospecArkFunction);

    criteria.add(Restrictions.eq("arkFunction", uploadCriteria.getArkFunction()));

    if (uploadCriteria.getId() != null) {
        criteria.add(Restrictions.eq("id", uploadCriteria.getId()));
    }//from  w w w  . j a v  a  2 s. co  m

    if (!studyListForUser.isEmpty()) {
        criteria.add(Restrictions.in("study", studyListForUser));
    }

    if (uploadCriteria.getFileFormat() != null) {
        criteria.add(Restrictions.ilike("fileFormat", uploadCriteria.getFileFormat()));
    }

    if (uploadCriteria.getDelimiterType() != null) {
        criteria.add(Restrictions.ilike("delimiterType", uploadCriteria.getDelimiterType()));
    }

    if (uploadCriteria.getFilename() != null) {
        criteria.add(Restrictions.ilike("filename", uploadCriteria.getFilename()));
    }

    criteria.addOrder(Order.desc("id"));
    List<Upload> resultsList = criteria.list();

    return resultsList;
}

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  ww. j  a v  a2 s.  c  om*/
    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 ww .j  a  v a2  s  .  com*/
    return totalCount.intValue() > 0;
}