namedgraph commented on issue #4006:
URL: https://github.com/apache/jena/issues/4006#issuecomment-4759906043

   > Perhaps we could add the `DocumentGraphRepository#addMappings(Model 
mapping)` method. Would such a method be convenient? The only problem here is 
prefixes.
   
   That would work but feels like a hack. My gut feeling is that a location 
mapper interface is missing for a proper refactoring - and Claude seems to 
agree.
   
   # Option A — adapter
   
   Wrap rather than subclass. Implement `GraphRepository`, delegate resolution 
to a `LocationMapper`, and delegate materialization back into a 
`DocumentGraphRepository` by registering the resolved location on the fly:
   
   ```java
   public final class MappedGraphRepository implements GraphRepository {
       private final LocationMapper resolver;
       private final DocumentGraphRepository store; // does the loading + 
caching
   
       public MappedGraphRepository(LocationMapper resolver, Supplier<Graph> 
factory) {
           this.resolver = resolver;
           this.store = new DocumentGraphRepository(factory);
       }
   
       @Override public Graph get(String id) {
           String loc = resolver.altMapping(id, id);   // exact + prefix, 
identity fallback
           if (!store.contains(loc))
               store.addMapping(loc, loc);              // register resolved 
source
           return store.get(loc);                       // load/cache/throw 
handled by DGR
       }
       // ids()/contains()/remove()/clear()/count()/loadedGraphs() delegate to 
store,
       // keyed by resolved location; keep an id→loc table if you want ids() to 
report logical ids.
   }
   ```
   
   # Option B — the upstream refactor (the "right" fix)
   
   Give DGR a pluggable resolution SPI and make `LocationMapper` one 
implementation of it. The cleanest version collapses DGR's private exact map 
into a `LocationMapper`, since `addMapping` is just another exact-entry layer:
   
   ```java
   interface LocationResolver { String resolve(String id); }   // null/id == no 
remap
   
   // DGR holds a LocationResolver; default impl is backed by a LocationMapper:
   addMapping(id, loc)  ->  lm.addAltEntry(id, loc);            // write path 
unchanged in behavior
   get(id):  String loc = lm.altMapping(id, id);  /* then materialize+cache 
keyed by loc */
   ```
   
   The new `LocationMapper` class is this: 
https://jena.apache.org/documentation/javadoc/arq/org.apache.jena.arq/org/apache/jena/riot/system/streammgr/LocationMapper.html
   
   @afs WDYT about option B?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to