You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/11/15 17:21:58 UTC

[2/6] jena git commit: Fix formatting. Use Txn.

Fix formatting. Use Txn.

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

Branch: refs/heads/master
Commit: 0af13c1f3fa7bf5c7da9426617191bdde0f419d6
Parents: 2c351ee
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Nov 14 14:27:42 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Nov 14 14:27:42 2016 +0000

----------------------------------------------------------------------
 .../java/arq/cmdline/ModDatasetAssembler.java   | 15 ++---
 .../java/arq/cmdline/ModDatasetGeneral.java     | 67 ++++++++------------
 2 files changed, 33 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/0af13c1f/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
index 840136c..9c1ffa0 100644
--- a/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
@@ -34,8 +34,7 @@ public class ModDatasetAssembler extends ModDataset
     private ModAssembler modAssembler = new ModAssembler() ;
 
     @Override
-    public Dataset createDataset()
-    {
+    public Dataset createDataset() {
         if ( modAssembler.getAssemblerFile() == null )
             return null ;
         
@@ -52,19 +51,15 @@ public class ModDatasetAssembler extends ModDataset
         catch (Exception ex)
         { throw new CmdException("Error creating dataset", ex) ; }
         return dataset ;
-        
     }
 
     @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        modAssembler.registerWith(cmdLine) ;
+    public void registerWith(CmdGeneral cmdLine) {
+        modAssembler.registerWith(cmdLine);
     }
 
     @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        modAssembler.processArgs(cmdLine) ;
+    public void processArgs(CmdArgModule cmdLine) {
+        modAssembler.processArgs(cmdLine);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/0af13c1f/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
index 0f9d665..57f0b19 100644
--- a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
@@ -27,10 +27,10 @@ import jena.cmd.CmdGeneral;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.query.DatasetFactory ;
 import org.apache.jena.query.LabelExistsException ;
-import org.apache.jena.query.ReadWrite ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.shared.JenaException ;
 import org.apache.jena.sparql.util.DatasetUtils ;
+import org.apache.jena.system.Txn;
 
 /** ModDataset: arguments to build a dataset - 
  * see also ModDatasetAssembler which extends ModDataset
@@ -40,10 +40,8 @@ public class ModDatasetGeneral extends ModDataset
 {
     // See also ModDatasetAssembler
     protected final ArgDecl graphDecl      = new ArgDecl(ArgDecl.HasValue, "graph") ;
-    protected final ArgDecl dataDecl      = new ArgDecl(ArgDecl.HasValue, "data") ;
+    protected final ArgDecl dataDecl       = new ArgDecl(ArgDecl.HasValue, "data") ;
     protected final ArgDecl namedGraphDecl = new ArgDecl(ArgDecl.HasValue, "named", "namedgraph", "namedGraph", "namedData", "nameddata") ;
-    //protected final ArgDecl dataFmtDecl    = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
-    //protected final ArgDecl dirDecl        = new ArgDecl(ArgDecl.HasValue, "dir") ;
     
     private List<String> dataURLs                = null ;
     private List<String> graphURLs               = null ;
@@ -51,8 +49,7 @@ public class ModDatasetGeneral extends ModDataset
     protected ModDatasetGeneral() {}
     
     @Override
-    public void registerWith(CmdGeneral cl)
-    {
+    public void registerWith(CmdGeneral cl) {
         cl.getUsage().startCategory("Dataset") ;
         cl.add(dataDecl,
                "--data=FILE",
@@ -62,24 +59,22 @@ public class ModDatasetGeneral extends ModDataset
                "Graph for default graph of the datset") ;
         cl.add(namedGraphDecl,
                "--namedGraph=FILE",
-               "Add a graph into the dataset as a named graph") ;
+               "Add a graph into the dataset as a named graph");
     }
-    
+
     @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        dataURLs = cmdLine.getValues(dataDecl) ;
-        graphURLs = cmdLine.getValues(graphDecl) ;
-        namedGraphURLs = cmdLine.getValues(namedGraphDecl) ;
+    public void processArgs(CmdArgModule cmdLine) {
+        dataURLs = cmdLine.getValues(dataDecl);
+        graphURLs = cmdLine.getValues(graphDecl);
+        namedGraphURLs = cmdLine.getValues(namedGraphDecl);
     }
     
     @Override
-    public Dataset createDataset()
-    {
-        // If nothing specified to the module.  Leave alone and hope the query has FROM/FROM NAMED
-        if (  ( dataURLs == null || dataURLs.size() == 0) &&
-              (graphURLs == null || graphURLs.size() == 0) &&
-              (namedGraphURLs == null || namedGraphURLs.size() == 0 ) )
+    public Dataset createDataset() {
+        // If nothing specified for this module, Leave alone and hope the query has FROM/FROM NAMED
+        if ( (dataURLs == null || dataURLs.size() == 0) &&
+             (graphURLs == null || graphURLs.size() == 0) &&
+             (namedGraphURLs == null || namedGraphURLs.size() == 0) )
             return null ;
         
         Dataset ds = DatasetFactory.createTxnMem() ;
@@ -94,25 +89,21 @@ public class ModDatasetGeneral extends ModDataset
         return ! list.isEmpty() ;
     }
     
-    protected void addGraphs(Dataset ds)
-    {
+    protected void addGraphs(Dataset ds) {
         try {
-            if ( hasEntries(dataURLs) ) 
-            {
-                if ( ds.supportsTransactions() )
-                    ds.begin(ReadWrite.WRITE) ;
-                
-                for ( String url : dataURLs )
-                    RDFDataMgr.read(ds, url) ;
-                
+            if ( hasEntries(dataURLs) ) {
                 if ( ds.supportsTransactions() ) {
-                    ds.commit() ;
-                    ds.end() ;
+                    Txn.executeWrite(ds, () -> {
+                        for ( String url : dataURLs )
+                            RDFDataMgr.read(ds, url);
+                    });
+                } else {
+                    for ( String url : dataURLs )
+                        RDFDataMgr.read(ds, url);
                 }
             }
-            
             if ( hasEntries(graphURLs) ||  hasEntries(namedGraphURLs) )
-                ds = DatasetUtils.addInGraphs(ds, graphURLs, namedGraphURLs, null) ;
+                DatasetUtils.addInGraphs(ds, graphURLs, namedGraphURLs, null) ;
         } 
         catch (LabelExistsException ex)
         { throw new CmdException(ex.getMessage()) ; }
@@ -122,13 +113,11 @@ public class ModDatasetGeneral extends ModDataset
         { throw new CmdException("Error creating dataset", ex) ; }
     }
 
-    public List<String> getGraphURLs()
-    {
-        return graphURLs ;
+    public List<String> getGraphURLs() {
+        return graphURLs;
     }
 
-    public List<String> getNamedGraphURLs()
-    {
-        return namedGraphURLs ;
+    public List<String> getNamedGraphURLs() {
+        return namedGraphURLs;
     }
 }