List of usage examples for javax.persistence EntityGraph addAttributeNodes
public void addAttributeNodes(Attribute<T, ?>... attribute);
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalEcNumbersRepositoryImpl.java
@Transactional(readOnly = true) @Override//from w ww. ja v a2 s. com public List<EcNumber> findEnzymeFamiliesByTaxId(Long taxId) { EntityGraph eGraph = entityManager.getEntityGraph("EcNumberEntityGraph"); eGraph.addAttributeNodes("uniprotAccession"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); List<EcNumber> result = query.from($).where($.uniprotAccession.taxId.eq(taxId)) .list(Projections.constructor(EcNumber.class, $.ecFamily)).stream().distinct() .collect(Collectors.toList()); result.sort(SORT_BY_EC); return result; }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalCompoundRepositoryImpl.java
@Override @Transactional(readOnly = true)// ww w.j a v a 2 s .co m public List<Compound> findCompoundsByTaxId(Long taxId) { EntityGraph eGraph = entityManager.getEntityGraph("CompoundEntityGraph"); eGraph.addAttributeNodes("uniprotAccession"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); List<Compound> result = query.from($).where($.uniprotAccession.taxId.eq(taxId)).distinct() .list(Projections.constructor(Compound.class, $.compoundId, $.compoundName, $.url, $.compoundRole)) .stream().distinct().collect(Collectors.toList()); return result; }
From source file:uk.ac.ebi.ep.data.repositories.DiseaseRepositoryImpl.java
@Override @Transactional(readOnly = true)//from w ww . java 2 s . c om public List<EnzymePortalDisease> findDiseases() { EntityGraph eGraph = entityManager.getEntityGraph("DiseaseEntityGraph"); eGraph.addAttributeNodes("uniprotAccession"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); return query.from($).list($); }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalSummaryRepositoryImpl.java
@Override public List<EnzymePortalSummary> findEnzymeSummariesByAccession(String accession) { EntityGraph eGraph = entityManager.getEntityGraph("summary.graph"); eGraph.addAttributeNodes("uniprotAccession"); eGraph.addSubgraph("uniprotAccession").addAttributeNodes("enzymePortalPathwaysSet", "enzymePortalReactionSet", "enzymePortalSummarySet", "enzymePortalDiseaseSet", "enzymePortalCompoundSet", "uniprotXrefSet", "enzymePortalEcNumbersSet"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); List<EnzymePortalSummary> summaries = query.from($) .where($.uniprotAccession.accession.equalsIgnoreCase(accession)).list($); return summaries; }
From source file:uk.ac.ebi.ep.data.repositories.DiseaseRepositoryImpl.java
@Override @Transactional(readOnly = true)/*from w ww.j av a 2s. c o m*/ public List<Disease> findDiseasesByTaxId(Long taxId) { EntityGraph eGraph = entityManager.getEntityGraph("DiseaseEntityGraph"); eGraph.addAttributeNodes("uniprotAccession"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); List<Disease> result = query.from($).where($.uniprotAccession.taxId.eq(taxId)) .list(Projections.constructor(Disease.class, $.meshId, $.diseaseName, $.url)).stream().distinct() .collect(Collectors.toList()); return result; }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalSummaryRepositoryImpl.java
@Override public EnzymePortalSummary findEnzymeSummaryByAccession(String accession) { //EntityGraph eGraph = entityManager.createEntityGraph(EnzymePortalSummary.class); EntityGraph eGraph = entityManager.getEntityGraph("summary.graph"); eGraph.addAttributeNodes("uniprotAccession"); eGraph.addSubgraph("uniprotAccession").addAttributeNodes("enzymePortalPathwaysSet", "enzymePortalReactionSet", "enzymePortalSummarySet", "enzymePortalDiseaseSet", "enzymePortalCompoundSet", "uniprotXrefSet", "enzymePortalEcNumbersSet"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); EnzymePortalSummary e = query.from($).where($.uniprotAccession.accession.equalsIgnoreCase(accession)) .singleResult($);/* w ww .ja va2s . co m*/ return e; }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalSummaryRepositoryImpl.java
@Override public Page<EnzymePortalSummary> findEnzymeSummariesByAccessions(List<String> accessions, Pageable pageable) { EntityGraph eGraph = entityManager.getEntityGraph("summary.graph"); eGraph.addAttributeNodes("uniprotAccession"); eGraph.addSubgraph("uniprotAccession").addAttributeNodes("enzymePortalPathwaysSet", "enzymePortalReactionSet", "enzymePortalSummarySet", "enzymePortalDiseaseSet", "enzymePortalCompoundSet", "uniprotXrefSet", "enzymePortalEcNumbersSet"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); BooleanBuilder builder = new BooleanBuilder(); accessions.stream().forEach((accession) -> { builder.or($.uniprotAccession.accession.equalsIgnoreCase(accession)); });//from ww w .ja va 2 s. co m query.from($).where(builder); List<EnzymePortalSummary> result = query.distinct().list($).parallelStream().distinct() .collect(Collectors.toList()); return new PageImpl(result, pageable, result.size()); }
From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java
private void buildEntityGraph(EntityGraph<T> entityGraph, String[] attributeGraph) { List<String> attributePaths = Arrays.asList(attributeGraph); // Sort to ensure that the intermediate entity subgraphs are created accordingly. Collections.sort(attributePaths); Collections.reverse(attributePaths); // We build the entity graph based on the paths with highest depth first for (String path : attributePaths) { // Fast path - just single attribute if (!path.contains(".")) { entityGraph.addAttributeNodes(path); continue; }//from www . j ava2s. c o m // We need to build nested sub fetch graphs String[] pathComponents = StringUtils.delimitedListToStringArray(path, "."); Subgraph<?> parent = null; for (int c = 0; c < pathComponents.length - 1; c++) { parent = c == 0 ? entityGraph.addSubgraph(pathComponents[c]) : parent.addSubgraph(pathComponents[c]); } parent.addAttributeNodes(pathComponents[pathComponents.length - 1]); } }