Example usage for org.hibernate.criterion DetachedCriteria setFetchMode

List of usage examples for org.hibernate.criterion DetachedCriteria setFetchMode

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria setFetchMode.

Prototype

public DetachedCriteria setFetchMode(String associationPath, FetchMode mode) 

Source Link

Document

Set the fetch mode for a given association

Usage

From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w  ww  . j a  v  a 2s.  c o m*/
public List<MyCalendarEvent> getCalendarEventsForBeginDate(Date beginDate, long usrId) {
    DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class);
    criteria.add(Restrictions.eq("beginDate", beginDate));
    criteria.add(Restrictions.eq("secUser.id", usrId));
    criteria.setFetchMode("secUser", FetchMode.JOIN);

    return getHibernateTemplate().findByCriteria(criteria);
}

From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   ww  w. j a  va 2  s .  co m
public List<MyCalendarEvent> getCalendarEventsFromToDate(Date beginDate, Date endDate, long usrId) {
    DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class);
    criteria.add(Restrictions.ge("beginDate", beginDate));
    criteria.add(Restrictions.le("endDate", endDate));
    criteria.add(Restrictions.eq("secUser.id", usrId));
    criteria.setFetchMode("secUser", FetchMode.JOIN);

    return getHibernateTemplate().findByCriteria(criteria);
}

From source file:fr.gael.dhus.service.UserService.java

License:Open Source License

/**
 * Retrieves corresponding users at the given criteria.
 *
 * @param criteria criteria contains filter and order of required collection.
 * @param skip     number of skipped valid results.
 * @param top      max of valid results.
 * @return a list of {@link User}//from ww w. ja  va  2  s . c o  m
 */
@Transactional(readOnly = true)
public List<User> getUsers(DetachedCriteria criteria, int skip, int top) {
    if (criteria == null) {
        criteria = DetachedCriteria.forClass(User.class);
    }
    criteria.setFetchMode("roles", FetchMode.SELECT);
    criteria.setFetchMode("restrictions", FetchMode.SELECT);
    List<User> result = userDao.listCriteria(criteria, skip, top);
    return result;
}

From source file:gov.nih.nci.cabio.annotations.ArrayAnnotationServiceImpl.java

License:BSD License

public List<CytobandPhysicalLocation> getCytobandPositions(String chromosomeNumber, String assembly)
        throws ApplicationException {

    DetachedCriteria criteria = DetachedCriteria.forClass(CytobandPhysicalLocation.class);

    criteria.setFetchMode("cytoband", FetchMode.JOIN);
    criteria.setFetchMode("chromosome", FetchMode.JOIN);

    criteria.add(Restrictions.eq("assembly", assembly));

    criteria.createCriteria("chromosome").add(Restrictions.eq("number", chromosomeNumber))
            .createCriteria("taxon").add(Restrictions.eq("abbreviation", taxon));

    List<CytobandPhysicalLocation> results = appService.query(criteria);
    return results;
}

From source file:gov.nih.nci.cabio.annotations.ArrayAnnotationServiceImpl.java

License:BSD License

public Collection<GeneAlias> getAliasesForGene(String symbol) throws ApplicationException {

    DetachedCriteria criteria = DetachedCriteria.forClass(Gene.class);

    criteria.setFetchMode("geneAliasCollection", FetchMode.JOIN)
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    criteria.add(Restrictions.eq("hugoSymbol", symbol).ignoreCase());
    criteria.createCriteria("taxon").add(Restrictions.eq("abbreviation", taxon));

    List<Gene> genes = appService.query(criteria);
    if (genes.isEmpty())
        throw new ApplicationException("No gene exists with HUGO symbol " + symbol);

    List<GeneAlias> results = new ArrayList<GeneAlias>();
    for (Gene g : genes) {
        results.addAll(g.getGeneAliasCollection());
    }/* www.java  2  s.  c  om*/

    return results;
}

From source file:gov.nih.nci.cananolab.service.admin.impl.OwnershipTransferServiceImpl.java

License:BSD License

private Sample findFullyLoadedSampleById(String sampleId) throws Exception {
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();/*from  w w  w.java  2  s  .c o m*/
    // load composition and characterization separate because of Hibernate
    // join limitation
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("id").eq(new Long(sampleId)));
    Sample sample = null;

    // load composition and characterization separate because of
    // Hibernate join limitation
    crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
    crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.authorCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
        sample = (Sample) result.get(0);
    }
    if (sample == null) {
        throw new NotExistException("Sample doesn't exist in the database");
    }

    // fully load composition
    SampleComposition comp = this.loadComposition(sample.getId().toString());
    sample.setSampleComposition(comp);

    // fully load characterizations
    List<Characterization> chars = this.loadCharacterizations(sample.getId().toString());
    if (chars != null && !chars.isEmpty()) {
        sample.setCharacterizationCollection(new HashSet<Characterization>(chars));
    } else {
        sample.setCharacterizationCollection(null);
    }
    return sample;
}

From source file:gov.nih.nci.cananolab.service.admin.impl.OwnershipTransferServiceImpl.java

License:BSD License

private SampleComposition loadComposition(String sampleId) throws Exception {
    SampleComposition composition = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();/*w  ww .  j a  v  a  2s. c  om*/
    DetachedCriteria crit = DetachedCriteria.forClass(SampleComposition.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    crit.setFetchMode("nanomaterialEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection",
            FetchMode.JOIN);
    crit.setFetchMode(
            "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection.targetCollection",
            FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.functionCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.functionCollection.targetCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.activationMethod", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);

    if (!result.isEmpty()) {
        composition = (SampleComposition) result.get(0);
    }
    return composition;
}

From source file:gov.nih.nci.cananolab.service.admin.impl.OwnershipTransferServiceImpl.java

License:BSD License

private List<Characterization> loadCharacterizations(String sampleId) throws Exception {
    List<Characterization> chars = new ArrayList<Characterization>();

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();//from   w ww .  j  a v a  2s.co  m
    DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    // fully load characterization
    crit.setFetchMode("pointOfContact", FetchMode.JOIN);
    crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("protocol", FetchMode.JOIN);
    crit.setFetchMode("protocol.file", FetchMode.JOIN);
    crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);

    for (int i = 0; i < results.size(); i++) {
        Characterization achar = (Characterization) results.get(i);
        chars.add(achar);
    }
    return chars;
}

From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java

License:BSD License

public List<Protocol> findProtocolsBy(String protocolType, String protocolName, String protocolAbbreviation,
        String fileTitle) throws Exception {
    List<Protocol> protocols = new ArrayList<Protocol>();
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();/*  w  w w .j  ava2  s.  c  o m*/
    DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class);
    crit.createAlias("file", "file", CriteriaSpecification.LEFT_JOIN);

    crit.setFetchMode("file.keywordCollection", FetchMode.JOIN);
    if (!StringUtils.isEmpty(protocolType)) {
        // case insensitive
        crit.add(Restrictions.ilike("type", protocolType, MatchMode.EXACT));
    }
    if (!StringUtils.isEmpty(protocolName)) {
        TextMatchMode protocolNameMatchMode = new TextMatchMode(protocolName);
        crit.add(Restrictions.ilike("name", protocolNameMatchMode.getUpdatedText(),
                protocolNameMatchMode.getMatchMode()));
    }
    if (!StringUtils.isEmpty(protocolAbbreviation)) {
        TextMatchMode protocolAbbreviationMatchMode = new TextMatchMode(protocolAbbreviation);
        crit.add(Restrictions.ilike("abbreviation", protocolAbbreviationMatchMode.getUpdatedText(),
                protocolAbbreviationMatchMode.getMatchMode()));
    }
    if (!StringUtils.isEmpty(fileTitle)) {
        TextMatchMode titleMatchMode = new TextMatchMode(fileTitle);
        crit.add(Restrictions.ilike("file.title", titleMatchMode.getUpdatedText(),
                titleMatchMode.getMatchMode()));
    }
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    for (int i = 0; i < results.size(); i++) {
        Protocol protocol = (Protocol) results.get(i);
        if (springSecurityAclService.currentUserHasReadPermission(protocol.getId(),
                SecureClassesEnum.PROTOCOL.getClazz())
                || springSecurityAclService.currentUserHasWritePermission(protocol.getId(),
                        SecureClassesEnum.PROTOCOL.getClazz())) {
            protocols.add(protocol);
        } else {
            logger.debug("User doesn't have access ot protocol with id " + protocol.getId());
        }
    }
    return protocols;
}

From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java

License:BSD License

public Protocol findProtocolBy(String protocolType, String protocolName, String protocolVersion)
        throws Exception {
    // protocol type and protocol name are required
    if (StringUtils.isEmpty(protocolType) && StringUtils.isEmpty(protocolName)) {
        return null;
    }//w  ww. j ava 2  s .c om
    Protocol protocol = null;
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class)
            .add(Property.forName("type").eq(protocolType).ignoreCase())
            .add(Property.forName("name").eq(protocolName).ignoreCase());
    if (!StringUtils.isEmpty(protocolVersion)) {
        crit.add(Property.forName("version").eq(protocolVersion).ignoreCase());
    }
    crit.setFetchMode("file", FetchMode.JOIN);
    crit.setFetchMode("file.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    if (results.isEmpty()) {
        return null;
    }
    if (results.size() > 1) {
        return null;
    }
    protocol = (Protocol) results.get(0);

    if (springSecurityAclService.currentUserHasReadPermission(protocol.getId(),
            SecureClassesEnum.PROTOCOL.getClazz())
            || springSecurityAclService.currentUserHasWritePermission(protocol.getId(),
                    SecureClassesEnum.PROTOCOL.getClazz())) {
        return protocol;
    } else {
        throw new NoAccessException();
    }
}