Example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

List of usage examples for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Prototype

ResultTransformer DISTINCT_ROOT_ENTITY

To view the source code for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Click Source Link

Document

Each row of results is a distinct instance of the root entity

Usage

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

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

License:BSD License

public List<PointOfContact> findOtherPointOfContactsBySampleId(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);
    }//  www .  j av  a 2s .c o m
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    List<PointOfContact> pointOfContacts = new ArrayList<PointOfContact>();
    for (int i = 0; i < results.size(); i++) {
        Sample sample = (Sample) results.get(i);
        Collection<PointOfContact> otherPOCs = sample.getOtherPointOfContactCollection();
        for (PointOfContact poc : otherPOCs) {
            pointOfContacts.add(poc);
        }
    }
    return pointOfContacts;
}

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

License:BSD License

public Sample findSampleById(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);
    }//  w w w .java 2  s  .c o m

    logger.debug("===============Finding a sample by id: " + System.currentTimeMillis());
    Sample sample = null;
    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.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 result = appService.query(crit);
    if (!result.isEmpty() || result.size() > 0) {
        sample = (Sample) result.get(0);
    }
    return sample;
}

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

License:BSD License

public Sample findSampleBasicById(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);
    }/*from   ww  w  .j  av  a  2 s  . c o m*/
    Sample sample = null;
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("id").eq(new Long(sampleId)));

    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

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