Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

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

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

From source file:es.urjc.mctwp.dao.GroupDAO.java

License:Open Source License

/**
 * Get the groups of a trial by filter conditions
 *  /*from   w  ww . j a  v a  2s . c o m*/
 * @param trial
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<Group> findGroupsByTrialFiltered(Trial trial, Group filter) {
    List<Group> result = null;
    Criteria criteria = null;
    String[] exclude = { "oid" };

    //Create the criteria search
    criteria = this.getSession().createCriteria(Group.class);

    //Create example query based on filter
    if (filter != null) {
        Example example = createExample(filter, exclude);
        criteria.add(example);
    }

    //Create criteria relation based on trial
    if (trial != null) {
        criteria.createCriteria("trial").add(Restrictions.eq("code", trial.getCode()));
    }

    //Search
    try {
        result = criteria.list();
    } catch (RuntimeException re) {
        logErrMsg("findGroupsByTrial", re);
        throw re;
    }

    return result;
}

From source file:es.urjc.mctwp.dao.PatientDAO.java

License:Open Source License

/**
 * Get the patients of a group by filter conditions
 *  //w  w w  . j av  a 2  s .  co  m
 * @param group
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<Patient> findPatientsByGroupFiltered(Group group, Patient filter) {
    List<Patient> result = null;
    Criteria criteria = null;
    String[] exclude = { "oid" };

    //Create the criteria search
    criteria = this.getSession().createCriteria(Patient.class);

    //Create example query based on filter
    if (filter != null) {
        Example example = createExample(filter, exclude);
        criteria.add(example);
    }

    //Create criteria relation based on group
    if (group != null) {
        criteria.createCriteria("group").add(Restrictions.eq("code", group.getCode()));
    }

    //Search
    try {
        result = criteria.list();
    } catch (RuntimeException re) {
        logErrMsg("findPatientsByGroup", re);
        throw re;
    }

    return result;
}

From source file:es.urjc.mctwp.dao.StudyDAO.java

License:Open Source License

/**
 * Get the studies of a patient by filter conditions
 *  //from w w w  . ja v a  2s  .c o m
 * @param patient
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<Study> findStudiesByPatientFiltered(Patient patient, Study filter) {
    List<Study> result = null;
    Criteria criteria = null;
    String[] exclude = { "oid" };

    //Create the criteria search
    criteria = this.getSession().createCriteria(Study.class);

    //Create example query based on filter
    if (filter != null) {
        Example example = createExample(filter, exclude);
        criteria.add(example);
    }

    //Create criteria relation based on trial
    if (patient != null) {
        criteria.createCriteria("patient").add(Restrictions.eq("code", patient.getCode()));
    }

    //Search
    try {
        result = criteria.list();
    } catch (RuntimeException re) {
        logErrMsg("findStudiesByPatient", re);
        throw re;
    }

    return result;
}

From source file:es.urjc.mctwp.dao.TrialDAO.java

License:Open Source License

/**
 * find all trials where user participate in, filtered
 * //from  w w  w . j a  v a  2 s.c o  m
 * @param usuario
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<Trial> findTrialsByUserFiltered(User usuario, Trial filter) {
    List<Trial> result = null;
    Criteria criteria = null;
    String[] exclude = { "oid" };

    //Create the criteria search
    criteria = this.getSession().createCriteria(Trial.class);

    //Create example query based on filter
    if (filter != null) {
        Example example = createExample(filter, exclude);
        criteria.add(example);
    }

    //Create criteria relation based on User
    if (usuario != null) {
        Example exPart = createExample(new Participation(), exclude);
        Criteria crPart = criteria.createCriteria("members").add(exPart);

        Example exUser = createExample(usuario, exclude);
        crPart.createCriteria("user").add(exUser);
    }

    //Search
    try {
        result = criteria.list();
    } catch (RuntimeException re) {
        logErrMsg("findTrialsByUser", re);
        throw re;
    }

    return result;
}

From source file:es.urjc.mctwp.service.commands.researchCmds.FindTasks.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public ResultCommand<List<Task>> runCommand() {
    Session sesion = sf.getCurrentSession();
    Criteria criteria = sesion.createCriteria(Task.class);

    if (startDate != null)
        criteria.add(Restrictions.ge("endDate", startDate));

    if (endDate != null)
        criteria.add(Restrictions.le("endDate", endDate));

    if (owner != null)
        criteria.createCriteria("owner").add(Restrictions.eq("code", owner));

    if (process != null)
        criteria.createCriteria("process").add(Restrictions.eq("code", process));

    if (taskState != null)
        criteria.add(Restrictions.eq("status", taskState));

    this.setResult(criteria.list());
    return this;
}

From source file:gov.nih.nci.caarray.dao.ArrayDaoImpl.java

License:BSD License

/**
 * {@inheritDoc}/* w  ww .  j  a  v  a  2  s.  com*/
 */
@Override
@SuppressWarnings({ "unchecked", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" })
public List<QuantitationType> searchForQuantitationTypes(PageSortParams<QuantitationType> params,
        QuantitationTypeSearchCriteria criteria) {
    final Criteria c = getCurrentSession().createCriteria(HybridizationData.class);
    c.createCriteria("hybridization").add(Restrictions.eq("id", criteria.getHybridization().getId()));
    c.createCriteria("dataSet").createAlias("quantitationTypes", "qt").createAlias("arrayData", "ad");
    c.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

    if (!criteria.getArrayDataTypes().isEmpty()) {
        final List<Long> ids = new LinkedList<Long>();
        for (final ArrayDataType type : criteria.getArrayDataTypes()) {
            ids.add(type.getId());
        }
        c.createCriteria("ad.type").add(Restrictions.in("id", ids));
    }

    if (!criteria.getFileTypes().isEmpty() || !criteria.getFileCategories().isEmpty()) {
        c.createAlias("ad.dataFile", "df");
    }

    if (!criteria.getFileTypes().isEmpty()) {
        c.add(Restrictions.in("df.type",
                Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(criteria.getFileTypes()))));
    }

    if (!criteria.getFileCategories().isEmpty()) {
        final Disjunction categoryCriterion = Restrictions.disjunction();
        if (criteria.getFileCategories().contains(FileCategory.DERIVED_DATA)) {
            categoryCriterion.add(Restrictions.in("df.type", Sets.newHashSet(
                    FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getDerivedArrayDataTypes()))));
        }
        if (criteria.getFileCategories().contains(FileCategory.RAW_DATA)) {
            categoryCriterion.add(Restrictions.in("df.type", Sets
                    .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getRawArrayDataTypes()))));
        }
        c.add(categoryCriterion);
    }

    c.setFirstResult(params.getIndex());
    if (params.getPageSize() > 0) {
        c.setMaxResults(params.getPageSize());
    }
    c.addOrder(toOrder(params, "qt"));

    final List<Map<String, Object>> results = c.list();
    final List<QuantitationType> qTypes = SetUniqueList.decorate(new LinkedList<QuantitationType>());
    for (final Map<String, Object> row : results) {
        final QuantitationType qt = (QuantitationType) row.get("qt");
        qTypes.add(qt);
    }
    return qTypes;
}

From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java

License:BSD License

/**
 * {@inheritDoc}//from   www.  jav a2  s  . c  o m
 */
@Override
public Project getProjectByPublicId(String publicId) {
    final Criteria c = getCurrentSession().createCriteria(Project.class);
    c.createCriteria("experiment").add(Restrictions.eq("publicIdentifier", publicId).ignoreCase());
    return (Project) c.uniqueResult();
}

From source file:gov.nih.nci.cabig.caaers.dao.StudyDao.java

License:BSD License

/**
 * TODO kkk//  w w  w  . j  a  va 2s.  com
 *
 * @param study
 * @param isWildCard
 * @return
 */
@Override
// TODO - Need to refactor the below into CaaersDao along with identifiers
public List<Study> searchByExample(final Study study, final boolean isWildCard) {
    Example example = Example.create(study).excludeZeroes().ignoreCase();
    Criteria studyCriteria = getSession().createCriteria(LocalStudy.class);
    studyCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    if (isWildCard) {
        example.excludeProperty("multiInstitutionIndicator").enableLike(MatchMode.ANYWHERE);
        studyCriteria.add(example);
        if (study.getIdentifiers().size() > 0) {
            studyCriteria.createCriteria("identifiers")
                    .add(Restrictions.ilike("value", study.getIdentifiers().get(0).getValue() + "%"));
        }
        if (study.getStudyOrganizations().size() > 0) {
            studyCriteria.createCriteria("studyOrganizations").add(Restrictions.eq("organization.id",
                    study.getStudyOrganizations().get(0).getOrganization().getId()));
        }
        return studyCriteria.list();
    }
    return studyCriteria.add(example).list();
}

From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java

License:BSD License

/**
 * {@inheritDoc}//from   w ww. j a  va 2  s.  c  o m
 */
@Override
@SuppressWarnings(UNCHECKED) // Hibernate operations are untyped
public List<UserWorkspace> retrieveAllSubscribedWorkspaces(Study study) {
    Criteria workspaceCriteria = getCurrentSession().createCriteria(UserWorkspace.class);
    workspaceCriteria.createCriteria("subscriptionCollection").add(Restrictions.eq(STUDY_ASSOCIATION, study));
    return workspaceCriteria.list();
}

From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java

License:BSD License

/**
 * {@inheritDoc}//w w  w.  ja v a2 s.  c o  m
 */
@Override
@SuppressWarnings(UNCHECKED) // Hibernate operations are untyped
public List<ImageSeries> findMatchingImageSeries(AbstractAnnotationCriterion criterion, Study study) {
    if (!criterion.getEntityType().equals(EntityTypeEnum.IMAGESERIES)) {
        return new ArrayList<ImageSeries>();
    }
    Criteria imageSeriesCrit = getCurrentSession().createCriteria(ImageSeries.class);
    if (criterion instanceof IdentifierCriterion) {
        imageSeriesCrit.add(AbstractAnnotationCriterionHandler.create(criterion).translate());
    } else {
        createAnnotationValuesCriteria(criterion, imageSeriesCrit, ANNOTATION_VALUE_COLLECTION_ASSOCIATION);
    }
    createStudySubjectAssignmentCriteria(imageSeriesCrit.createCriteria(IMAGE_SERIES_ACQUISITION_ASSOCIATION)
            .createCriteria(STUDY_SUBJECT_ASSIGNMENT_ASSOCIATION), study);

    return imageSeriesCrit.list();
}