Repository: jena Updated Branches: refs/heads/master 539f27c3a -> 2472f6ae8
Add convenience operations NodeTable.containsNode and .containsNodeId Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/88836ee2 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/88836ee2 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/88836ee2 Branch: refs/heads/master Commit: 88836ee2332936e9ee969974bc67d9f6c03d6ad0 Parents: 539f27c Author: Andy Seaborne <[email protected]> Authored: Tue Sep 23 14:36:37 2014 +0100 Committer: Andy Seaborne <[email protected]> Committed: Tue Sep 23 14:36:37 2014 +0100 ---------------------------------------------------------------------- .../hp/hpl/jena/tdb/store/nodetable/NodeTable.java | 8 +++++++- .../jena/tdb/store/nodetable/NodeTableCache.java | 12 ++++++++++++ .../jena/tdb/store/nodetable/NodeTableLogger.java | 17 +++++++++++++++++ .../jena/tdb/store/nodetable/NodeTableNative.java | 14 +++++++++++++- .../jena/tdb/store/nodetable/NodeTableWrapper.java | 9 +++++++++ .../hpl/jena/tdb/transaction/NodeTableTrans.java | 14 ++++++++++++++ 6 files changed, 72 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTable.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTable.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTable.java index 34cc3e7..23ea998 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTable.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTable.java @@ -43,13 +43,19 @@ public interface NodeTable extends Sync, Closeable /** Look up node id and return the Node - return null if not found */ public Node getNodeForNodeId(NodeId id) ; + /** Test whether the node table contains an entry for node */ + public boolean containsNode(Node node) ; + + /** Test whether the node table contains an entry for node */ + public boolean containsNodeId(NodeId nodeId) ; + /** Iterate over all nodes (not necessarily fast). Does not include inlined NodeIds */ public Iterator<Pair<NodeId, Node>> all() ; /** The offset needed to predicate allocation difference between peristent tables - internal function */ public NodeId allocOffset() ; - /** Any thing there? */ + /** Anything there? */ public boolean isEmpty() ; } http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableCache.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableCache.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableCache.java index c27e847..a16b889 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableCache.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableCache.java @@ -92,6 +92,18 @@ public class NodeTableCache implements NodeTable @Override public NodeId getAllocateNodeId(Node node) { return _idForNode(node, true) ; } + @Override + public boolean containsNode(Node node) { + NodeId x = getNodeIdForNode(node) ; + return NodeId.isDoesNotExist(x) ; + } + + @Override + public boolean containsNodeId(NodeId nodeId) { + Node x = getNodeForNodeId(nodeId) ; + return x == null ; + } + // ---- The worker functions // NodeId ==> Node private Node _retrieveNodeByNodeId(NodeId id) http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableLogger.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableLogger.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableLogger.java index 37214be..d3617e1 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableLogger.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableLogger.java @@ -70,6 +70,23 @@ public class NodeTableLogger implements NodeTable } @Override + public boolean containsNode(Node node) { + //info("containsNodeId("+id+") =>") ; + boolean b = nodeTable.containsNode(node) ; + info("containsNode("+node+") => "+b) ; + return b ; + } + + @Override + public boolean containsNodeId(NodeId id) { + //info("containsNodeId("+id+") =>") ; + boolean b = nodeTable.containsNodeId(id) ; + info("containsNodeId("+id+") => "+b) ; + return b ; + } + + + @Override public NodeId allocOffset() { NodeId nodeId = nodeTable.allocOffset() ; http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableNative.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableNative.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableNative.java index 57e85fa..17162c9 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableNative.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableNative.java @@ -79,9 +79,21 @@ public class NodeTableNative implements NodeTable @Override public NodeId getAllocateNodeId(Node node) { return _idForNode(node, true) ; } + @Override + public boolean containsNode(Node node) { + NodeId x = getNodeIdForNode(node) ; + return NodeId.isDoesNotExist(x) ; + } + + @Override + public boolean containsNodeId(NodeId nodeId) { + Node x = getNodeForNodeId(nodeId) ; + return x == null ; + } + // ---- The worker functions // Synchronization: - // accesIndex and readNodeFromTable + // accessIndex and readNodeFromTable // Cache around this class further out in NodeTableCache are synchronized // to maintain cache validatity which indirectly sync access to the NodeTable. http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableWrapper.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableWrapper.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableWrapper.java index 662de57..a2ef49a 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableWrapper.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/nodetable/NodeTableWrapper.java @@ -55,6 +55,15 @@ public class NodeTableWrapper implements NodeTable } @Override + public boolean containsNode(Node node) { + return nodeTable.containsNode(node) ; + } + + @Override + public boolean containsNodeId(NodeId nodeId) { + return nodeTable.containsNodeId(nodeId) ; } + + @Override public NodeId allocOffset() { return nodeTable.allocOffset() ; http://git-wip-us.apache.org/repos/asf/jena/blob/88836ee2/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java index e28cad2..e4542d7 100644 --- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java +++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java @@ -118,6 +118,20 @@ public class NodeTableTrans implements NodeTable, TransactionLifecycle return node ; } + @Override + public boolean containsNode(Node node) { + NodeId x = getNodeIdForNode(node) ; + return NodeId.isDoesNotExist(x) ; + } + + @Override + public boolean containsNodeId(NodeId nodeId) { + Node x = getNodeForNodeId(nodeId) ; + return x == null ; + } + + + /** Convert from a id to the id in the "journal" file */ private NodeId mapToJournal(NodeId id) {
