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 2017/06/29 10:45:38 UTC

[02/11] jena git commit: Rename is dumpnodes

Rename is dumpnodes

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

Branch: refs/heads/master
Commit: 91a65ad2a7e6e0d11dbd1672837b0addb5d12423
Parents: 0ab57c0
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 27 22:41:03 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 27 22:41:03 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/tdb/tools/dumpnodes.java      | 188 +++++++++++++++++++
 .../src/main/java/tdb/tools/dumpnodetable.java  | 184 ------------------
 .../src/main/java/tdb/tools/dumpnodetable1.java | 184 ------------------
 3 files changed, 188 insertions(+), 368 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/91a65ad2/jena-cmds/src/main/java/tdb/tools/dumpnodes.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/dumpnodes.java b/jena-cmds/src/main/java/tdb/tools/dumpnodes.java
new file mode 100644
index 0000000..933517f
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tools/dumpnodes.java
@@ -0,0 +1,188 @@
+/*
+ * 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 tdb.tools ;
+
+import java.io.OutputStream ;
+import java.nio.ByteBuffer ;
+import java.util.Iterator ;
+import java.util.function.Function ;
+
+import arq.cmdline.CmdARQ;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.Pair ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Node_Literal ;
+import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.tdb.base.file.FileFactory ;
+import org.apache.jena.tdb.base.file.FileSet ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.objectfile.ObjectFile ;
+import org.apache.jena.tdb.lib.NodeLib ;
+import org.apache.jena.tdb.setup.StoreParams ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.sys.Names ;
+import tdb.cmdline.ModLocation ;
+
+public class dumpnodes extends CmdARQ {
+    ModLocation modLocation = new ModLocation() ;
+
+    static public void main(String... argv) {
+        LogCtl.setLog4j() ;
+        new dumpnodes(argv).mainRun() ;
+    }
+
+    @Override
+    protected void exec() {
+        Location loc = modLocation.getLocation() ;
+        ObjectFile objFile = determineNodeTable(loc);
+        dump(System.out, objFile) ;
+    }
+    
+    private ObjectFile determineNodeTable(Location loc) {
+        // Directly open the nodes.dat file.
+        StoreParams storeParams = StoreParams.getDftStoreParams();
+        FileSet fsId2Node = new FileSet(loc, storeParams.getIndexId2Node()) ;
+        
+        String file = fsId2Node.filename(Names.extNodeData);
+        ObjectFile objFile = FileFactory.createObjectFileDisk(file);
+        return objFile;
+    }
+
+    protected dumpnodes(String[] argv) {
+        super(argv) ;
+        super.addModule(modLocation) ;
+    }
+
+    // Taken from NodeTableNative.
+    private static Iterator<Pair<NodeId, Node>> all(ObjectFile objFile)
+    {
+        Iterator<Pair<Long, ByteBuffer>> objs = objFile.all() ; 
+        Function<Pair<Long, ByteBuffer>, Pair<NodeId, Node>> transform = item -> {
+            NodeId id = NodeId.create(item.car().longValue());
+            ByteBuffer bb = item.cdr();
+            Node n = NodeLib.decode(bb);
+            return new Pair<>(id, n);
+        };
+        return Iter.map(objs, transform) ;
+    }
+    
+    public static void dump(OutputStream w, ObjectFile objFile) {
+        // Better to hack the indexes?
+        Iterator<Pair<NodeId, Node>> iter = all(objFile) ;
+        long count = 0 ;
+        try (IndentedWriter iw = new IndentedWriter(w)) {
+            if ( ! iter.hasNext() ) {
+                iw.println("No nodes in the .dat file");
+                return ;
+            }
+            
+            for ( ; iter.hasNext() ; ) {
+                Pair<NodeId, Node> pair = iter.next() ;
+                iw.print(pair.car().toString()) ;
+                iw.print(" : ") ;
+                // iw.print(pair.cdr()) ;
+                Node n = pair.cdr() ;
+                String $ = stringForNode(n) ;
+                iw.print($) ;
+                iw.println() ;
+                count++ ;
+            }
+            iw.println() ;
+            iw.printf("Total: " + count) ;
+            iw.println() ;
+            iw.flush() ;
+        }
+    }
+
+    private static String stringForNode(Node n) {
+        if ( n == null )
+            return "<<null>>" ;
+
+        if ( n.isBlank() )
+            return "_:" + n.getBlankNodeLabel() ;
+
+        if ( n.isLiteral() )
+            return stringForLiteral((Node_Literal)n) ;
+
+        if ( n.isURI() ) {
+            String uri = n.getURI() ;
+            return stringForURI(uri) ;
+        }
+
+        if ( n.isVariable() )
+            return "?" + n.getName() ;
+
+        if ( n.equals(Node.ANY) )
+            return "ANY" ;
+
+        Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ;
+        return n.toString() ;
+    }
+
+    public static String stringForURI(String uri) {
+        return "<" + uri + ">" ;
+    }
+
+    public static String stringForLiteral(Node_Literal literal) {
+        String datatype = literal.getLiteralDatatypeURI() ;
+        String lang = literal.getLiteralLanguage() ;
+        String s = literal.getLiteralLexicalForm() ;
+
+        StringBuilder sbuff = new StringBuilder() ;
+        sbuff.append("\"") ;
+        FmtUtils.stringEsc(sbuff, s, true) ;
+        sbuff.append("\"") ;
+
+        // Format the language tag
+        if ( lang != null && lang.length() > 0 ) {
+            sbuff.append("@") ;
+            sbuff.append(lang) ;
+        }
+
+        if ( datatype != null ) {
+            sbuff.append("^^") ;
+            sbuff.append(stringForURI(datatype)) ;
+        }
+
+        return sbuff.toString() ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        if ( modVersion.getVersionFlag() )
+            modVersion.printVersionAndExit() ;
+        if ( modLocation.getLocation() == null )
+            cmdError("Location required") ;
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName() + " --loc=DIR IndexName" ;
+    }
+
+    @Override
+    protected String getCommandName() {
+        return Lib.className(this) ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/91a65ad2/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java b/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
deleted file mode 100644
index c163e8d..0000000
--- a/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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 tdb.tools ;
-
-import java.io.OutputStream ;
-import java.nio.ByteBuffer ;
-import java.util.Iterator ;
-import java.util.function.Function ;
-
-import arq.cmdline.CmdARQ;
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Node_Literal ;
-import org.apache.jena.sparql.util.FmtUtils ;
-import org.apache.jena.tdb.base.file.FileFactory ;
-import org.apache.jena.tdb.base.file.FileSet ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.objectfile.ObjectFile ;
-import org.apache.jena.tdb.lib.NodeLib ;
-import org.apache.jena.tdb.setup.StoreParams ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.sys.Names ;
-import tdb.cmdline.ModLocation ;
-
-public class dumpnodetable extends CmdARQ {
-    ModLocation modLocation = new ModLocation() ;
-
-    static public void main(String... argv) {
-        LogCtl.setLog4j() ;
-        new dumpnodetable(argv).mainRun() ;
-    }
-
-    @Override
-    protected void exec() {
-        Location loc = modLocation.getLocation() ;
-
-        ObjectFile objFile = determineNodeTable(loc);
-        dump(System.out, objFile) ;
-    }
-    
-    private ObjectFile determineNodeTable(Location loc) {
-        // Directly open the nodes.dat file.
-        StoreParams storeParams = StoreParams.getDftStoreParams();
-        FileSet fsId2Node = new FileSet(loc, storeParams.getIndexId2Node()) ;
-        
-        String file = fsId2Node.filename(Names.extNodeData);
-        ObjectFile objFile = FileFactory.createObjectFileDisk(file);
-        return objFile;
-    }
-
-    protected dumpnodetable(String[] argv) {
-        super(argv) ;
-        super.addModule(modLocation) ;
-    }
-
-    // Taken from NodeTableNative.
-    private static Iterator<Pair<NodeId, Node>> all(ObjectFile objFile)
-    {
-        Iterator<Pair<Long, ByteBuffer>> objs = objFile.all() ; 
-        Function<Pair<Long, ByteBuffer>, Pair<NodeId, Node>> transform = item -> {
-            NodeId id = NodeId.create(item.car().longValue());
-            ByteBuffer bb = item.cdr();
-            Node n = NodeLib.decode(bb);
-            return new Pair<>(id, n);
-        };
-        return Iter.map(objs, transform) ;
-    }
-    
-    public static void dump(OutputStream w, ObjectFile objFile) {
-        // Better to hack the indexes?
-        Iterator<Pair<NodeId, Node>> iter = all(objFile) ;
-        long count = 0 ;
-        try (IndentedWriter iw = new IndentedWriter(w)) {
-            for ( ; iter.hasNext() ; ) {
-                Pair<NodeId, Node> pair = iter.next() ;
-                iw.print(pair.car().toString()) ;
-                iw.print(" : ") ;
-                // iw.print(pair.cdr()) ;
-                Node n = pair.cdr() ;
-                String $ = stringForNode(n) ;
-                iw.print($) ;
-                iw.println() ;
-                count++ ;
-            }
-            iw.println() ;
-            iw.printf("Total: " + count) ;
-            iw.println() ;
-            iw.flush() ;
-        }
-    }
-
-    private static String stringForNode(Node n) {
-        if ( n == null )
-            return "<<null>>" ;
-
-        if ( n.isBlank() )
-            return "_:" + n.getBlankNodeLabel() ;
-
-        if ( n.isLiteral() )
-            return stringForLiteral((Node_Literal)n) ;
-
-        if ( n.isURI() ) {
-            String uri = n.getURI() ;
-            return stringForURI(uri) ;
-        }
-
-        if ( n.isVariable() )
-            return "?" + n.getName() ;
-
-        if ( n.equals(Node.ANY) )
-            return "ANY" ;
-
-        Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ;
-        return n.toString() ;
-    }
-
-    public static String stringForURI(String uri) {
-        return "<" + uri + ">" ;
-    }
-
-    public static String stringForLiteral(Node_Literal literal) {
-        String datatype = literal.getLiteralDatatypeURI() ;
-        String lang = literal.getLiteralLanguage() ;
-        String s = literal.getLiteralLexicalForm() ;
-
-        StringBuilder sbuff = new StringBuilder() ;
-        sbuff.append("\"") ;
-        FmtUtils.stringEsc(sbuff, s, true) ;
-        sbuff.append("\"") ;
-
-        // Format the language tag
-        if ( lang != null && lang.length() > 0 ) {
-            sbuff.append("@") ;
-            sbuff.append(lang) ;
-        }
-
-        if ( datatype != null ) {
-            sbuff.append("^^") ;
-            sbuff.append(stringForURI(datatype)) ;
-        }
-
-        return sbuff.toString() ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        if ( modVersion.getVersionFlag() )
-            modVersion.printVersionAndExit() ;
-        if ( modLocation.getLocation() == null )
-            cmdError("Location required") ;
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName() + " --loc=DIR IndexName" ;
-    }
-
-    @Override
-    protected String getCommandName() {
-        return Lib.className(this) ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/91a65ad2/jena-cmds/src/main/java/tdb/tools/dumpnodetable1.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/dumpnodetable1.java b/jena-cmds/src/main/java/tdb/tools/dumpnodetable1.java
deleted file mode 100644
index 05f6da2..0000000
--- a/jena-cmds/src/main/java/tdb/tools/dumpnodetable1.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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 tdb.tools ;
-
-import java.io.OutputStream ;
-import java.util.Iterator ;
-
-import arq.cmdline.CmdARQ;
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Node_Literal ;
-import org.apache.jena.sparql.util.FmtUtils ;
-import org.apache.jena.tdb.StoreConnection ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.Build ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-import tdb.cmdline.ModLocation ;
-
-public class dumpnodetable1 extends CmdARQ {
-    ModLocation modLocation = new ModLocation() ;
-
-    static public void main(String... argv) {
-        LogCtl.setLog4j() ;
-        new dumpnodetable1(argv).mainRun() ;
-    }
-
-    @Override
-    protected void exec() {
-        Location loc = modLocation.getLocation() ;
-        NodeTable nodeTable = determineNodeTable(loc);
-        dump(System.out, nodeTable) ;
-    }
-    
-
-
-    private NodeTable determineNodeTable(Location loc) {
-        // Causes recovery.
-        StoreConnection sConn = StoreConnection.make(loc) ;
-        DatasetGraphTDB dsg = sConn.getBaseDataset() ;
-        NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
-        return nodeTable;
-    }
-
-    protected dumpnodetable1(String[] argv) {
-        super(argv) ;
-        super.addModule(modLocation) ;
-    }
-
-    public static void dumpNodes(OutputStream w, String location) {
-        dump(w, location, Names.indexNode2Id, SystemTDB.Node2NodeIdCacheSize, Names.indexId2Node, SystemTDB.NodeId2NodeCacheSize,
-             SystemTDB.NodeMissCacheSize) ;
-    }
-
-    public static void dumpPrefixes(OutputStream w, String location) {
-        dump(w, location, Names.prefixNode2Id, 100, Names.prefixId2Node, 100, 10) ;
-    }
-
-    public static void dump(OutputStream w, String location, String indexNode2Id, int node2NodeIdCacheSize, String indexId2Node,
-                            int nodeId2NodeCacheSize, //
-
-                            int sizeNodeMissCacheSize) {
-        NodeTable nodeTable = Build.makeNodeTable(Location.create(location), indexNode2Id, node2NodeIdCacheSize, indexId2Node,
-                                                  nodeId2NodeCacheSize, sizeNodeMissCacheSize) ;
-    }
-
-    public static void dump(OutputStream w, NodeTable nodeTable) {
-        // Better to hack the indexes?
-        Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ;
-        long count = 0 ;
-        try (IndentedWriter iw = new IndentedWriter(w)) {
-            for ( ; iter.hasNext() ; ) {
-                Pair<NodeId, Node> pair = iter.next() ;
-                iw.print(pair.car().toString()) ;
-                iw.print(" : ") ;
-                // iw.print(pair.cdr()) ;
-                Node n = pair.cdr() ;
-                String $ = stringForNode(n) ;
-                iw.print($) ;
-                iw.println() ;
-                count++ ;
-            }
-            iw.println() ;
-            iw.printf("Total: " + count) ;
-            iw.println() ;
-            iw.flush() ;
-        }
-    }
-
-    private static String stringForNode(Node n) {
-        if ( n == null )
-            return "<<null>>" ;
-
-        if ( n.isBlank() )
-            return "_:" + n.getBlankNodeLabel() ;
-
-        if ( n.isLiteral() )
-            return stringForLiteral((Node_Literal)n) ;
-
-        if ( n.isURI() ) {
-            String uri = n.getURI() ;
-            return stringForURI(uri) ;
-        }
-
-        if ( n.isVariable() )
-            return "?" + n.getName() ;
-
-        if ( n.equals(Node.ANY) )
-            return "ANY" ;
-
-        Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ;
-        return n.toString() ;
-    }
-
-    public static String stringForURI(String uri) {
-        return "<" + uri + ">" ;
-    }
-
-    public static String stringForLiteral(Node_Literal literal) {
-        String datatype = literal.getLiteralDatatypeURI() ;
-        String lang = literal.getLiteralLanguage() ;
-        String s = literal.getLiteralLexicalForm() ;
-
-        StringBuilder sbuff = new StringBuilder() ;
-        sbuff.append("\"") ;
-        FmtUtils.stringEsc(sbuff, s, true) ;
-        sbuff.append("\"") ;
-
-        // Format the language tag
-        if ( lang != null && lang.length() > 0 ) {
-            sbuff.append("@") ;
-            sbuff.append(lang) ;
-        }
-
-        if ( datatype != null ) {
-            sbuff.append("^^") ;
-            sbuff.append(stringForURI(datatype)) ;
-        }
-
-        return sbuff.toString() ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        if ( modVersion.getVersionFlag() )
-            modVersion.printVersionAndExit() ;
-        if ( modLocation.getLocation() == null )
-            cmdError("Location required") ;
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName() + " --loc=DIR IndexName" ;
-    }
-
-    @Override
-    protected String getCommandName() {
-        return Lib.className(this) ;
-    }
-
-}