Thank you both, Andy and Martynas, the GraphReadOnly approach seems to
work well and feels more natural than model union.
Martynas, I swear I searched before asking again! :-)
Best,
Marco.
On 28/08/2021 15:01, Martynas Jusevičius wrote:
I remember asking a similar question 5 years ago :)
https://mail-archives.apache.org/mod_mbox/jena-users/201610.mbox/%3cCAE35VmwR+QjzGiEcWwO0sVJcFcnb=CTYqHc-fp7iF550=1b...@mail.gmail.com%3e
ModelFactory.createUnion() might to be an option.
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ModelFactory.html#createUnion(org.apache.jena.rdf.model.Model,org.apache.jena.rdf.model.Model)
On Sat, Aug 28, 2021 at 3:43 PM Andy Seaborne <a...@apache.org> wrote:
On 27/08/2021 12:23, Zak Mc Kracken wrote:
Hi all,
I have a little RDF file (describing a dataset metadata), which I want
to read in an helper class and return as a read-only view on the file.
The reason to return it as read-only is that I also keep a simple cache
of uri/Object, which is a simplified view of RDF resources in the file,
so a modifiable Model would make it impossible to keep the two aligned.
That said, I wonder if there is some read-only wrapper for the Jena's
Model interface, something similar to Collections.unmodifiableXXX(),
which of course, would be based on the decorator pattern, with
delegation to a base Model for most of the interface methods, except
interceptors for addXXX(), which would throw
UnsupportedOperationException. Would be easy to implement it, but I
don't like to reinvent wheels, if something like that already exists.
Apparently there isn't one. Not sure why not.
There is a read-only graph (and a read-only DatasetGraph) so one way to
create a read-only model is:
Model model = ModelFactory.createDefaultModel();
Graph graphRO = new GraphReadOnly(model.getGraph());
Model modelRO = ModelFactory.createModelForGraph(graphRO);
Graph is a narrower interface do catching things here is less code. In
fact, GraphBase is read-only unless add/delete(Triple) are overwritten.
Andy
Thanks,
Marco.