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:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java

License:BSD License

public Characterization findCharacterizationById(String charId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(charId),
            SecureClassesEnum.CHAR.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(charId),
                    SecureClassesEnum.CHAR.getClazz())) {
        new NoAccessException("User has no access to the characterization " + charId);
    }//from  ww w.  j  av a  2  s.  c  om
    Characterization achar = null;
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class)
            .add(Property.forName("id").eq(new Long(charId)));
    // 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 result = appService.query(crit);
    if (!result.isEmpty()) {
        achar = (Characterization) result.get(0);
        checkAssociatedVisibility(achar);
    }
    return achar;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java

License:BSD License

public Finding findFindingById(String findingId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(findingId),
            SecureClassesEnum.FINDING.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(findingId),
                    SecureClassesEnum.FINDING.getClazz())) {
        new NoAccessException("User has no access to the finding " + findingId);
    }//from  w w w.  java2  s . com
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Finding.class)
            .add(Property.forName("id").eq(new Long(findingId)));
    crit.setFetchMode("datumCollection", FetchMode.JOIN);
    crit.setFetchMode("datumCollection.conditionCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    Finding finding = null;
    if (!result.isEmpty()) {
        finding = (Finding) result.get(0);
        if (finding.getFileCollection() != null) {
            removeUnaccessibleFiles(finding.getFileCollection());
        }
    }
    return finding;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public Function findFunctionById(String funcId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(funcId),
            SecureClassesEnum.FUNCTION.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(funcId),
                    SecureClassesEnum.FUNCTION.getClazz())) {
        new NoAccessException("User has no access to the function " + funcId);
    }//  w w  w.  j a v a2  s  .  c  o  m
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Function.class)
            .add(Property.forName("id").eq(new Long(funcId)));
    crit.setFetchMode("targetCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    Function func = null;
    if (!result.isEmpty()) {
        func = (Function) result.get(0);
    }
    return func;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public ComposingElement findComposingElementById(String ceId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(ceId),
            SecureClassesEnum.COMPOSINGELEMENT.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(ceId),
                    SecureClassesEnum.COMPOSINGELEMENT.getClazz())) {
        new NoAccessException("User has no access to the composing element " + ceId);
    }/*from  ww w .  j  a  v a2 s.  co  m*/
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(ComposingElement.class)
            .add(Property.forName("id").eq(new Long(ceId)));
    crit.setFetchMode("inherentFunctionCollection", FetchMode.JOIN);
    crit.setFetchMode("inherentFunctionCollection.targetCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    ComposingElement ce = null;
    if (!result.isEmpty()) {
        ce = (ComposingElement) result.get(0);
    }
    return ce;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public SampleComposition findCompositionBySampleId(String sampleId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the sample " + sampleId);
    }//  ww w  .  ja v a  2  s .  com
    SampleComposition composition = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    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);
        /*if (!springSecurityAclService.currentUserHasReadPermission(composition.getId(), SecureClassesEnum.COMPOSITION.getClazz()) &&
           !springSecurityAclService.currentUserHasWritePermission(composition.getId(), SecureClassesEnum.COMPOSITION.getClazz())) {
           throw new NoAccessException("User doesn't have access to the composition " + composition.getId());
        }*/
    }
    return composition;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public NanomaterialEntity findNanomaterialEntityById(String sampleId, String entityId) throws Exception {
    NanomaterialEntity entity = null;//  w w w  . j a va2  s.  c  o m
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the nanomaterial entity " + entityId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(NanomaterialEntity.class)
            .add(Property.forName("id").eq(new Long(entityId)));
    crit.setFetchMode("sampleComposition", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("composingElementCollection", FetchMode.JOIN);
    crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN);
    crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    if (!result.isEmpty()) {
        entity = (NanomaterialEntity) result.get(0);
    }
    return entity;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public FunctionalizingEntity findFunctionalizingEntityById(String sampleId, String entityId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the functionalizing entity " + entityId);
    }/*www . ja  v  a  2s  .  c  om*/
    FunctionalizingEntity entity = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(FunctionalizingEntity.class)
            .add(Property.forName("id").eq(new Long(entityId)));
    crit.setFetchMode("activationMethod", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("functionCollection", FetchMode.JOIN);
    crit.setFetchMode("functionCollection.targetCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementB", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
        entity = (FunctionalizingEntity) result.get(0);
    }
    return entity;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java

License:BSD License

public ChemicalAssociation findChemicalAssociationById(String sampleId, String assocId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the chemical association " + assocId);
    }/*  ww  w .  j a va  2s  .  co m*/
    ChemicalAssociation assoc = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(ChemicalAssociation.class)
            .add(Property.forName("id").eq(new Long(assocId)));
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("associatedElementA.nanomaterialEntity", FetchMode.JOIN);
    crit.setFetchMode("associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("associatedElementB.nanomaterialEntity", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
        assoc = (ChemicalAssociation) result.get(0);
    }
    return assoc;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java

License:BSD License

public Sample findSampleByName(String sampleName) throws Exception {
    Sample sample = null;//from w  ww .  ja v a 2  s. c om
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("name").eq(sampleName).ignoreCase());
    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("characterizationCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.nanomaterialEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.nanomaterialEntityCollection.composingElementCollection",
            FetchMode.JOIN);
    crit.setFetchMode(
            "sampleComposition.nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection",
            FetchMode.JOIN);

    crit.setFetchMode("sampleComposition.functionalizingEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("sampleComposition.functionalizingEntityCollection.functionCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List<Object> result = appService.query(crit);
    if (!result.isEmpty()) {
        sample = (Sample) result.get(0);
        if (!springSecurityAclService.currentUserHasReadPermission(sample.getId(),
                SecureClassesEnum.SAMPLE.getClazz())
                && !springSecurityAclService.currentUserHasWritePermission(sample.getId(),
                        SecureClassesEnum.SAMPLE.getClazz())) {
            throw new NoAccessException("User has no access to the sample " + sampleName);
        }
    }
    return sample;
}

From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java

License:BSD License

public List<Keyword> findKeywordsBySampleId(String sampleId) throws Exception {
    // check whether user has access to the sample

    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User doesn't have access to the sample : " + sampleId);
    }/* w  w  w.j  a v a 2  s  .  c o m*/
    List<Keyword> keywords = new ArrayList<Keyword>();

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    Sample sample = null;
    if (!result.isEmpty()) {
        sample = (Sample) result.get(0);
        keywords.addAll(sample.getKeywordCollection());
    }
    return keywords;
}