List of usage examples for org.hibernate FetchMode JOIN
FetchMode JOIN
To view the source code for org.hibernate FetchMode JOIN.
Click Source Link
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * [UC1186] Gerar Relatrio Ordem de Servio Cobrana p/Resultado * //from ww w .jav a 2 s. c o m * Pesquisar as Ordens de servios a partir de seu imvel e tipo de servio * * @author Hugo Azevedo * @data 02/07/2011 */ public Collection obterOSImovelTipoServico(Integer id, Integer tipoServico) throws ErroRepositorioException { Session session = HibernateUtil.getSession(); Collection<OrdemServico> retorno = new ArrayList(); try { Criteria crit = session.createCriteria(OrdemServico.class); crit.setFetchMode("imovel", FetchMode.JOIN); crit.setFetchMode("servicoTipo", FetchMode.JOIN); crit.setFetchMode("atendimentoMotivoEncerramento", FetchMode.JOIN); crit.add(Restrictions.eq("imovel.id", id)); if (tipoServico != null && tipoServico.intValue() != -1) { crit.add(Restrictions.eq("servicoTipo.id", tipoServico.intValue())); } retorno = (Collection<OrdemServico>) crit.list(); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retorno; }
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()); }/*from w w w .j a va 2 s .co m*/ return results; }
From source file:gov.nih.nci.caintegrator.studyQueryService.germline.SNPAssociationFindingsHandler.java
License:BSD License
protected void initializeProxies(Collection<? extends Finding> findings, Session session) { List<GeneBiomarker> gbObjs = new ArrayList<GeneBiomarker>(); /* initialize SNPAnnotations */ List<Long> snpAssocFindingIDs = new ArrayList<Long>(); Collection<Long> snpAnnotsIDs = new HashSet<Long>(); Collection<Long> populationIDs = new HashSet<Long>(); for (Iterator<? extends Finding> iterator = findings.iterator(); iterator.hasNext();) { SNPAssociationFinding finding = (SNPAssociationFinding) iterator.next(); snpAnnotsIDs.add(finding.getSnpAnnotation().getId()); snpAssocFindingIDs.add(finding.getId()); }/*from w w w. j a va2 s .c o m*/ if (snpAnnotsIDs.size() > 0) { ArrayList arrayIDs = new ArrayList(snpAnnotsIDs); for (int i = 0; i < arrayIDs.size();) { Collection values = new ArrayList(); int begIndex = i; i += IN_PARAMETERS; int lastIndex = (i < arrayIDs.size()) ? i : (arrayIDs.size()); values.addAll(arrayIDs.subList(begIndex, lastIndex)); Criteria snpAnnotcrit = session.createCriteria(SNPAnnotation.class) .setFetchMode("geneBiomarkerCollection", FetchMode.JOIN).add(Restrictions.in("id", values)); snpAnnotcrit.list(); } } if (snpAssocFindingIDs.size() > 0) { ArrayList arrayIDs = new ArrayList(snpAssocFindingIDs); for (int i = 0; i < arrayIDs.size();) { Collection values = new ArrayList(); int begIndex = i; i += IN_PARAMETERS; int lastIndex = (i < arrayIDs.size()) ? i : (arrayIDs.size()); values.addAll(arrayIDs.subList(begIndex, lastIndex)); Criteria snpAssocFindingCrit = session.createCriteria(SNPAssociationFinding.class) .setFetchMode("oddsRatioCollection", FetchMode.JOIN).add(Restrictions.in("id", values)); snpAssocFindingCrit.list(); } } // Collection findingIDs = new HashSet(); // for (Iterator<? extends Finding> iterator = findings.iterator(); iterator.hasNext();) { // SNPAssociationFinding finding = (SNPAssociationFinding) iterator.next(); // findingIDs.add(finding.getId()); // //gbObjs.addAll(finding.getSnpAnnotation().getGeneBiomarkerCollection()); // } // // Criteria crit; // ArrayList<String> arrayIDs = new ArrayList<String>(findingIDs); // for (int i = 0; i < arrayIDs.size();) { // List<String> values = new ArrayList<String>(); // int begIndex = i; // i += 1000 ; // int lastIndex = (i < arrayIDs.size()) ? i : (arrayIDs.size()); // values.addAll(arrayIDs.subList(begIndex, lastIndex)); // crit = session.createCriteria(SNPAnnotation.class). // createAlias("snpAssociationFindingCollection", "findings"). // setFetchMode("geneBiomarkerCollection", FetchMode.EAGER). // add(Restrictions.in("findings.id", values)); // crit.list(); // } // //Hibernate.initialize(gbObjs); // //gbObjs = null; }
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();//ww w . j a v a 2 s .c om // 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();//from w w w. ja 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 va2 s . c om*/ 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();/*from w w w. ja v a 2 s. co 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; }/*from w ww .j av a 2s . c o m*/ 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(); } }
From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java
License:BSD License
public Protocol findProtocolById(String protocolId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz())) { new NoAccessException("User has no access to the protocol " + protocolId); }/* w ww . j av a 2s. c o m*/ Protocol protocol = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class) .add(Property.forName("id").eq(new Long(protocolId))); crit.setFetchMode("file", FetchMode.JOIN); crit.setFetchMode("file.keywordCollection", FetchMode.JOIN); List result = appService.query(crit); if (!result.isEmpty()) { protocol = (Protocol) result.get(0); } return protocol; }