From 09f0e8b1c829013e377a42be84a0ce977973ee21 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Fri, 24 Aug 2018 12:02:20 +0100 Subject: [PATCH] Use only getW() for the denying write operations. --- .../sparql/core/DatasetGraphReadOnly.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphReadOnly.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphReadOnly.java index dffb52b4d02..06aae4fe07d 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphReadOnly.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphReadOnly.java @@ -18,8 +18,8 @@ package org.apache.jena.sparql.core; -import java.util.HashMap ; import java.util.Map ; +import java.util.concurrent.ConcurrentHashMap; import org.apache.jena.atlas.logging.Log ; import org.apache.jena.graph.Graph ; @@ -31,6 +31,9 @@ */ public class DatasetGraphReadOnly extends DatasetGraphWrapper { + // Add a read-only wrapper any graphs returned. + // Block write access at getW(). + public DatasetGraphReadOnly(DatasetGraph dsg) { super(dsg) ; } private Graph dftGraph = null ; @@ -50,10 +53,12 @@ public Graph getDefaultGraph() get().begin(mode) ; } - private Map namedGraphs = new HashMap<>() ; + private Map namedGraphs = new ConcurrentHashMap<>() ; @Override public Graph getGraph(Node graphNode) { + // Cache GraphReadOnly wrappers. This also makes == work (a nicety) + // if the underlying DatasetGraph isn't changing. if ( namedGraphs.containsKey(graphNode) ) { if ( !super.containsGraph(graphNode) ) { namedGraphs.remove(graphNode) ; @@ -70,18 +75,6 @@ public Graph getGraph(Node graphNode) { return g ; } - @Override - public void setDefaultGraph(Graph g) - { throw new UnsupportedOperationException("read-only dataset") ; } - - @Override - public void addGraph(Node graphName, Graph graph) - { throw new UnsupportedOperationException("read-only dataset") ; } - - @Override - public void removeGraph(Node graphName) - { throw new UnsupportedOperationException("read-only dataset") ; } - /** For operations that write the DatasetGraph. */ @Override protected DatasetGraph getW()