Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

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);
    }/*w ww.java  2 s .co m*/
    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  av a 2  s. com*/
    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  w  w w. j  av  a  2 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);
    }//from  www .ja  v a2  s. c  o m
    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  v a2  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);
    }/*ww  w. j a  va  2s .com*/
    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);
    }/*from  w  w w.j  a  v  a 2 s.  c  o  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 w  w.  ja v  a2  s.co  m
    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);
    }//from  w  ww. ja v a 2  s.com
    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;
}

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

License:BSD License

public PointOfContact findPrimaryPointOfContactBySampleId(String sampleId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId),
            SecureClassesEnum.SAMPLE.getClazz())
            && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId),
                    SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User has no access to the sample " + sampleId);
    }/*  ww  w  .j a  v  a 2  s.c  o  m*/
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
    crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    PointOfContact poc = null;
    for (int i = 0; i < results.size(); i++) {
        Sample sample = (Sample) results.get(i);
        poc = sample.getPrimaryPointOfContact();
    }
    return poc;
}