jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [03/34] jena git commit: Refactor the do-nothing DatasetGraphs.
Date Sat, 17 Nov 2018 17:20:29 GMT
Refactor the do-nothing DatasetGraphs.

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

Branch: refs/heads/master
Commit: c846b05517da4b6e2bf43dd49afe8392ac3e7069
Parents: 512f663
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Nov 1 09:37:10 2018 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Nov 13 15:35:19 2018 +0000

----------------------------------------------------------------------
 .../jena/sparql/core/DatasetGraphNull.java      | 125 +++++++++++++++++++
 .../jena/sparql/core/DatasetGraphOne.java       |  26 ++--
 .../jena/sparql/core/DatasetGraphReadOnly.java  |   2 +-
 .../jena/sparql/core/DatasetGraphSink.java      |  51 +-------
 .../jena/sparql/core/DatasetGraphZero.java      |  85 +------------
 .../org/apache/jena/sparql/graph/GraphZero.java |   2 +-
 6 files changed, 151 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphNull.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphNull.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphNull.java
new file mode 100644
index 0000000..a01fc5c
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphNull.java
@@ -0,0 +1,125 @@
+/*
+ * 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.Iterator;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.query.ReadWrite;
+import org.apache.jena.query.TxnType;
+
+/** A {@link DatasetGraph} class for support of {@link DatasetGraph DatasetGraphs} that do
nothing.
+ *  <ul> 
+ *  <li>No named graphs.
+ *  <li>Empty default graph.
+ *  <li>Empty union graph.
+ *  <li>No update. ({@link DatasetGraphSink} overrides this)
+ *  </ul>
+ *  
+ * @see DatasetGraphSink
+ * @see DatasetGraphZero
+ */
+public abstract class DatasetGraphNull extends DatasetGraphBaseFind {
+    protected abstract Graph createGraph();  
+    private Graph dftGraph = createGraph(); 
+    private Graph unionGraph = createGraph(); 
+
+    protected DatasetGraphNull() {}
+    
+    private Transactional txn                           = TransactionalNull.create();
+    @Override public void begin()                       { txn.begin(); }
+    @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
+    @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
+    @Override public boolean promote(Promote txnType)   { return txn.promote(txnType); }
+    @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 ReadWrite transactionMode()        { return txn.transactionMode(); }
+    @Override public TxnType transactionType()          { return txn.transactionType(); }
+    @Override public boolean supportsTransactions()     { return true; }
+    @Override public boolean supportsTransactionAbort() { return true; }
+
+    @Override
+    public Iterator<Node> listGraphNodes() {
+        return Iter.nullIterator();
+    }
+    
+    @Override
+    protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
+        return Iter.nullIterator();
+    }
+    
+    @Override
+    protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node
o) {
+        return Iter.nullIterator();
+    }
+    
+    @Override
+    protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
+        return Iter.nullIterator();
+    }
+    
+    @Override
+    public Graph getDefaultGraph() {
+        return dftGraph;
+    }
+    
+    @Override
+    public Graph getUnionGraph() {
+        return unionGraph;
+    }
+    
+    @Override
+    public Graph getGraph(Node graphNode) {
+        if ( Quad.isDefaultGraph(graphNode) )
+            return dftGraph;
+        if ( Quad.isUnionGraph(graphNode) )
+            return getUnionGraph();
+        return null;
+    }
+    
+    @Override
+    public void add(Quad quad) { unsupportedMethod(this, "add") ; } 
+    
+    @Override
+    public void delete(Quad quad) { unsupportedMethod(this, "delete") ; }
+    
+    @Override
+    public void deleteAny(Node g, Node s, Node p, Node o) {
+        unsupportedMethod(this, "deleteAny");
+    }
+
+    @Override
+    public void setDefaultGraph(Graph g) {
+        unsupportedMethod(this, "setDefaultGraph");
+    }
+
+    @Override
+    public void addGraph(Node graphName, Graph graph) {
+        unsupportedMethod(this, "addGraph");
+    }
+
+    @Override
+    public void removeGraph(Node graphName) {
+        unsupportedMethod(this, "removeGraph");
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/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 2aa627d..cbcf2ed 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
@@ -27,11 +27,11 @@ import org.apache.jena.atlas.iterator.NullIterator;
 import org.apache.jena.graph.Graph;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.Triple;
-import org.apache.jena.graph.impl.WrappedGraph;
 import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
 import org.apache.jena.reasoner.InfGraph;
-import org.apache.jena.sparql.graph.GraphWrapper;
+import org.apache.jena.sparql.graph.GraphOps;
+import org.apache.jena.sparql.graph.GraphZero;
 
 /** DatasetGraph of a single graph as default graph.
  * <p>
@@ -65,15 +65,10 @@ public class DatasetGraphOne extends DatasetGraphBaseFind {
                 graph = ((InfGraph)graph).getRawGraph();
                 continue;
             }
-            if ( graph instanceof GraphWrapper ) {
-                graph = ((GraphWrapper)graph).get();
-                continue;
-            }
-            if ( graph instanceof WrappedGraph ) {
-                graph = ((WrappedGraph)graph).getWrapped();
-                continue;
-            }
-            return graph;
+            Graph graph2 = GraphOps.unwrapOne(graph);
+            if ( graph2 == graph )
+                return graph;
+            graph = graph2;
         }
     }
     
@@ -123,11 +118,18 @@ public class DatasetGraphOne extends DatasetGraphBaseFind {
     public Graph getDefaultGraph() {
         return graph;
     }
+    
+    @Override
+    public Graph getUnionGraph() {
+        return GraphZero.instance();
+    }
 
     @Override
     public Graph getGraph(Node graphNode) {
         if ( isDefaultGraph(graphNode) )
-            return graph;
+            return getDefaultGraph();
+        if ( Quad.isUnionGraph(graphNode) )
+            return getUnionGraph();
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphReadOnly.java
----------------------------------------------------------------------
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 06aae4f..7b624b4 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
@@ -49,7 +49,7 @@ public class DatasetGraphReadOnly extends DatasetGraphWrapper
     @Override public void begin(ReadWrite mode)         {
         if ( mode == ReadWrite.WRITE )
             //throw new JenaTransactionException("read-only dataset : no write transactions")
;
-            Log.warn(this,  "Write transaction on a read-only dataset") ;
+            Log.warn(this, "Write transaction on a read-only dataset") ;
         get().begin(mode) ; 
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
index 88716ca..7a5faa6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
@@ -18,13 +18,8 @@
 
 package org.apache.jena.sparql.core;
 
-import java.util.Iterator;
-
-import org.apache.jena.atlas.iterator.Iter;
 import org.apache.jena.graph.Graph;
 import org.apache.jena.graph.Node;
-import org.apache.jena.query.ReadWrite;
-import org.apache.jena.query.TxnType;
 import org.apache.jena.sparql.graph.GraphSink;
 
 
@@ -33,56 +28,20 @@ import org.apache.jena.sparql.graph.GraphSink;
  * 
  * @see DatasetGraphZero - a DSG that does not allow changes.
  */
-public class DatasetGraphSink extends DatasetGraphBaseFind {
+public class DatasetGraphSink extends DatasetGraphNull {
 
     public static DatasetGraph create() { return new DatasetGraphSink(); }
     
-    private Graph dftGraph = GraphSink.instance();
-    
-    public DatasetGraphSink() {}
-    
-    private Transactional txn                           = TransactionalNull.create();
-    @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
-    @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote(Promote txnType)   { return txn.promote(txnType); }
-    @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 ReadWrite transactionMode()        { return txn.transactionMode(); }
-    @Override public TxnType transactionType()          { return txn.transactionType(); }
-    @Override public boolean supportsTransactions()     { return true; }
-    @Override public boolean supportsTransactionAbort() { return true; }
-    
     @Override
-    public Iterator<Node> listGraphNodes() {
-        return Iter.nullIterator();
+    protected Graph createGraph() {
+        return GraphSink.instance();
     }
     
-    @Override
-    protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
-        return Iter.nullIterator();
-    }
-    
-    @Override
-    protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node
o) {
-        return Iter.nullIterator();
-    }
+    public DatasetGraphSink() {}
     
-    @Override
-    protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
-        return Iter.nullIterator();
-    }
+    // Ignore all updates.
     
     @Override
-    public Graph getDefaultGraph() {
-        return dftGraph;
-    }
-    @Override
-    public Graph getGraph(Node graphNode) {
-        return null;
-    }
-    @Override
     public void add(Quad quad) { /* ignore */ } 
     
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
index 702f7bb..32f0469 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
@@ -18,13 +18,7 @@
 
 package org.apache.jena.sparql.core;
 
-import java.util.Iterator;
-
-import org.apache.jena.atlas.iterator.Iter;
 import org.apache.jena.graph.Graph;
-import org.apache.jena.graph.Node;
-import org.apache.jena.query.ReadWrite;
-import org.apache.jena.query.TxnType;
 import org.apache.jena.sparql.graph.GraphZero;
 
 /** An always empty {@link DatasetGraph}. 
@@ -32,83 +26,14 @@ import org.apache.jena.sparql.graph.GraphZero;
  * No changes allowed - this is not a sink.
  * @see DatasetGraphSink
  */
-public class DatasetGraphZero extends DatasetGraphBaseFind {
-
-    // Invariant DatasetGraph; it does have tarnsaction state so new object here.
+public class DatasetGraphZero extends DatasetGraphNull {
+    /**Invariant {@link DatasetGraph}; it does have transaction state so new object here.
*/
     public static DatasetGraph create() { return new DatasetGraphZero(); }
-    
-    private Graph dftGraph = GraphZero.instance();
-
-    public DatasetGraphZero() {}
-    
-    private Transactional txn                           = TransactionalNull.create();
-    @Override public void begin()                       { txn.begin(); }
-    @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
-    @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote(Promote txnType)   { return txn.promote(txnType); }
-    @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 ReadWrite transactionMode()        { return txn.transactionMode(); }
-    @Override public TxnType transactionType()          { return txn.transactionType(); }
-    @Override public boolean supportsTransactions()     { return true; }
-    @Override public boolean supportsTransactionAbort() { return true; }
 
-    
-    @Override
-    public Iterator<Node> listGraphNodes() {
-        return Iter.nullIterator();
-    }
-    
-    @Override
-    protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
-        return Iter.nullIterator();
-    }
-    
-    @Override
-    protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node
o) {
-        return Iter.nullIterator();
-    }
-    
-    @Override
-    protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
-        return Iter.nullIterator();
-    }
-    
     @Override
-    public Graph getDefaultGraph() {
-        return dftGraph;
+    protected Graph createGraph() {
+        return GraphZero.instance();
     }
     
-    @Override
-    public Graph getGraph(Node graphNode) {
-        return null;
-    }
-    
-    @Override
-    public void add(Quad quad) { unsupportedMethod(this, "add") ; } 
-    
-    @Override
-    public void delete(Quad quad) { unsupportedMethod(this, "delete") ; }
-    
-    @Override
-    public void deleteAny(Node g, Node s, Node p, Node o) {
-        throw new UnsupportedOperationException("deleteAny");
-    }
-
-    @Override
-    public void setDefaultGraph(Graph g) {
-        throw new UnsupportedOperationException("setDefaultGraph");
-    }
-
-    @Override
-    public void addGraph(Node graphName, Graph graph) {
-        throw new UnsupportedOperationException("addGraph");
-    }
-
-    @Override
-    public void removeGraph(Node graphName) {
-        throw new UnsupportedOperationException("removeGraph");
-    }
+    public DatasetGraphZero() {}
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/c846b055/jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphZero.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphZero.java b/jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphZero.java
index 479340b..d3076c2 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphZero.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphZero.java
@@ -34,7 +34,7 @@ import org.apache.jena.util.iterator.NullIterator;
 public class GraphZero extends GraphBase {
     
     public static Graph instance() {
-        // It has transaction state do unsafe to share one object on one thread. 
+        // It has transaction state so unsafe to share one object on one thread. 
         return new GraphZero();
     }
 


Mime
View raw message