Example usage for org.hibernate Criteria setMaxResults

List of usage examples for org.hibernate Criteria setMaxResults

Introduction

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

Prototype

public Criteria setMaxResults(int maxResults);

Source Link

Document

Set a limit upon the number of objects to be retrieved.

Usage

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

License:Open Source License

public InvCell getNextAvailableInvCell(InvBox invBox) {
    Criteria criteria = getSession().createCriteria(InvCell.class);
    criteria.add(Restrictions.eq("invBox", invBox));
    criteria.add(Restrictions.isNull("biospecimen"));
    criteria.setMaxResults(1);
    return (InvCell) criteria.list().get(0);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<LinkSubjectStudy> searchPageableSubjects(LimsVO limsVoCriteria, List<Study> studyList, int first,
        int count) {
    Criteria criteria = buildGeneralSubjectCriteria(limsVoCriteria, studyList);
    criteria.setFirstResult(first);/*from  w ww  .  j ava2s. co m*/
    criteria.setMaxResults(count);
    List<LinkSubjectStudy> subjectList = criteria.list();
    return subjectList;
}

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

License:Open Source License

public List<PhenoDataSetCollection> searchPageablePhenoCollection(PhenoDataCollectionVO collectionCriteria,
        int first, int count) {

    List<PhenoDataSetCollection> resultList = new ArrayList<PhenoDataSetCollection>();
    StringBuffer sb = new StringBuffer();
    sb.append("SELECT qnaire, pc ");
    sb.append("  FROM " + PhenoDataSetGroup.class.getName() + " AS qnaire ");
    sb.append("  LEFT JOIN qnaire.phenoDataSetCollections as pc ");
    sb.append("  WITH pc.linkSubjectStudy.id = :subjectId ");
    sb.append(" WHERE qnaire.study.id = :studyId ");
    //sb.append("   AND qnaire.arkFunction.id = :functionId ");
    sb.append("   AND qnaire.published = true ");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("subjectId",
            collectionCriteria.getPhenoDataSetCollection().getLinkSubjectStudy().getId());
    query.setParameter("studyId", collectionCriteria.getPhenoDataSetGroup().getStudy().getId());
    //log.info("colcrit ark=" + collectionCriteria.getArkFunction());
    //long id = collectionCriteria.getArkFunction().getId();
    //log.info("id=" + id);
    //query.setParameter("functionId",id);
    query.setFirstResult(first);//  w w w .j a v a  2  s  . c  o  m
    query.setMaxResults(count);

    List<Object[]> listOfObjects = query.list();
    for (Object[] objects : listOfObjects) {
        //CustomFieldGroup questionnaire = new CustomFieldGroup();
        PhenoDataSetGroup questionnaire = new PhenoDataSetGroup();
        PhenoDataSetCollection pc = new PhenoDataSetCollection();
        if (objects.length > 0 && objects.length >= 1) {
            questionnaire = (PhenoDataSetGroup) objects[0];
            if (objects[1] != null) {
                pc = (PhenoDataSetCollection) objects[1];
            } else {
                pc.setQuestionnaire(questionnaire);
            }
            resultList.add(pc);
        }
    }
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.createAlias("questionnaire", "qnaire");
    criteria.add(Restrictions.eq("linkSubjectStudy",
            collectionCriteria.getPhenoDataSetCollection().getLinkSubjectStudy()));
    // Just a precaution (PhenoCollection to should always map to a CustomFieldGroup where the ArkFunction will correspond to Pheno) 
    criteria.add(Restrictions.eq("qnaire.arkFunction", collectionCriteria.getArkFunction()));
    criteria.setFirstResult(first);
    criteria.setMaxResults(count);
    resultList = criteria.list();
    return resultList;
}

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

License:Open Source License

public Collection<PhenoDataSetFieldDisplay> getCFDLinkedToQuestionnaire(PhenoDataSetGroup phenoDataSetGroup,
        int first, int count) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    criteria.setFirstResult(first);//from   w ww .ja v a  2s .co m
    criteria.setMaxResults(count);
    criteria.addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    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);
    return (PhenoDataSetCategory) criteria.uniqueResult();
}

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

License:Open Source License

@Override
public List<PhenoDataSetCategory> searchPageablePhenoDataSetCategories(
        PhenoDataSetCategory phenoDataSetCategoryCriteria, int first, int count) {
    Criteria criteria = buildGeneralPhenoDataSetCategoryCritera(phenoDataSetCategoryCriteria);
    criteria.setFirstResult(first);//from www . j  ava 2 s.  co  m
    criteria.setMaxResults(count);
    criteria.addOrder(Order.asc("name"));
    List<PhenoDataSetCategory> phenoDataSetCategoryList = (List<PhenoDataSetCategory>) criteria.list();
    return phenoDataSetCategoryList;
}

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);

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

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

        if (existingPhenoDataSetCategory != null
                && !phenoDataSetCategoryToUpdate.getId().equals(existingPhenoDataSetCategory.getId())) {
            isUnique = false;//from ww  w  . j  ava  2 s  .  co m
        }
    } 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);
    return (PhenoDataSetField) criteria.uniqueResult();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<PhenoDataSetField> searchPageablePhenoFields(PhenoDataSetField phenoDataSetCriteria, int first,
        int count) {
    Criteria criteria = buildGeneralPhenoFieldCritera(phenoDataSetCriteria);
    criteria.setFirstResult(first);/*w w  w  . jav  a 2 s.  com*/
    criteria.setMaxResults(count);
    criteria.addOrder(Order.asc("name"));
    List<PhenoDataSetField> phenoDataSetList = (List<PhenoDataSetField>) criteria.list();
    return phenoDataSetList;
}

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);
    return (PhenoDataSetFieldDisplay) criteria.uniqueResult();
}