jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [21/34] jena git commit: JENA-1131: Separate uses: DatasetGraphMapLink and DatasetGraphMap
Date Sat, 06 Feb 2016 15:51:10 GMT
JENA-1131: Separate uses: DatasetGraphMapLink and DatasetGraphMap

Code maintenance.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/cf0aa842
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/cf0aa842
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/cf0aa842

Branch: refs/heads/master
Commit: cf0aa8422cb6849bd5ecf58fbcef415ad4768584
Parents: 13d98f0
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Feb 5 18:36:58 2016 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Feb 5 19:17:33 2016 +0000

----------------------------------------------------------------------
 .../org/apache/jena/query/DatasetFactory.java   |   8 -
 .../apache/jena/sparql/core/DatasetGraph.java   |   8 +
 .../core/DatasetGraphAltDefaultGraph.java       |   4 +-
 .../jena/sparql/core/DatasetGraphBase.java      |  19 +--
 .../sparql/core/DatasetGraphCollection.java     |   5 +-
 .../jena/sparql/core/DatasetGraphCopyAdd.java   |   2 +-
 .../jena/sparql/core/DatasetGraphFactory.java   |  52 +++---
 .../jena/sparql/core/DatasetGraphMap.java       | 159 ++++++++-----------
 .../jena/sparql/core/DatasetGraphMapLink.java   | 158 ++++++++++++++++++
 .../jena/sparql/core/DatasetGraphOne.java       |   2 +
 .../sparql/core/DatasetGraphTriplesQuads.java   |   8 +-
 .../jena/sparql/core/DatasetGraphWrapper.java   |  10 ++
 .../apache/jena/sparql/core/DatasetImpl.java    |   8 -
 .../jena/sparql/core/DynamicDatasets.java       |   2 +-
 .../jena/sparql/core/TransactionalMRSW.java     |  22 +--
 .../sparql/core/mem/DatasetGraphInMemory.java   |   1 +
 .../jena/sparql/modify/GraphStoreBasic.java     |   6 -
 .../jena/sparql/modify/UpdateEngineWorker.java  |  54 ++-----
 .../apache/jena/sparql/util/DatasetUtils.java   |  43 +++--
 .../jena/sparql/util/graph/GraphUtils.java      |  14 ++
 .../apache/jena/sdb/store/DatasetGraphSDB.java  |   5 +-
 .../apache/jena/tdb/store/DatasetGraphTDB.java  |   5 +-
 22 files changed, 354 insertions(+), 241 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java b/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
index cf6faf1..3203b44 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
@@ -97,14 +97,6 @@ public class DatasetFactory {
 		return wrap(DatasetGraphFactory.createGeneral()); 
 	}
 
-	/**
-	 * @deprecated This operation may be removed.
-	 */
-	@Deprecated
-	public static Dataset createMemFixed() {
-		return wrap(DatasetGraphFactory.createMemFixed());
-	}
-
     /**
 	 * @param model The model for the default graph
 	 * @return a dataset with the given model as the default graph

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraph.java
index 0983ab6..cf4f90b 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraph.java
@@ -140,4 +140,12 @@ public interface DatasetGraph extends Transactional, Closeable
     /** Close the dataset */
     @Override
     public void close() ;
+    
+//    public boolean supportsTransactions() ;
+//    public boolean supportsTransactionAbort() ;
+    
+    public default boolean supportsTransactions()  { return ! (this instanceof TransactionalNotSupported) ; }  
+    //public default boolean supportsTransactions() { return ! (this instanceof TransactionalNotSupported) ; }
+    
+    public default boolean supportsTransactionAbort() { return ! (this instanceof TransactionalNotSupported) ; }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphAltDefaultGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphAltDefaultGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphAltDefaultGraph.java
index 2e7b7a8..e6a5f77 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphAltDefaultGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphAltDefaultGraph.java
@@ -35,7 +35,7 @@ public class DatasetGraphAltDefaultGraph extends DatasetGraphCollection implemen
     private Graph defaultGraph ;
     private final DatasetGraph dsg ;
 
-    public DatasetGraphAltDefaultGraph(DatasetGraph dsg, Graph defaultGraph) {  
+    public DatasetGraphAltDefaultGraph(boolean x, DatasetGraph dsg, Graph defaultGraph) {  
         this.defaultGraph = defaultGraph ;
         this.dsg = dsg ;
     }
@@ -60,6 +60,8 @@ public class DatasetGraphAltDefaultGraph extends DatasetGraphCollection implemen
 
     @Override
     public void removeGraph(Node graphName)           { dsg.removeGraph(graphName); }
+    
+    
 }    
 
 

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphBase.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphBase.java
index 4c4c8f1..1eb29c6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphBase.java
@@ -23,7 +23,6 @@ import org.apache.jena.atlas.io.IndentedLineBuffer ;
 import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
 import org.apache.jena.shared.Lock ;
 import org.apache.jena.shared.LockMRSW ;
 import org.apache.jena.sparql.sse.writers.WriterGraph ;
@@ -176,21 +175,5 @@ abstract public class DatasetGraphBase implements DatasetGraph
         return out.asString() ;
     }
 
-    // Helpers
-    
-    /** Convert an iterator of triples into quads for the default graph.
-     * This is {@link Quad#defaultGraphIRI}, not {@link Quad#defaultGraphNodeGenerated},
-     * which is for quads outside a dataset, usually the output of parsers. 
-     */
-    protected static Iterator<Quad> triples2quadsDftGraph(Iterator<Triple> iter) {
-        return triples2quads(Quad.defaultGraphIRI, iter) ;
-    }
-
-    /** Convert an iterator of triples into quads for the specificed graph name. */
-    protected static Iter<Quad> triples2quads(final Node graphNode, Iterator<Triple> iter) {
-        return Iter.iter(iter).map(t -> new Quad(graphNode, t)) ;
-    }
-
-    
-
+    // Helpers: See GraphUtils.
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCollection.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCollection.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCollection.java
index 49c04d4..b90651a 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCollection.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCollection.java
@@ -18,6 +18,8 @@
 
 package org.apache.jena.sparql.core;
 
+import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph ;
+
 import java.util.Iterator ;
 import java.util.List ;
 import java.util.Objects ;
@@ -27,12 +29,13 @@ import org.apache.jena.atlas.iterator.IteratorConcat ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.shared.JenaException ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.* ;
 
 /** Base class for implementations of a DatasetGraph as a set of graphs.
  * This can be a fixed collection or a changeable collection depending
  * on the implementation of getDefaultGraph()/getGraph(Node)  
  */
-public abstract class DatasetGraphCollection extends DatasetGraphBaseFind
+public abstract class DatasetGraphCollection extends DatasetGraphBaseFind implements TransactionalNotSupported
 {
     @Override
     public void add(Quad quad)

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCopyAdd.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCopyAdd.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCopyAdd.java
index 6f4757f..296b555 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCopyAdd.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphCopyAdd.java
@@ -27,7 +27,7 @@ import org.apache.jena.graph.Node ;
 
 /*package*/ class DatasetGraphCopyAdd extends DatasetGraphWrapper 
 {
-    public DatasetGraphCopyAdd(DatasetGraph dsg) {
+    public DatasetGraphCopyAdd(boolean x , DatasetGraph dsg) {
         super(dsg);
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
index 7fef093..97a0ff6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
@@ -28,7 +28,7 @@ import org.apache.jena.sparql.graph.GraphFactory ;
 
 public class DatasetGraphFactory
 {
-    /** Create an in-memory, non-transactional {@link DatasetGraph}.
+    /** Create an in-memory {@link DatasetGraph}.
      * This implementation copies the triples of an added graph into the dataset. 
      * <p>
      * See also {@link #createTxnMem()}
@@ -40,10 +40,25 @@ public class DatasetGraphFactory
      */
     
     public static DatasetGraph create() {
-        return new DatasetGraphCopyAdd(createGeneral()) ;
+        return new DatasetGraphMap() ;
     }
 
     /**
+     * Create a general-purpose, non-transactional Dataset.<br/>
+     * 
+     * This dataset can contain graphs from any source when added via {@link Dataset#addNamedModel}.
+     * Any graphs needed are in-memory unless explicitly added with {@link DatasetGraph#addGraph}.
+     * </p>
+     * These are held as links to the supplied graph and not copied.
+     * <p> 
+     * This dataset does not support transactions. 
+     * <p>
+     * 
+     * @return a general-purpose DatasetGraph
+     */
+    public static DatasetGraph createGeneral() { return new DatasetGraphMapLink(memGraphMaker) ; }
+
+    /**
      * @return a DatasetGraph which features transactional in-memory operation
      */
     public static DatasetGraph createTxnMem() { return new DatasetGraphInMemory(); }
@@ -76,9 +91,13 @@ public class DatasetGraphFactory
     
     /** Clone the structure of a DatasetGraph
      */
-    @Deprecated
     public static DatasetGraph cloneStructure(DatasetGraph dsg) {
-        return new DatasetGraphMap(dsg, memGraphMaker) ;
+        DatasetGraphMapLink dsg2 = new DatasetGraphMapLink(dsg.getDefaultGraph()) ;
+        for ( Iterator<Node> names = dsg.listGraphNodes() ; names.hasNext() ; ) {
+            Node gn = names.next() ;
+            dsg2.addGraph(gn, dsg.getGraph(gn)) ;
+        }
+        return dsg2 ;
     }
 
     private static void copyOver(DatasetGraph dsgDest, DatasetGraph dsgSrc)
@@ -95,11 +114,8 @@ public class DatasetGraphFactory
      * Create a DatasetGraph starting with a single graph.
      * New graphs must be explicitly added.
      */
-    public static DatasetGraph create(Graph graph)
-    {
-        final DatasetGraph dsg2 = createMemFixed() ;
-        dsg2.setDefaultGraph(graph) ;
-        return dsg2 ;
+    public static DatasetGraph create(Graph graph) {
+        return new DatasetGraphMapLink(graph) ;
     }
 
     /**
@@ -116,22 +132,4 @@ public class DatasetGraphFactory
     public static GraphMaker graphMakerNull = () -> null ;
 
     public static GraphMaker memGraphMaker = () -> GraphFactory.createDefaultGraph() ;
-
-    /**
-     * Create a general-purpose, non-transactional Dataset.<br/>
-     * 
-     * This dataset can contain graphs from any source when added via {@link Dataset#addNamedModel}.
-     * Any graphs needed are in-memory unless explicitly added with {@link DatasetGraph#addGraph}.
-     * </p>
-     * These are held as links to the supplied graph and not copied.
-     * <p> 
-     * This dataset does not support transactions. 
-     * <p>
-     * 
-     * @return a general-purpose DatasetGraph
-     */
-    public static DatasetGraph createGeneral() { return new DatasetGraphMap(memGraphMaker) ; }
-    
-    @Deprecated
-    public static DatasetGraph createMemFixed() { return new DatasetGraphMap(GraphFactory.createDefaultGraph()) ; }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
index 5bbd30c..89474cd 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
@@ -18,149 +18,126 @@
 
 package org.apache.jena.sparql.core;
 
+import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quads ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph ;
+
 import java.util.HashMap ;
 import java.util.Iterator ;
 import java.util.Map ;
 
+import org.apache.jena.atlas.iterator.IteratorConcat ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
-import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.graph.Triple ;
 import org.apache.jena.sparql.ARQException ;
 import org.apache.jena.sparql.core.DatasetGraphFactory.GraphMaker ;
 
 /** Implementation of a DatasetGraph as an extensible set of graphs.
  *  Subclasses need to manage any implicit graph creation.
+ *  This implementation provides copy-in, copy-out for {@link #addGraph}  
  */
-public class DatasetGraphMap extends DatasetGraphCollection
+public class DatasetGraphMap extends DatasetGraphTriplesQuads implements TransactionalNotSupported
 {
-    private final Transactional txn = new TransactionalMRSW() ;
-    @Override public void begin(ReadWrite mode) { txn.begin(mode) ; }
-    @Override public void commit()              { txn.commit() ; }
-    @Override public void abort()               { txn.abort() ; }
-    @Override public boolean isInTransaction()  { return txn.isInTransaction() ; }
-    @Override public void end()                 { txn.end(); }
-    
     private final GraphMaker graphMaker ;
     private final Map<Node, Graph> graphs = new HashMap<>() ;
 
     private Graph defaultGraph ;
-
-    /** Create a new DatasetGraph that initially shares the graphs of the
-     * given DatasetGraph.  Adding/removing graphs will only affect this
-     * object, not the argument DatasetGraph but changes to shared
-     * graphs are seen by both objects.
-     */
-    /*package*/ DatasetGraphMap(DatasetGraph dsg, GraphMaker graphMaker) {
-        this.graphMaker = graphMaker ; 
-        this.defaultGraph = dsg.getDefaultGraph() ;
-        for ( Iterator<Node> names = dsg.listGraphNodes() ; names.hasNext() ; ) {
-            Node gn = names.next() ;
-            addGraph(gn, dsg.getGraph(gn)) ;
-        }
-    }
-
-    /** 
-     *  A {@code DatasetGraph} with graphs for default and named graphs as given
-     *  but new graphs are created in memory.
-     */
-    /*package*/ DatasetGraphMap(DatasetGraph dsg) {
-        this(dsg, DatasetGraphFactory.memGraphMaker) ;
-    }
-
-    private DatasetGraphMap(Graph dftGraph, GraphMaker graphMaker) {
-        this.graphMaker = graphMaker;
-        this.defaultGraph = dftGraph ;
-    }
     
-    /** A {@code DatasetGraph} with in-memory graphs for default and named graphs as needed */ 
     public DatasetGraphMap() {
         this(DatasetGraphFactory.memGraphMaker) ; 
     }
     
-    /*package*/ DatasetGraphMap(GraphMaker graphMaker) {
+    public DatasetGraphMap(GraphMaker graphMaker) {
         this(graphMaker.create(), graphMaker) ;
     }
-
-    /** A {@code DatasetGraph} that uses the given graph for the default graph
-     *  and create in-memory graphs for named graphs as needed
-     */
-    public DatasetGraphMap(Graph dftGraph) {
-        this.defaultGraph = dftGraph ;
-        this.graphMaker = DatasetGraphFactory.graphMakerNull ;
+    
+    public DatasetGraphMap(Graph defaultGraph, GraphMaker graphMaker) {
+        this.defaultGraph = defaultGraph ;
+        this.graphMaker = graphMaker ;
     }
     
     @Override
-    public boolean containsGraph(Node graphNode)
-    {
-        return graphs.containsKey(graphNode) ;
+    public Iterator<Node> listGraphNodes() {
+        return graphs.keySet().iterator();
     }
 
     @Override
-    public Graph getDefaultGraph()
-    {
-        return defaultGraph ;
+    protected void addToDftGraph(Node s, Node p, Node o) {
+        getDefaultGraph().add(Triple.create(s, p, o)) ;
     }
 
     @Override
-    public Graph getGraph(Node graphNode)
-    {
-        Graph g = graphs.get(graphNode) ;
-        if ( g == null )
-        {
-            g = getGraphCreate() ;
-            if ( g != null )
-                addGraph(graphNode, g) ;
-        }
-        return g ;
+    protected void addToNamedGraph(Node g, Node s, Node p, Node o) {
+        getGraph(g).add(Triple.create(s, p, o)) ;
     }
 
-    /** Called from getGraph when a nonexistent graph is asked for.
-     * Return null for "nothing created as a graph"
-     */
-    protected Graph getGraphCreate() { 
-        Graph g = graphMaker.create() ;
-        if ( g == null )
-            throw new ARQException("Can't make new graphs") ;
-        return g ;
+    @Override
+    protected void deleteFromDftGraph(Node s, Node p, Node o) {
+        getDefaultGraph().delete(Triple.create(s, p, o)) ;
     }
-    
 
     @Override
-    public void addGraph(Node graphName, Graph graph)
-    { 
-        graphs.put(graphName, graph) ;
+    protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o) {
+        getGraph(g).delete(Triple.create(s, p, o)) ;
     }
 
     @Override
-    public void removeGraph(Node graphName)
-    {
-        graphs.remove(graphName) ;
+    protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
+        Iterator<Triple> iter = getDefaultGraph().find(s, p, o) ;
+        return triples2quadsDftGraph(iter)  ;
+        
     }
 
     @Override
-    public void setDefaultGraph(Graph g)
-    {
-        defaultGraph = g ;
+    protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) {
+        Iterator<Triple> iter = getGraph(g).find(s, p, o) ;
+        return triples2quads(g, iter) ;
     }
 
     @Override
-    public Iterator<Node> listGraphNodes()
-    {
-        return graphs.keySet().iterator() ;
+    protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
+        Iterator<Node> gnames = listGraphNodes() ;
+        IteratorConcat<Quad> iter = new IteratorConcat<>() ;
+
+        // Named graphs
+        for ( ; gnames.hasNext() ; )  
+        {
+            Node gn = gnames.next();
+            Iterator<Quad> qIter = findInSpecificNamedGraph(gn, s, p, o) ;
+            if ( qIter != null )
+                iter.add(qIter) ;
+        }
+        return iter ;
     }
 
     @Override
-    public long size()
-    {
-        return graphs.size() ;
+    public Graph getDefaultGraph() {
+        return defaultGraph;
     }
 
     @Override
-    public void close()
-    { 
-        defaultGraph.close();
-        for ( Graph graph : graphs.values() )
-            graph.close();
-        super.close() ;
+    public Graph getGraph(Node graphNode) {
+        Graph g = graphs.get(graphNode);
+        if ( g == null ) {
+            g = getGraphCreate();
+            if ( g != null )
+                graphs.put(graphNode, g);
+        }
+        return g;
+    }
+
+    /** Called from getGraph when a nonexistent graph is asked for.
+     * Return null for "nothing created as a graph"
+     */
+    protected Graph getGraphCreate() { 
+        Graph g = graphMaker.create() ;
+        if ( g == null )
+            throw new ARQException("Can't make new graphs") ;
+        return g ;
+    }
+    
+    @Override
+    public long size() {
+        return graphs.size();
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
new file mode 100644
index 0000000..47448e0
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.core;
+
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.Map ;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.ARQException ;
+import org.apache.jena.sparql.core.DatasetGraphFactory.GraphMaker ;
+
+/** Implementation of a DatasetGraph as an extensible set of graphs.
+ * Graphs are held by reference. Care is needed when manipulating their contents
+ * especially if they are also in another {@code DatasetGraph}. 
+ */
+public class DatasetGraphMapLink extends DatasetGraphCollection
+{
+    private final Transactional txn = new TransactionalMRSW() ;
+    @Override public void begin(ReadWrite mode)         { txn.begin(mode) ; }
+    @Override public void commit()                      { txn.commit() ; }
+    @Override public void abort()                       { txn.abort() ; }
+    @Override public boolean isInTransaction()          { return txn.isInTransaction() ; }
+    @Override public void end()                         { txn.end(); }
+    @Override public boolean supportsTransactions()     { return true ; }
+    @Override public boolean supportsTransactionAbort() { return false ; }
+    
+    private final GraphMaker graphMaker ;
+    private final Map<Node, Graph> graphs = new HashMap<>() ;
+
+    private Graph defaultGraph ;
+
+    /** Create a new DatasetGraph that initially shares the graphs of the
+     * given DatasetGraph.  Adding/removing graphs will only affect this
+     * object, not the argument DatasetGraph but changes to shared
+     * graphs are seen by both objects.
+     */
+    DatasetGraphMapLink(DatasetGraph dsg, GraphMaker graphMaker) {
+        this.graphMaker = graphMaker ; 
+        this.defaultGraph = dsg.getDefaultGraph() ;
+        for ( Iterator<Node> names = dsg.listGraphNodes() ; names.hasNext() ; ) {
+            Node gn = names.next() ;
+            addGraph(gn, dsg.getGraph(gn)) ;
+        }
+    }
+
+    /** 
+     *  A {@code DatasetGraph} with graphs for default and named graphs as given
+     *  but new graphs are created in memory.
+     */
+    DatasetGraphMapLink(DatasetGraph dsg) {
+        this(dsg, DatasetGraphFactory.memGraphMaker) ;
+    }
+
+    private DatasetGraphMapLink(Graph dftGraph, GraphMaker graphMaker) {
+        this.graphMaker = graphMaker;
+        this.defaultGraph = dftGraph ;
+    }
+    
+    /** A {@code DatasetGraph} with in-memory graphs for default and named graphs as needed */ 
+    public DatasetGraphMapLink() {
+        this(DatasetGraphFactory.memGraphMaker) ; 
+    }
+    
+    /*package*/ DatasetGraphMapLink(GraphMaker graphMaker) {
+        this(graphMaker.create(), graphMaker) ;
+    }
+
+    /** A {@code DatasetGraph} that uses the given graph for the default graph
+     *  and create in-memory graphs for named graphs as needed
+     */
+    public DatasetGraphMapLink(Graph dftGraph) {
+        this.defaultGraph = dftGraph ;
+        this.graphMaker = DatasetGraphFactory.graphMakerNull ;
+    }
+    
+    @Override
+    public boolean containsGraph(Node graphNode) {
+        return graphs.containsKey(graphNode);
+    }
+
+    @Override
+    public Graph getDefaultGraph() {
+        return defaultGraph;
+    }
+
+    @Override
+    public Graph getGraph(Node graphNode) {
+        Graph g = graphs.get(graphNode);
+        if ( g == null ) {
+            g = getGraphCreate();
+            if ( g != null )
+                addGraph(graphNode, g);
+        }
+        return g;
+    }
+
+    /** Called from getGraph when a nonexistent graph is asked for.
+     * Return null for "nothing created as a graph"
+     */
+    protected Graph getGraphCreate() { 
+        Graph g = graphMaker.create() ;
+        if ( g == null )
+            throw new ARQException("Can't make new graphs") ;
+        return g ;
+    }
+
+    @Override
+    public void addGraph(Node graphName, Graph graph) {
+        graphs.put(graphName, graph);
+    }
+
+    @Override
+    public void removeGraph(Node graphName) {
+        graphs.remove(graphName);
+    }
+
+    @Override
+    public void setDefaultGraph(Graph g) {
+        defaultGraph = g;
+    }
+
+    @Override
+    public Iterator<Node> listGraphNodes() {
+        return graphs.keySet().iterator();
+    }
+
+    @Override
+    public long size() {
+        return graphs.size();
+    }
+
+    @Override
+    public void close() {
+        defaultGraph.close();
+        for ( Graph graph : graphs.values() )
+            graph.close();
+        super.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
index 7f923a0..a12d5f4 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
@@ -18,6 +18,8 @@
 
 package org.apache.jena.sparql.core;
 
+import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph ;
+
 import java.util.Iterator ;
 
 import org.apache.jena.atlas.iterator.Iter ;

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTriplesQuads.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTriplesQuads.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTriplesQuads.java
index f5877dd..019e17a 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTriplesQuads.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTriplesQuads.java
@@ -63,7 +63,13 @@ public abstract class DatasetGraphTriplesQuads extends DatasetGraphBaseFind
     protected abstract void deleteFromDftGraph(Node s, Node p, Node o) ;
     protected abstract void deleteFromNamedGraph(Node g, Node s, Node p, Node o) ;
     
-    // Default implementations.
+    // Default implementations - copy based.
+    
+    @Override
+    public void setDefaultGraph(Graph graph) { 
+        GraphUtil.addInto(getDefaultGraph(), graph) ;
+    }
+    
     @Override
     public void addGraph(Node graphName, Graph graph) {
         GraphUtil.addInto(getGraph(graphName), graph) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
index f5f5c7f..6b7bae9 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
@@ -186,5 +186,15 @@ public class DatasetGraphWrapper implements DatasetGraph, Sync
     @Override
     public void end()
     { get().end() ; }
+
+    @Override
+    public boolean supportsTransactions() {
+        return get().supportsTransactions() ;
+    }
+
+    @Override
+    public boolean supportsTransactionAbort() {
+        return get().supportsTransactionAbort() ;
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
index f7c94e4..fdbb74b 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
@@ -52,14 +52,6 @@ public class DatasetImpl implements Dataset
         return ds ;
     }
     
-    /** Clone the structure of a DatasetGraph.
-     * The current graph themselves are shared but new naming and new graphs are
-     * only in the cloned    
-     */
-    public static Dataset cloneStructure(DatasetGraph datasetGraph) {
-        return new DatasetImpl(new DatasetGraphMap(datasetGraph));
-    }
-
     protected DatasetImpl(DatasetGraph dsg) {
         this(dsg, dsg);
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/DynamicDatasets.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DynamicDatasets.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DynamicDatasets.java
index e283fca..602cfa8 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DynamicDatasets.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DynamicDatasets.java
@@ -68,7 +68,7 @@ public class DynamicDatasets
     public static DatasetGraph dynamicDataset(Collection<Node> defaultGraphs, Collection<Node> namedGraphs, DatasetGraph dsg, boolean defaultUnionGraph)
     {
         Graph dft = new GraphUnionRead(dsg, defaultGraphs) ;
-        DatasetGraph dsg2 = new DatasetGraphMap(dft) ;
+        DatasetGraph dsg2 = new DatasetGraphMapLink(dft) ;
         
         // The named graphs.
         for ( Node gn : namedGraphs )

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalMRSW.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalMRSW.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalMRSW.java
index 56420d3..3b7f733 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalMRSW.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalMRSW.java
@@ -27,18 +27,20 @@ import org.apache.jena.sparql.JenaTransactionException ;
 
 /** An implementation of Tranactional that provides MRSW locking but no abort.
  *  This is often the best you can do for a system that does not itself provide transactions.
+ *  @apiNote
+ *  To use with implementation inheritance, for when you don't inherit:
+ *  <pre>
+ *      private final Transactional txn                     = new TransactionalMRSW() ;
+ *      {@literal @}Override public void begin(ReadWrite mode)         { txn.begin(mode) ; }
+ *      {@literal @}Override public void commit()                      { txn.commit() ; }
+ *      {@literal @}Override public void abort()                       { txn.abort() ; }
+ *      {@literal @}Override public boolean isInTransaction()          { return txn.isInTransaction() ; }
+ *      {@literal @}Override public void end()                         { txn.end(); }
+ *      {@literal @}Override public boolean supportsTransactions()     { return true ; }
+ *      {@literal @}Override public boolean supportsTransactionAbort() { return false ; }
+ *   </pre>
  */ 
 public class TransactionalMRSW implements Transactional {
-        
-    /* To use with implementation inheritance, for when you can't inherit:
-        private final Transactional txn = new TransactionalMRSW() ;
-        @Override public void begin(ReadWrite mode) { txn.begin(mode) ; }
-        @Override public void commit()              { txn.commit() ; }
-        @Override public void abort()               { txn.abort() ; }
-        @Override public boolean isInTransaction()  { return txn.isInTransaction() ; }
-        @Override public void end()                 { txn.end(); }
-     */
-    
     private final ThreadLocal<ReadWrite> txnMode  = ThreadLocal.withInitial( ()->null ) ;
     private final Lock lock ;
 

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
index 9517992..920c173 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
@@ -23,6 +23,7 @@ import static org.apache.jena.graph.Node.ANY;
 import static org.apache.jena.query.ReadWrite.READ;
 import static org.apache.jena.query.ReadWrite.WRITE;
 import static org.apache.jena.sparql.core.Quad.isUnionGraph;
+import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph ;
 import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.Iterator;

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/modify/GraphStoreBasic.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/GraphStoreBasic.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/GraphStoreBasic.java
index c601b71..35d7e95 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/GraphStoreBasic.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/GraphStoreBasic.java
@@ -18,7 +18,6 @@
 
 package org.apache.jena.sparql.modify;
 
-import org.apache.jena.query.Dataset ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetGraphWrapper ;
 import org.apache.jena.update.GraphStore ;
@@ -26,11 +25,6 @@ import org.apache.jena.update.GraphStore ;
 @SuppressWarnings("deprecation")
 public class GraphStoreBasic extends DatasetGraphWrapper implements GraphStore
 {
-    public GraphStoreBasic(Dataset ds)
-    { 
-        super(ds.asDatasetGraph()) ;
-    }
-
     public GraphStoreBasic(DatasetGraph dsg)
     { 
         super(dsg) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
index 4394655..a94f4e2 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
@@ -336,7 +336,7 @@ public class UpdateEngineWorker implements UpdateVisitor
         ThresholdPolicy<Binding> policy = ThresholdPolicyFactory.policyFromContext(datasetGraph.getContext());
         DataBag<Binding> db = BagFactory.newDefaultBag(policy, SerializationFactoryFinder.bindingSerializationFactory());
         try {
-            Iterator<Binding> bindings = evalBindings(el, null);
+            Iterator<Binding> bindings = evalBindings(el);
             db.addAll(bindings);
             Iter.close(bindings);
 
@@ -362,23 +362,16 @@ public class UpdateEngineWorker implements UpdateVisitor
         // WITH
         // USING overrides WITH
         if ( dsg == null && withGraph != null ) {
-            if ( false ) {
-                // Subtle difference : WITH <uri>... WHERE {}
-                // and an empty/unknown graph <uri>
-                //   rewrite with GRAPH -> no match.
-                //   redo as dataset with different default graph -> match
-                //     SPARQL is unclear about what happens when the graph does not exist.
-                //     but the rewrite with ElementNamedGraph is closer to SPARQL.
-                
-                // Ye Olde way - create a special dataset
-                dsg = processWithOld(update) ;
-                withGraph = null ;
-            }
-            else
-                // Better, treat as
-                // WHERE { GRAPH <with> { ... } }
-                // This is the SPARQL wording (which is a bit loose).  
-                elt = new ElementNamedGraph(withGraph, elt) ;
+            // Subtle difference : WITH <uri>... WHERE {}
+            // and an empty/unknown graph <uri>
+            //   rewrite with GRAPH -> no match.
+            //   redo as dataset with different default graph -> match
+            // SPARQL is unclear about what happens when the graph does not exist.
+            //   but the rewrite with ElementNamedGraph is closer to SPARQL.
+            // Better, treat as
+            // WHERE { GRAPH <with> { ... } }
+            // This is the SPARQL wording (which is a bit loose).  
+            elt = new ElementNamedGraph(withGraph, elt) ;
         }
 
         // WITH :
@@ -426,15 +419,6 @@ public class UpdateEngineWorker implements UpdateVisitor
         return DynamicDatasets.dynamicDataset(update.getUsing(), update.getUsingNamed(), datasetGraph, false);
     }
 
-    protected DatasetGraph processWithOld(UpdateModify update) {
-        Node withGraph = update.getWithIRI();
-        if ( withGraph == null )
-            return null;
-        Graph g = graphOrDummy(datasetGraph, withGraph);
-        DatasetGraph dsg = new DatasetGraphAltDefaultGraph(datasetGraph, g);
-        return dsg;
-    }
-
     private Graph graphOrDummy(DatasetGraph dsg, Node gn) {
         Graph g = graph(datasetGraph, gn);
         if ( g == null )
@@ -564,19 +548,9 @@ public class UpdateEngineWorker implements UpdateVisitor
         return query;
     }
 
-    protected Iterator<Binding> evalBindings(Element pattern, Node dftGraph) {
-        return evalBindings(elementToQuery(pattern), dftGraph);
-    }
-
-    protected Iterator<Binding> evalBindings(Query query, Node dftGraph) {
-        DatasetGraph dsg = datasetGraph;
-        if ( query != null ) {
-            if ( dftGraph != null ) {
-                Graph g = graphOrDummy(dsg, dftGraph);
-                dsg = new DatasetGraphAltDefaultGraph(dsg, g);
-            }
-        }
-        return evalBindings(query, dsg, inputBinding, context);
+    protected Iterator<Binding> evalBindings(Element pattern) {
+        Query query = elementToQuery(pattern);
+        return evalBindings(query, datasetGraph, inputBinding, context);
     }
 
     protected static Iterator<Binding> evalBindings(Query query, DatasetGraph dsg, Binding inputBinding, Context context) {

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
index b875760..56fcd60 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
@@ -35,7 +35,6 @@ import org.apache.jena.shared.JenaException ;
 import org.apache.jena.sparql.core.DatasetDescription ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetGraphFactory ;
-import org.apache.jena.sparql.core.Transactional ;
 import org.apache.jena.sparql.graph.GraphFactory ;
 
 /** Internal Dataset factory + graph equivalents. */
@@ -117,13 +116,17 @@ public class DatasetUtils
      */
     public static Dataset addInGraphs(Dataset ds, List<String> uriList, List<String> namedSourceList, String baseURI) {
         boolean transactionWrapper = ds.supportsTransactions() && !ds.isInTransaction();
-        if ( !transactionWrapper )
-            return addInGraphsWorker(ds, uriList, namedSourceList, baseURI);
+        if ( !transactionWrapper ) {
+            addInGraphsWorker(ds, uriList, namedSourceList, baseURI);
+            return ds ;
+        }
 
         // TODO Replace with Txn.executeWrite when Txn code ready.
         ds.begin(ReadWrite.WRITE);
         try {
-            return addInGraphsWorker(ds, uriList, namedSourceList, baseURI);
+             addInGraphsWorker(ds, uriList, namedSourceList, baseURI);
+             ds.commit() ;
+             return ds ;
         }
         catch (JenaException ex) {
             ds.abort();
@@ -136,7 +139,7 @@ public class DatasetUtils
         }
     }
 
-    private static Dataset addInGraphsWorker(Dataset ds, List<String> uriList, List<String> namedSourceList, String baseURI) {
+    private static void addInGraphsWorker(Dataset ds, List<String> uriList, List<String> namedSourceList, String baseURI) {
         if ( ds.getDefaultModel() == null )
             // Not that it should be null ...
             ds.setDefaultModel(GraphFactory.makeDefaultModel());
@@ -166,7 +169,6 @@ public class DatasetUtils
                 ds.addNamedModel(absURI, m);
             }
         }
-        return ds;
     }
     
     // ---- DatasetGraph level.
@@ -198,7 +200,8 @@ public class DatasetUtils
 
     public static DatasetGraph createDatasetGraph(List<String> uriList, List<String> namedSourceList, String baseURI) {
         DatasetGraph dsg = DatasetGraphFactory.createGeneral();
-        return addInGraphs(dsg, uriList, namedSourceList, baseURI);
+        addInGraphs(dsg, uriList, namedSourceList, baseURI);
+        return dsg ;
     }
     
     /** Add graphs into a DatasetGraph
@@ -207,33 +210,30 @@ public class DatasetUtils
      * @param uriList           Default graph
      * @param namedSourceList   Named graphs
      * @param baseURI
-     * @return Dataset, as passed in.
      */
-    private static DatasetGraph addInGraphs(DatasetGraph dsg, List<String> uriList, List<String> namedSourceList, String baseURI) {
-        if ( ! (dsg instanceof Transactional) )
-            return addInGraphsWorker(dsg, uriList, namedSourceList, baseURI) ;
-        Transactional transactional = (Transactional)dsg ;
+    private static void addInGraphs(DatasetGraph dsg, List<String> uriList, List<String> namedSourceList, String baseURI) {
+        if ( ! dsg.supportsTransactions() )
+            addInGraphsWorker(dsg, uriList, namedSourceList, baseURI) ;
         
-        if ( ! transactional.isInTransaction() )
-            return addInGraphsWorker(dsg, uriList, namedSourceList, baseURI);
+        if ( dsg.isInTransaction() )
+            addInGraphsWorker(dsg, uriList, namedSourceList, baseURI);
 
         // TODO Replace with Txn.executeWrite when Txn code ready.
-        transactional.begin(ReadWrite.WRITE);
+        dsg.begin(ReadWrite.WRITE);
         try {
-            return addInGraphsWorker(dsg, uriList, namedSourceList, baseURI);
+            addInGraphsWorker(dsg, uriList, namedSourceList, baseURI);
+            dsg.commit() ;
         }
         catch (JenaException ex) {
-            transactional.abort();
+            dsg.abort();
             throw ex;
         }
         finally {
-            if ( transactional.isInTransaction() )
-                transactional.commit();
-            transactional.end();
+            dsg.end();
         }
     }
 
-    private static DatasetGraph addInGraphsWorker(DatasetGraph dsg, List<String> uriList, List<String> namedSourceList, String baseURI) {
+    private static void addInGraphsWorker(DatasetGraph dsg, List<String> uriList, List<String> namedSourceList, String baseURI) {
         // Merge into background graph
         if ( uriList != null ) {
             Model m = GraphFactory.makeDefaultModel();
@@ -266,6 +266,5 @@ public class DatasetUtils
                 dsg.addGraph(gn, m.getGraph());
             }
         }
-        return dsg;
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
index 6fb0a63..eae8384 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
@@ -24,12 +24,14 @@ import java.util.Iterator ;
 import java.util.List ;
 import java.util.Set ;
 
+import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.query.* ;
 import org.apache.jena.rdf.model.* ;
+import org.apache.jena.sparql.core.Quad ;
 import org.apache.jena.sparql.util.NotUniqueException ;
 import org.apache.jena.sparql.util.PropertyRequiredException ;
 import org.apache.jena.sparql.util.QueryExecUtils ;
@@ -41,6 +43,18 @@ import org.apache.jena.vocabulary.RDF ;
 
 public class GraphUtils
 {
+    /** Convert an iterator of triples into quads for the default graph.
+     * This is {@link Quad#defaultGraphIRI}, not {@link Quad#defaultGraphNodeGenerated},
+     * which is for quads outside a dataset, usually the output of parsers. 
+     */
+    public static Iterator<Quad> triples2quadsDftGraph(Iterator<Triple> iter) {
+        return triples2quads(Quad.defaultGraphIRI, iter) ;
+    }
+
+    /** Convert an iterator of triples into quads for the specificed graph name. */
+    public static Iter<Quad> triples2quads(final Node graphNode, Iterator<Triple> iter) {
+        return Iter.iter(iter).map(t -> new Quad(graphNode, t)) ;
+    }
 
     public static List<String> multiValueString(Resource r, Property p)
     {

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-sdb/src/main/java/org/apache/jena/sdb/store/DatasetGraphSDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/store/DatasetGraphSDB.java b/jena-sdb/src/main/java/org/apache/jena/sdb/store/DatasetGraphSDB.java
index a4b68bf..f958151 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/store/DatasetGraphSDB.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/store/DatasetGraphSDB.java
@@ -35,6 +35,7 @@ import org.apache.jena.sparql.core.DatasetGraphTriplesQuads ;
 import org.apache.jena.sparql.core.Quad ;
 import org.apache.jena.sparql.core.TransactionalNotSupported ;
 import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.sparql.util.graph.GraphUtils ;
 
 public class DatasetGraphSDB extends DatasetGraphTriplesQuads 
     implements DatasetGraph, TransactionalNotSupported/** SDB uses JDBC transactions*/, Closeable
@@ -147,11 +148,11 @@ public class DatasetGraphSDB extends DatasetGraphTriplesQuads
         }
 
         public static Iterator<Quad> findInDftGraph(DatasetGraph dsg, Node s, Node p, Node o) {
-            return triples2quadsDftGraph(dsg.getDefaultGraph().find(s, p, o)) ;
+            return GraphUtils.triples2quadsDftGraph(dsg.getDefaultGraph().find(s, p, o)) ;
         }
 
         public static Iterator<Quad> findInSpecificNamedGraph(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
-            return triples2quadsDftGraph(dsg.getGraph(g).find(s, p, o)) ;
+            return GraphUtils.triples2quadsDftGraph(dsg.getGraph(g).find(s, p, o)) ;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/cf0aa842/jena-tdb/src/main/java/org/apache/jena/tdb/store/DatasetGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/DatasetGraphTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/DatasetGraphTDB.java
index 6f9a243..7072f85 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/DatasetGraphTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/DatasetGraphTDB.java
@@ -27,7 +27,6 @@ import org.apache.jena.atlas.lib.Sync ;
 import org.apache.jena.atlas.lib.tuple.Tuple ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
 import org.apache.jena.sparql.core.DatasetGraphTriplesQuads ;
 import org.apache.jena.sparql.core.Quad ;
 import org.apache.jena.sparql.core.TransactionalNotSupported ;
@@ -38,6 +37,7 @@ import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
 import org.apache.jena.tdb.sys.Session ;
 import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 import org.apache.jena.tdb.transaction.DatasetGraphTxn ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.* ;
 
 /** This is the class that creates a dataset over the storage. 
  *  The name is historical. "{@code TDBStorage}" might be ebtter nowadays. 
@@ -87,9 +87,6 @@ public class DatasetGraphTDB extends DatasetGraphTriplesQuads
     protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o)
     { return getQuadTable().find(Node.ANY, s, p, o) ; }
 
-    protected static Iterator<Quad> triples2quadsDftGraph(Iterator<Triple> iter)
-    { return triples2quads(Quad.defaultGraphIRI, iter) ; }
- 
     @Override
     protected void addToDftGraph(Node s, Node p, Node o)
     { getTripleTable().add(s,p,o) ; }


Mime
View raw message