Skip to content

Commit

Permalink
Use only getW() for the denying write operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Aug 24, 2018
1 parent a17c6dd commit 09f0e8b
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand All @@ -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 ;
Expand All @@ -50,10 +53,12 @@ public Graph getDefaultGraph()
get().begin(mode) ;
}

private Map<Node, Graph> namedGraphs = new HashMap<>() ;
private Map<Node, Graph> 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) ;
Expand All @@ -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()
Expand Down

0 comments on commit 09f0e8b

Please sign in to comment.