jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] jena git commit: JENA-1575: tdbloader - unnecessarily specific class cast.
Date Sun, 15 Jul 2018 16:05:49 GMT
Repository: jena
Updated Branches:
  refs/heads/master 084257d45 -> b7a2d311e


JENA-1575: tdbloader - unnecessarily specific class cast.

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

Branch: refs/heads/master
Commit: bd4f66969202f4514f000749b3c3bf65682f21fc
Parents: e15d2df
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Jul 12 23:38:52 2018 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Jul 13 14:26:17 2018 +0100

----------------------------------------------------------------------
 .../src/main/java/tdb/cmdline/CmdTDBGraph.java  | 85 +++++++++-----------
 jena-cmds/src/main/java/tdb/tdbloader.java      |  4 +-
 .../java/org/apache/jena/tdb/TDBLoader.java     | 37 ++++-----
 .../apache/jena/tdb/store/DatasetGraphTDB.java  |  8 +-
 .../org/apache/jena/tdb/store/GraphTDB.java     |  2 +-
 .../org/apache/jena/tdb/store/TestLoader.java   |  4 +-
 6 files changed, 65 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java b/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
index 2ec33a8..719c111 100644
--- a/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
+++ b/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
@@ -20,61 +20,56 @@ package tdb.cmdline;
 
 import jena.cmd.ArgDecl;
 import jena.cmd.CmdException;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.tdb.store.GraphNonTxnTDB ;
+import org.apache.jena.atlas.lib.Lib;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.tdb.store.GraphTDB;
 
-public abstract class CmdTDBGraph extends CmdTDB
-{
-    private static final ArgDecl argNamedGraph          = new ArgDecl(ArgDecl.HasValue, "graph")
;
-    protected String graphName = null ;
-    
-    protected CmdTDBGraph(String[] argv)
-    {
-        super(argv) ;
-        super.add(argNamedGraph, "--graph=IRI", "Act on a named graph") ;
+public abstract class CmdTDBGraph extends CmdTDB {
+    private static final ArgDecl argNamedGraph = new ArgDecl(ArgDecl.HasValue, "graph");
+    protected String             graphName     = null;
+
+    protected CmdTDBGraph(String[] argv) {
+        super(argv);
+        super.add(argNamedGraph, "--graph=IRI", "Act on a named graph");
     }
-    
+
     @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
+    protected void processModulesAndArgs() {
+        super.processModulesAndArgs();
         if ( contains(argNamedGraph) )
-            graphName = getValue(argNamedGraph) ; 
+            graphName = getValue(argNamedGraph);
     }
-    
-    protected Model getModel()
-    {
-        Dataset ds = tdbDatasetAssembler.getDataset() ;
-        
-        if ( graphName != null )
-        {
-            Model m = ds.getNamedModel(graphName) ;
+
+    protected Model getModel() {
+        Dataset ds = tdbDatasetAssembler.getDataset();
+
+        if ( graphName != null ) {
+            Model m = ds.getNamedModel(graphName);
             if ( m == null )
-                throw new CmdException("No such named graph (is this a TDB dataset?)") ;
-            return m ;
-        }
-        else
-            return ds.getDefaultModel() ;
+                throw new CmdException("No such named graph (is this a TDB dataset?)");
+            return m;
+        } else
+            return ds.getDefaultModel();
+    }
+
+    public Node getGraphName() {
+        return graphName == null ? null : NodeFactory.createURI(graphName);
     }
-    
-    public Node getGraphName()  { return graphName == null ? null : NodeFactory.createURI(graphName)
; } 
-    
-    protected GraphNonTxnTDB getGraph()
-    {
+
+    protected GraphTDB getGraph() {
+        DatasetGraph dsg = tdbDatasetAssembler.getDataset().asDatasetGraph();
         if ( graphName != null )
-            return (GraphNonTxnTDB)tdbDatasetAssembler.getDataset().getNamedModel(graphName).getGraph()
;
+            return (GraphTDB)dsg.getGraph(getGraphName());
         else
-            return (GraphNonTxnTDB)tdbDatasetAssembler.getDataset().getDefaultModel().getGraph()
;
+            return (GraphTDB)dsg.getDefaultGraph();
     }
-    
+
     @Override
-    protected String getCommandName()
-    {
-        return Lib.className(this) ;
+    protected String getCommandName() {
+        return Lib.className(this);
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/jena-cmds/src/main/java/tdb/tdbloader.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbloader.java b/jena-cmds/src/main/java/tdb/tdbloader.java
index 2d6a5f8..3baff15 100644
--- a/jena-cmds/src/main/java/tdb/tdbloader.java
+++ b/jena-cmds/src/main/java/tdb/tdbloader.java
@@ -27,7 +27,7 @@ import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RDFLanguages ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.TDBLoader ;
-import org.apache.jena.tdb.store.GraphNonTxnTDB ;
+import org.apache.jena.tdb.store.GraphTDB;
 import tdb.cmdline.CmdTDB ;
 import tdb.cmdline.CmdTDBGraph ;
 
@@ -124,7 +124,7 @@ public class tdbloader extends CmdTDBGraph {
 //    }
 
     void loadNamedGraph(List<String> urls) {
-        GraphNonTxnTDB graph = getGraph() ;
+        GraphTDB graph = getGraph() ;
         TDBLoader.load(graph, urls, showProgress) ;
         return ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/jena-tdb/src/main/java/org/apache/jena/tdb/TDBLoader.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBLoader.java b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBLoader.java
index 0183f2f..fd8f6ec 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBLoader.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBLoader.java
@@ -26,9 +26,9 @@ import org.apache.jena.atlas.lib.Timer ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.GraphNonTxnTDB ;
+import org.apache.jena.tdb.store.GraphTDB ;
 import org.apache.jena.tdb.store.bulkloader.BulkLoader ;
-import org.slf4j.Logger ;
+import org.apache.jena.tdb.sys.TDBInternal;
 
 /** Public interface to the loader functionality.
  * The bulk loader is not transactional. 
@@ -75,30 +75,29 @@ public class TDBLoader
     {
         TDBLoader loader = new TDBLoader() ;
         loader.setShowProgress(showProgress) ;
-        // TODO Lang version
         loader.loadDataset(dataset, input) ;
     }
     
     /** Load the contents of URL into a graph */
-    public static void load(GraphNonTxnTDB graph, String url)
+    public static void load(GraphTDB graph, String url)
     {
         load(graph, url, false) ;
     }
     
     /** Load the contents of URL into a graph */
-    public static void load(GraphNonTxnTDB graph, String url, boolean showProgress)
+    public static void load(GraphTDB graph, String url, boolean showProgress)
     {
         load(graph, asList(url), showProgress) ;
     }
 
     /** Load the contents of URL into a graph */
-    public static void load(GraphNonTxnTDB graph, List<String> urls)
+    public static void load(GraphTDB graph, List<String> urls)
     {
         load(graph, urls, false) ;
     }
     
     /** Load the contents of URL into a graph */
-    public static void load(GraphNonTxnTDB graph, List<String> urls, boolean showProgress)
+    public static void load(GraphTDB graph, List<String> urls, boolean showProgress)
     {
         TDBLoader loader = new TDBLoader() ;
         loader.setShowProgress(showProgress) ;
@@ -140,7 +139,6 @@ public class TDBLoader
     
     private boolean showProgress = true ;
     private boolean generateStats = true ;
-    private Logger loaderLog  = TDB.logLoader ;
     private boolean checking ;
     
     // ---- The class itself.
@@ -148,19 +146,19 @@ public class TDBLoader
     public TDBLoader() {}
 
     /** Load a graph from a URL - assumes URL names a triples format document*/
-    public void loadGraph(GraphNonTxnTDB graph, String url)
+    public void loadGraph(GraphTDB graph, String url)
     {
         loadGraph(graph, asList(url)) ;
     }
     
     /** Load a graph from a list of URL - assumes the URLs name triples format documents
*/
-    public void loadGraph(GraphNonTxnTDB graph, List<String> urls)
+    public void loadGraph(GraphTDB graph, List<String> urls)
     {
         loadGraph$(graph, urls, showProgress, generateStats) ;
     }
     
     /** Load a graph from a list of URL - assumes the URLs name triples format documents
*/
-    public void loadGraph(GraphNonTxnTDB graph, InputStream in)
+    public void loadGraph(GraphTDB graph, InputStream in)
     {
         loadGraph$(graph, in, showProgress, generateStats) ;
     }
@@ -204,13 +202,7 @@ public class TDBLoader
     public final void setGenerateStats(boolean generateStats)
     { this.generateStats = generateStats ; }
     
-//    public final Logger getLogger()
-//    { return this.loaderLog ; }
-//
-//    public final void setLogger(Logger log)
-//    { this.loaderLog = log ; }
-    
-    private static void loadGraph$(GraphNonTxnTDB graph, List<String> urls, boolean
showProgress, boolean collectStats) {
+    private static void loadGraph$(GraphTDB graph, List<String> urls, boolean showProgress,
boolean collectStats) {
         if ( graph.getGraphName() == null )
             loadDefaultGraph$(graph.getDatasetGraphTDB(), urls, showProgress, collectStats)
;
         else
@@ -219,11 +211,14 @@ public class TDBLoader
 
     // These are the basic operations for TDBLoader.
 
-    private static void loadGraph$(GraphNonTxnTDB graph, InputStream input, boolean showProgress,
boolean collectStats) {
+    private static void loadGraph$(GraphTDB graph, InputStream input, boolean showProgress,
boolean collectStats) {
+        
+        DatasetGraphTDB dsgtdb = TDBInternal.getBaseDatasetGraphTDB(graph.getDatasetGraphTDB());
+        
         if ( graph.getGraphName() == null )
-            loadDefaultGraph$(graph.getDatasetGraphTDB(), input, showProgress, collectStats)
;
+            loadDefaultGraph$(dsgtdb, input, showProgress, collectStats) ;
         else
-            loadNamedGraph$(graph.getDatasetGraphTDB(), graph.getGraphName(), input, showProgress,
collectStats) ;
+            loadNamedGraph$(dsgtdb, graph.getGraphName(), input, showProgress, collectStats)
;
     }
 
     private static void loadDefaultGraph$(DatasetGraphTDB dataset, List<String> urls,
boolean showProgress, boolean collectStats) {

http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/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 7d62863..7142269 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
@@ -104,11 +104,11 @@ public class DatasetGraphTDB extends DatasetGraphTriplesQuads
     protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o)
     { getQuadTable().delete(g, s, p, o) ; }
     
-    public GraphNonTxnTDB getDefaultGraphTDB() 
-    { return (GraphNonTxnTDB)getDefaultGraph() ; }
+    public GraphTDB getDefaultGraphTDB() 
+    { return (GraphTDB)getDefaultGraph() ; }
 
-    public GraphNonTxnTDB getGraphTDB(Node graphNode)
-    { return (GraphNonTxnTDB)getGraph(graphNode) ; }
+    public GraphTDB getGraphTDB(Node graphNode)
+    { return (GraphTDB)getGraph(graphNode) ; }
 
     @Override
     public void close() {

http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
index bf43b1c..e881a8a 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
@@ -64,7 +64,7 @@ public abstract class GraphTDB extends GraphView implements Closeable, Sync
{
      * For transactional, it is the transactional view.
      * <p>
      * Immediate validity only.
-     * Not valid across transatcion boundaries, nor non-transactional to transactional. 
+     * Not valid across transaction boundaries, nor non-transactional to transactional. 
      */
     public abstract DatasetGraphTDB getDatasetGraphTDB() ;
     

http://git-wip-us.apache.org/repos/asf/jena/blob/bd4f6696/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java b/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
index d2c1a14..0ebf6ef 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
@@ -146,7 +146,7 @@ public class TestLoader extends BaseTest {
     @Test
     public void load_graph_05() {
         DatasetGraphTDB dsg = fresh() ;
-        GraphNonTxnTDB graph = dsg.getDefaultGraphTDB() ;
+        GraphTDB graph = dsg.getDefaultGraphTDB() ;
         TDBLoader.load(graph, DIR + "data-4.ttl", false) ;
         String uri = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
         assertEquals("http://example/", uri) ;
@@ -155,7 +155,7 @@ public class TestLoader extends BaseTest {
     @Test
     public void load_graph_06() {
         DatasetGraphTDB dsg = fresh() ;
-        GraphNonTxnTDB graph = dsg.getGraphTDB(g) ;
+        GraphTDB graph = dsg.getGraphTDB(g) ;
         TDBLoader.load(graph, DIR + "data-4.ttl", false) ;
         String uri1 = dsg.getGraph(g).getPrefixMapping().getNsPrefixURI("") ;
         assertEquals("http://example/", uri1) ;


Mime
View raw message