List of usage examples for javax.persistence EntityGraph addSubgraph
public <X> Subgraph<X> addSubgraph(String attributeName);
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.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 w w . j av a 2s . c o 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 w w w .j a va 2 s .c o 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; }/* ww w.j av a2s . 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]); } }