You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by na...@apache.org on 2008/11/09 23:00:06 UTC

svn commit: r712571 - in /xml/xindice/trunk/java/src/org/apache/xindice/core: filer/BTree.java filer/BTreeFiler.java filer/BTreeNotFoundException.java indexer/ValueIndexer.java

Author: natalia
Date: Sun Nov  9 14:00:06 2008
New Revision: 712571

URL: http://svn.apache.org/viewvc?rev=712571&view=rev
Log:
Replace throwing BTreeNotFoundException with returning a special value

Removed:
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeNotFoundException.java
Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java?rev=712571&r1=712570&r2=712571&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java Sun Nov  9 14:00:06 2008
@@ -77,6 +77,8 @@
     protected static final byte BRANCH = 2;
     protected static final byte STREAM = 3;
 
+    protected static final long VALUE_DOES_NOT_EXIST = -1;
+
     /**
      * Identity map of the recently used tree nodes to ensure that same
      * node is present in the memory once and only once.
@@ -311,7 +313,7 @@
      */
     protected final BTreeRootInfo findBTreeRoot(Value v) throws IOException, BTreeException {
         long position = findValue(v);
-        return new BTreeRootInfo(v, position);
+        return position == VALUE_DOES_NOT_EXIST ? null : new BTreeRootInfo(v, position);
     }
 
     /**
@@ -595,7 +597,7 @@
 
                 case LEAF:
                     if (idx < 0) {
-                        throw new BTreeNotFoundException("Value '" + value + "' doesn't exist");
+                        return VALUE_DOES_NOT_EXIST;
                     } else {
                         long oldPtr = ptrs[idx];
 
@@ -814,7 +816,7 @@
 
         public synchronized long findValue(Value value) throws IOException, BTreeException {
             if (value == null) {
-                throw new BTreeNotFoundException("Can't search on null Value");
+                throw new BTreeException(FaultCodes.DBE_CANNOT_READ, "Can't search on null Value");
             }
 
             int idx = Arrays.binarySearch(values, value);
@@ -826,7 +828,7 @@
 
                 case LEAF:
                     if (idx < 0) {
-                        throw new BTreeNotFoundException("Value '" + value + "' doesn't exist");
+                        return VALUE_DOES_NOT_EXIST;
                     } else {
                         return ptrs[idx];
                     }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java?rev=712571&r1=712570&r2=712571&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java Sun Nov  9 14:00:06 2008
@@ -101,6 +101,10 @@
         checkOpened();
         try {
             long pos = findValue(key);
+            if (pos == VALUE_DOES_NOT_EXIST) {
+                return null;
+            }
+
             Page startPage = getPage(pos);
             Value v = metaOnly ? null : readValue(startPage);
             BTreeFilerPageHeader sph = (BTreeFilerPageHeader) startPage.getPageHeader();
@@ -110,15 +114,10 @@
             meta.put(Record.MODIFIED, new Long(sph.getModified()));
 
             return new Record(key, v, meta);
-        } catch (BTreeNotFoundException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Record '" + key + "' not found: " + e);
-            }
         } catch (IOException e) {
             throw new FilerException(FaultCodes.DBE_CANNOT_READ,
                                      "Can't read record '" + key + "': " + e.getMessage(), e);
         }
-        return null;
     }
 
     public Record writeRecord(Key key, Value value) throws DBException {
@@ -165,6 +164,10 @@
         checkOpened();
         try {
             long pos = removeValue(key);
+            if (pos == VALUE_DOES_NOT_EXIST) {
+                return false;
+            }
+
             Page p = getPage(pos);
             unlinkPages(p);
 
@@ -172,16 +175,10 @@
 
             flush();
             return true;
-        } catch (BTreeNotFoundException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Record '" + key + "' not found (" + e + ")");
-            }
         } catch (IOException e) {
             throw new FilerException(FaultCodes.DBE_CANNOT_DROP,
                                      "Can't delete record '" + key + "': " + e.getMessage(), e);
         }
-
-        return false;
     }
 
     public long getRecordCount() throws DBException {

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java?rev=712571&r1=712570&r2=712571&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java Sun Nov  9 14:00:06 2008
@@ -28,7 +28,6 @@
 import org.apache.xindice.core.filer.BTree;
 import org.apache.xindice.core.filer.BTreeCallback;
 import org.apache.xindice.core.filer.BTreeCorruptException;
-import org.apache.xindice.core.filer.BTreeNotFoundException;
 import org.apache.xindice.core.filer.Paged;
 import org.apache.xindice.core.query.QueryEngine;
 import org.apache.xindice.util.Configuration;
@@ -172,11 +171,8 @@
                 }
 
                 try {
-                    BTreeRootInfo root;
-
-                    try {
-                        root = findBTreeRoot(v);
-                    } catch (BTreeNotFoundException e) {
+                    BTreeRootInfo root = findBTreeRoot(v);
+                    if (root == null) {
                         root = createBTreeRoot(v);
                     }