private void populateGraph ( final EntityGraph < ? > graph , final Set < String > fetches ) { Map < String , Subgraph < ? > > created = new HashMap <> ( ) ; for ( String fetch : fetches ) { final String [ ] parts = StringUtils . split ( fetch , ' ' ) ; // Starts of null (meaning parent is the root graph), updated as we go through path segments to refer to the last path segment Subgraph < ? > parent = null ; // Iterate over the path segments, adding attributes subgraphs for ( int i = 0 ; i < parts . length ; i ++ ) { final String path = StringUtils . join ( parts , ' ' , 0 , i + 1 ) ; final boolean isLeaf = ( i == parts . length - 1 ) ; final Subgraph < ? > existing = created . get ( path ) ; if ( existing == null ) { if ( parent == null ) { try { // Relation under root graph . addAttributeNodes ( parts [ i ] ) ; // Only set up a subgraph if this is not a leaf node // This prevents us trying to add a Subgraph for a List of Embeddable if ( ! isLeaf ) parent = graph . addSubgraph ( parts [ i ] ) ; } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException ( "Error adding graph member " + parts [ i ] + " with isLeaf=" + isLeaf + " to root as part of " + fetch , e ) ; } } else { try { // Relation under parent parent . addAttributeNodes ( parts [ i ] ) ; // Only set up a subgraph if this is not a leaf node // This prevents us trying to add a Subgraph for a List of Embeddable if ( ! isLeaf ) parent = parent . addSubgraph ( parts [ i ] ) ; } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException ( "Error adding graph member " + parts [ i ] + " with isLeaf=" + isLeaf + " as part of " + fetch + " with parent.class=" + parent . getClassType ( ) , e ) ; } } if ( ! isLeaf ) created . put ( path , parent ) ; } else { // Already seen this graph node before parent = existing ; } } } }
Creates an EntityGraph representing the