jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [10/34] jena git commit: Add sdb.sdbupdate. Tidy commands.
Date Sat, 06 Feb 2016 15:50:59 GMT
Add sdb.sdbupdate. Tidy commands.

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

Branch: refs/heads/master
Commit: ce26db2fc9af9bfe428e3833ca236b2a3422b7cb
Parents: d5188e9
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Feb 4 14:04:28 2016 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Feb 5 19:14:08 2016 +0000

----------------------------------------------------------------------
 jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java |   8 --
 jena-sdb/src/main/java/sdb/cmd/ModGraph.java  |   7 +-
 jena-sdb/src/main/java/sdb/sdbdump.java       |  35 +++++---
 jena-sdb/src/main/java/sdb/sdbupdate.java     | 100 +++++++++++++++++++++
 4 files changed, 125 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/ce26db2f/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java b/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
index 0b039aa..969b0e4 100644
--- a/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
+++ b/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
@@ -31,14 +31,6 @@ import arq.cmdline.ModTime ;
 
 public abstract class CmdArgsDB extends CmdARQ
 {
-    static {
-        //  Tune N3 output for result set output.
-        System.setProperty("usePropertySymbols",   "false") ;
-        System.setProperty("objectLists" ,         "false") ;
-        System.setProperty("minGap",               "2") ;
-        System.setProperty("propertyColumn",       "14") ;
-    }
-    
     private ModStore  modStore  = new ModStore() ;
     private ModTime   modTime   = new ModTime() ;
     private ModLogSQL modLogSQL = new ModLogSQL() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/ce26db2f/jena-sdb/src/main/java/sdb/cmd/ModGraph.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/sdb/cmd/ModGraph.java b/jena-sdb/src/main/java/sdb/cmd/ModGraph.java
index 1d6df21..0e6bb72 100644
--- a/jena-sdb/src/main/java/sdb/cmd/ModGraph.java
+++ b/jena-sdb/src/main/java/sdb/cmd/ModGraph.java
@@ -31,7 +31,6 @@ import org.apache.jena.sdb.Store ;
 public class ModGraph extends ModBase
 {
     private static ArgDecl argDeclGraphName = new ArgDecl(true, "graph") ;
-    private static ArgDecl argDeclGraphDeafult = new ArgDecl(false, "default") ;
 
     private Graph graph = null ;
     private String graphName = null ;
@@ -51,9 +50,11 @@ public class ModGraph extends ModBase
         graphName = cmdLine.getValue(argDeclGraphName) ;
     }
 
+    public String getGraphName() { return graphName ; }
+    
     public Graph getGraph(Store store)
     { 
-        if ( graphName == null )
+        if ( graphName == null || graphName.equals("default") )
             return SDBFactory.connectDefaultGraph(store) ;
         else
             return SDBFactory.connectNamedGraph(store, graphName) ;
@@ -61,7 +62,7 @@ public class ModGraph extends ModBase
     
     public Model getModel(Store store)
     { 
-        if ( graphName == null )
+        if ( graphName == null || graphName.equals("default") )
             return SDBFactory.connectDefaultModel(store) ;
         else
             return SDBFactory.connectNamedModel(store, graphName) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/ce26db2f/jena-sdb/src/main/java/sdb/sdbdump.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/sdb/sdbdump.java b/jena-sdb/src/main/java/sdb/sdbdump.java
index d557933..12456cd 100644
--- a/jena-sdb/src/main/java/sdb/sdbdump.java
+++ b/jena-sdb/src/main/java/sdb/sdbdump.java
@@ -21,11 +21,13 @@ package sdb;
 import java.util.List;
 
 import jena.cmd.ArgDecl;
-
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.Dataset ;
 import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.RDFLanguages ;
 import org.apache.jena.sdb.SDB ;
-import org.apache.jena.atlas.lib.Lib ;
-
 import sdb.cmd.CmdArgsDB;
 import sdb.cmd.ModGraph;
 
@@ -79,19 +81,24 @@ public class sdbdump extends CmdArgsDB
     protected void execCmd(List<String> args)
     {
         // This is a streamable syntax.
-        String syntax = "N-TRIPLES" ;
+        String syntax = "N-QUADS";
         if ( contains(argDeclSyntax) )
-            syntax = getArg(argDeclSyntax).getValue() ;
-        if ( isDebug() )
-            System.out.println("Debug: syntax is "+syntax) ;
-        
+            syntax = getArg(argDeclSyntax).getValue();
+        Lang lang = RDFLanguages.nameToLang(syntax);
+
         try {
-            Model model = modGraph.getModel(getStore()) ;
-            model.write(System.out, syntax) ;
-        } catch (Exception ex)
-        {
-            System.err.println("Exception: "+ex+" :: "+ex.getMessage()) ;
-            ex.printStackTrace(System.err) ;
+            if ( modGraph.getGraphName() == null ) {
+                System.err.println("DATASET:"+lang) ;
+                Dataset dataset = getModStore().getDataset();
+                RDFDataMgr.write(System.out, dataset, lang);
+            } else {
+                Model model = modGraph.getModel(getStore());
+                RDFDataMgr.write(System.out, model, lang);
+            }
+        }
+        catch (Exception ex) {
+            System.err.println("Exception: " + ex + " :: " + ex.getMessage());
+            ex.printStackTrace(System.err);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/ce26db2f/jena-sdb/src/main/java/sdb/sdbupdate.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/sdb/sdbupdate.java b/jena-sdb/src/main/java/sdb/sdbupdate.java
new file mode 100644
index 0000000..6475a07
--- /dev/null
+++ b/jena-sdb/src/main/java/sdb/sdbupdate.java
@@ -0,0 +1,100 @@
+/*
+ * 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 sdb;
+
+
+import java.util.List;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.sdb.SDB ;
+import org.apache.jena.sdb.compiler.SDB_QC ;
+import org.apache.jena.update.UpdateExecutionFactory ;
+import org.apache.jena.update.UpdateFactory ;
+import org.apache.jena.update.UpdateRequest ;
+import sdb.cmd.CmdArgsDB;
+
+ 
+public class sdbupdate extends CmdArgsDB
+{
+    static final ArgDecl updateArg = new ArgDecl(ArgDecl.HasValue, "update", "file") ;
+    
+    List<String> requestFiles = null ;
+    
+    public static void main(String... argv) {
+        SDB.init();
+        new sdbupdate(argv).mainRun();
+    }
+   
+    protected sdbupdate(String... args)
+    {
+        super(args);
+        super.add(updateArg, "--update=FILE", "Update commands to execute") ;
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary()  { return getCommandName()+" <SPEC> [ <update>
|  --update=file ]"; }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs(); 
+    }
+    
+    static final String divider = "- - - - - - - - - - - - - -" ;
+    
+    @Override
+    protected void execCmd(List<String> positionalArgs)
+    {
+        if ( isVerbose() )
+            SDB_QC.PrintSQL = true ;
+        
+        getStore() ;
+        Dataset dataset = getModStore().getDataset() ;
+
+        List<String> requestFiles = getValues(updateArg) ;
+        
+        if ( requestFiles.size() == 0 && getPositional().size() == 0 )
+            throw new CmdException("Nothing to do") ;
+
+        for ( String filename : requestFiles )
+            execOneFile(filename, dataset) ;
+
+        for ( String requestString : super.getPositional() ) {
+            requestString = indirect(requestString) ;
+            execOne(requestString, dataset) ;
+        }
+    }
+
+    private void execOneFile(String filename, Dataset store) {
+        UpdateRequest req = UpdateFactory.read(filename, Syntax.syntaxARQ) ;
+        UpdateExecutionFactory.create(req, store).execute() ;
+    }
+
+    private void execOne(String requestString, Dataset store) {
+        UpdateRequest req = UpdateFactory.create(requestString, Syntax.syntaxARQ) ;
+        UpdateExecutionFactory.create(req, store).execute() ;
+    }
+}


Mime
View raw message