[Mulgara-svn] r1289 - trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11

pag at mulgara.org pag at mulgara.org
Tue Sep 30 06:07:02 UTC 2008


Author: pag
Date: 2008-09-29 23:07:01 -0700 (Mon, 29 Sep 2008)
New Revision: 1289

Added:
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeMapper.java
Modified:
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeAllocator.java
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataAVLComparator.java
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
Log:
Added a blank node mapper to enable backup/restore to work on this stringpool

Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeAllocator.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeAllocator.java	2008-09-30 06:06:14 UTC (rev 1288)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeAllocator.java	2008-09-30 06:07:01 UTC (rev 1289)
@@ -27,6 +27,9 @@
   /** The bit that indicates a blank node. */
   static final long BLANK_NODE_BIT = 0x4000000000000000L;
 
+  /** The mask that can remove the BLANK_NODE_BIT. */
+  static final private long COUNTER_MASK = 0x3FFFFFFFFFFFFFFFL;
+
   /** The first valid blank node value. */
   static final long FIRST = 1;
   
@@ -133,4 +136,23 @@
     nextNode = committedNextNode;
   }
 
+
+  /**
+   * Convert a blank node code to a counter value.
+   * @param blankGNode The blank node value.
+   * @return A value with the blank node bit turned off.
+   */
+  public static final long nodeToCounter(long blankGNode) {
+    return blankGNode & COUNTER_MASK;
+  }
+
+
+  /**
+   * Convert a blank node code to a counter value.
+   * @param blankGNode The blank node value.
+   * @return A value with the blank node bit turned off.
+   */
+  public static final long counterToNode(long counter) {
+    return counter | BLANK_NODE_BIT;
+  }
 }

Added: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeMapper.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeMapper.java	                        (rev 0)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/BlankNodeMapper.java	2008-09-30 06:07:01 UTC (rev 1289)
@@ -0,0 +1,74 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.store.stringpool.xa11;
+
+import java.io.IOException;
+
+import org.mulgara.util.IntFile;
+import org.mulgara.util.LongMapper;
+
+/**
+ * Manages node-to-node mapping, including our blank nodes that need to be mapped to other nodes.
+ *
+ * @created Sep 26, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class BlankNodeMapper implements LongMapper {
+
+  /** Maps normal node values to other node values. */
+  private IntFile nodeMap;
+
+  /** Maps blank node values to other node values. */
+  private IntFile blankNodeMap;
+
+  public BlankNodeMapper(String baseName) throws IOException {
+    nodeMap = IntFile.newTempIntFile(baseName);
+    blankNodeMap = IntFile.newTempIntFile(baseName + "_b");
+  }
+
+  /**
+   * @see org.mulgara.util.LongMapper#delete()
+   */
+  public void delete() throws IOException {
+    try {
+      nodeMap.delete();
+    } finally {
+      blankNodeMap.delete();
+    }
+  }
+
+  /**
+   * @see org.mulgara.util.LongMapper#getLong(long)
+   */
+  public long getLong(long key) throws Exception {
+    if (BlankNodeAllocator.isBlank(key)) {
+      return blankNodeMap.getLong(BlankNodeAllocator.nodeToCounter(key));
+    } else {
+      return nodeMap.getLong(key);
+    }
+  }
+
+  /**
+   * @see org.mulgara.util.LongMapper#putLong(long, long)
+   */
+  public void putLong(long key, long value) throws Exception {
+    if (BlankNodeAllocator.isBlank(key)) {
+      blankNodeMap.putLong(BlankNodeAllocator.nodeToCounter(key), value);
+    } else {
+      nodeMap.putLong(key, value);
+    }
+  }
+
+}

Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataAVLComparator.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataAVLComparator.java	2008-09-30 06:06:14 UTC (rev 1288)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataAVLComparator.java	2008-09-30 06:07:01 UTC (rev 1289)
@@ -87,10 +87,9 @@
       data.rewind();
       nodeData.rewind();
       c = spComparator.comparePrefix(data, nodeData, dataSize);
+      data.limit(savedDataLimit);
       if (c != 0) return c;
 
-      data.limit(savedDataLimit);
-
       try {
         // Retrieve the remaining bytes if any.
         // Set the limit before the position in case the limit was made

Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java	2008-09-30 06:06:14 UTC (rev 1288)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java	2008-09-30 06:07:01 UTC (rev 1289)
@@ -56,6 +56,7 @@
 import org.mulgara.store.xa.XAStringPool;
 import org.mulgara.store.xa.XAUtils;
 import org.mulgara.util.Constants;
+import org.mulgara.util.LongMapper;
 import org.mulgara.util.functional.Pair;
 
 import static org.mulgara.store.stringpool.xa11.DataStruct.*;
@@ -261,11 +262,13 @@
   }
 
   /**
-   * @deprecated
+   * @deprecated The <var>nodePool</var> parameter must equal this. Use {@link #findGNode(SPObject, boolean)} with a true <var>create</var> parameter instead.
    * @see org.mulgara.store.stringpool.StringPool#findGNode(org.mulgara.store.stringpool.SPObject, org.mulgara.store.nodepool.NodePool)
    */
   public long findGNode(SPObject spObject, NodePool nodePool) throws StringPoolException {
-    throw new UnsupportedOperationException("Cannot manually set the node pool for an XA 1.1 store.");
+    if (nodePool != this) throw new IllegalStateException("The XA11 data store must manage its own nodes");
+    checkInitialized();
+    return currentPhase.findGNode(spObject, true);
   }
 
   /**
@@ -682,6 +685,12 @@
   }
 
 
+  /** @see org.mulgara.store.xa.XANodePool#getNodeMapper() */
+  public LongMapper getNodeMapper() throws Exception {
+    return new BlankNodeMapper("n2n");
+  }
+
+
   /**
    * Inform all listeners that a new node was just allocated.
    * @param newNode The newly allocated node.




More information about the Mulgara-svn mailing list