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 2012/07/14 15:55:02 UTC
svn commit: r1361548 -
/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java
Author: andy
Date: Sat Jul 14 13:55:02 2012
New Revision: 1361548
URL: http://svn.apache.org/viewvc?rev=1361548&view=rev
Log:
Some debug code.
Added:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java
Added: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java?rev=1361548&view=auto
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java (added)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/DebugTDB.java Sat Jul 14 13:55:02 2012
@@ -0,0 +1,132 @@
+/**
+ * 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 com.hp.hpl.jena.tdb.sys;
+
+import java.util.Iterator ;
+
+import org.openjena.atlas.lib.Tuple ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.tdb.base.file.Location ;
+import com.hp.hpl.jena.tdb.base.record.Record ;
+import com.hp.hpl.jena.tdb.index.Index ;
+import com.hp.hpl.jena.tdb.index.RangeIndex ;
+import com.hp.hpl.jena.tdb.index.TupleIndex ;
+import com.hp.hpl.jena.tdb.index.TupleIndexRecord ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTableLib ;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+import com.hp.hpl.jena.tdb.store.NodeId ;
+
+/** Lowlevel utilities for working with TDB */
+
+public class DebugTDB
+{
+ public static NodeId lookup(DatasetGraphTDB dsg, Node n)
+ {
+ NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
+ NodeId nid = nt.getNodeIdForNode(n) ;
+ return nid ;
+ }
+
+ public static void dumpInternals(DatasetGraphTDB dsg, boolean includeNamedGraphs)
+ {
+ dumpNodeTable("Nodes", dsg) ;
+ TupleIndex[] indexes1 = dsg.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes() ;
+ TupleIndex[] indexes2 = dsg.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes() ;
+ for ( TupleIndex idx : indexes1 )
+ {
+ System.out.println(idx.getName()) ;
+ dumpIndex(idx) ;
+ }
+
+ if ( ! includeNamedGraphs ) return ;
+
+ for ( TupleIndex idx : indexes2 )
+ {
+ System.out.println(idx.getName()) ;
+ dumpIndex(idx) ;
+ }
+ }
+
+ public static void dumpNodeTable(String label, DatasetGraphTDB dsg)
+ {
+ NodeTable nt1 = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
+ NodeTableLib.print(label, nt1) ;
+ }
+
+// public static RangeIndex makeRangeIndex(Location location, String indexName,
+// int dftKeyLength, int dftValueLength,
+// int readCacheSize,int writeCacheSize)
+
+ public static void dumpNodeIndex(String dir)
+ {
+ Location location = new Location(dir) ;
+ Index nodeToId = SetupTDB.makeIndex(location, Names.indexNode2Id, SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId, -1 ,-1) ;
+ Iterator<Record> iter = nodeToId.iterator() ;
+ while(iter.hasNext())
+ {
+ System.out.println(iter.next()) ;
+ }
+ }
+
+
+ public static TupleIndex getIndex(String idxName, DatasetGraphTDB dsg)
+ {
+ System.out.println(idxName) ;
+ TupleIndex[] indexes1 = dsg.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes() ;
+ TupleIndex[] indexes2 = dsg.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes() ;
+ TupleIndex idx = null ;
+
+ for ( TupleIndex i : indexes1 )
+ {
+ if ( i.getName().equals(idxName) )
+ return i ;
+ }
+
+ for ( TupleIndex i : indexes2 )
+ {
+ if ( i.getName().equals(idxName) )
+ return i ;
+ }
+ return null ;
+ }
+
+ public static void dumpIndex(TupleIndex idx)
+ {
+ Iterator<Tuple<NodeId>> iter = idx.all() ;
+ while(iter.hasNext())
+ {
+ Tuple<NodeId> tuple = iter.next() ;
+ System.out.println(tuple) ;
+ }
+
+ if ( false )
+ {
+ // Dump raw
+ TupleIndexRecord tir = (TupleIndexRecord)idx ;
+ RangeIndex rIdx = tir.getRangeIndex() ;
+ Iterator<Record> rIter = rIdx.iterator() ;
+ while(rIter.hasNext())
+ System.out.println(rIter.next()) ;
+ }
+ }
+
+}
+