[Mulgara-svn] r908 - in trunk/src/jar: resolver-spi/java/org/mulgara/store/statement resolver-store/java/org/mulgara/store/statement/xa

pag at mulgara.org pag at mulgara.org
Thu May 8 00:06:51 UTC 2008


Author: pag
Date: 2008-05-07 17:06:50 -0700 (Wed, 07 May 2008)
New Revision: 908

Modified:
   trunk/src/jar/resolver-spi/java/org/mulgara/store/statement/StatementStore.java
   trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/XAStatementStoreImpl.java
Log:
Punched a new query hole into the API. This permits choosing which ordering you want when there are sufficient variables to have multiple indexes that will suit a query. This can avoid the need to re-order Tuples in some circumstances. The current implementation is asymmetric, as the use case for it was restricted, but it can be expanded to being completely symmetric if it proves to be useful.

Modified: trunk/src/jar/resolver-spi/java/org/mulgara/store/statement/StatementStore.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/store/statement/StatementStore.java	2008-05-07 14:30:50 UTC (rev 907)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/store/statement/StatementStore.java	2008-05-08 00:06:50 UTC (rev 908)
@@ -114,6 +114,23 @@
   ) throws StatementStoreException;
 
   /**
+   * Locate all triples matching the given specification using the given ordering mask.
+   *
+   * @param mask the mask indicating the index to use. This MUST be compatible with the
+   *             following nodes.
+   * @param node0 the value for the first element of the triples
+   * @param node1 the value for the second element of the triples
+   * @param node2 the value for the third element of the triples
+   * @param node3 the value for the fourth element of the triples
+   * @return the {@link StoreTuples}
+   * @throws StatementStoreException if something exceptional happens
+   */
+  public StoreTuples findTuples(
+      int mask,
+      long node0, long node1, long node2, long node3
+  ) throws StatementStoreException;
+
+  /**
    * Returns a StoreTuples which contains all triples in the store.  The
    * parameters provide a hint about how the StoreTuples will be used.  This
    * information is used to select the index from which the StoreTuples will be

Modified: trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/XAStatementStoreImpl.java
===================================================================
--- trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/XAStatementStoreImpl.java	2008-05-07 14:30:50 UTC (rev 907)
+++ trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/XAStatementStoreImpl.java	2008-05-08 00:06:50 UTC (rev 908)
@@ -540,8 +540,46 @@
     return currentPhase.findTuples(objectPool, node0, node1, node2, node3);
   }
 
+  
+  /**
+   * Finds triples matching the given specification and index mask.
+   *
+   * @param mask The mask of the index to use. This is only allowable for 3 variables
+   *             and a given graph.
+   * @param node0 The 0 node of the triple to find.
+   * @param node1 The 1 node of the triple to find.
+   * @param node2 The 2 node of the triple to find.
+   * @param node3 The 3 node of the triple to find.
+   * @return A set of all the triples which match the search.
+   * @throws StatementStoreException EXCEPTION TO DO
+   */
+  public synchronized StoreTuples findTuples(
+      int mask, long node0, long node1, long node2, long node3
+  ) throws StatementStoreException {
+    checkInitialized();
+    dirty = false;
+    if (!checkMask(mask, node0, node1, node2, node3)) throw new StatementStoreException("Bad explicit index selection for given node pattern.");
+    return currentPhase.findTuples(objectPool, mask, node0, node1, node2, node3);
+  }
 
   /**
+   * Tests a mask for consistency against the nodes it will be used to find.
+   * @param mask The mask to test.
+   * @param node0 The 0 node of the triple to find.
+   * @param node1 The 1 node of the triple to find.
+   * @param node2 The 2 node of the triple to find.
+   * @param node3 The 3 node of the triple to find.
+   * @return <code>true</code> if the mask is consistent with the given nodes.
+   */
+  private static boolean checkMask(int mask, long node0, long node1, long node2, long node3) {
+    if (node0 != NONE && 0 == (mask & MASK0)) return false;
+    if (node1 != NONE && 0 == (mask & MASK1)) return false;
+    if (node2 != NONE && 0 == (mask & MASK2)) return false;
+    if (node3 != NONE && 0 == (mask & MASK3)) return false;
+    return true;
+  }
+
+  /**
    * Returns a StoreTuples which contains all triples in the store.  The
    * parameters provide a hint about how the StoreTuples will be used.  This
    * information is used to select the index from which the StoreTuples will be
@@ -1305,7 +1343,26 @@
       return phase.findTuples(objectPool, node0, node1, node2, node3);
     }
 
+    /**
+     * Finds triples matching the given specification.
+     *
+     * @param mask The mask of the index to use. This is only allowable for 3 variables
+     *             and a given graph.
+     * @param node0 The 0 node of the triple to find.
+     * @param node1 The 1 node of the triple to find.
+     * @param node2 The 2 node of the triple to find.
+     * @param node3 The 3 node of the triple to find.
+     * @return A StoreTuples which contains the triples which match the search.
+     * @throws StatementStoreException EXCEPTION TO DO
+     */
+    public synchronized StoreTuples findTuples(
+        int mask, long node0, long node1, long node2, long node3
+    ) throws StatementStoreException {
+      if (!checkMask(mask, node0, node1, node2, node3)) throw new StatementStoreException("Bad explicit index selection for given node pattern.");
+      return phase.findTuples(objectPool, mask, node0, node1, node2, node3);
+    }
 
+
     /**
      * Returns a StoreTuples which contains all triples in the store.  The
      * parameters provide a hint about how the StoreTuples will be used.  This
@@ -1717,7 +1774,59 @@
       }
     }
 
+    /**
+     * Finds triples matching the given specification.
+     *
+     * @param objectPool PARAMETER TO DO
+     * @param variableMask the mask used to indicate the desired index.
+     * @param node0 The 0 node of the triple to find.
+     * @param node1 The 1 node of the triple to find.
+     * @param node2 The 2 node of the triple to find.
+     * @param node3 The 3 node of the triple to find.
+     * @return A StoreTuples containing all the triples which match the search.
+     * @throws StatementStoreException EXCEPTION TO DO
+     */
+    StoreTuples findTuples(
+        ObjectPool objectPool, int variableMask,
+        long node0, long node1, long node2, long node3
+    ) throws StatementStoreException {
+      if (
+          node0 < NodePool.NONE ||
+          node1 < NodePool.NONE ||
+          node2 < NodePool.NONE ||
+          node3 < NodePool.NONE
+      ) {
+        // There is at least one query node.  Return an empty StoreTuples.
+        return TuplesOperations.empty();
+      }
 
+      if (0 == (variableMask & MASK3)) throw new StatementStoreException("This version of find is for re-ordering graphs, base on a given mask.");
+      try {
+        switch (variableMask) {
+          case MASK3:
+            return tripleAVLFilePhases[TI_3012].findTuples(objectPool, node3);
+          case MASK0 | MASK3:
+            return tripleAVLFilePhases[TI_3012].findTuples(objectPool, node3);
+          case MASK1 | MASK3:
+            return tripleAVLFilePhases[TI_3120].findTuples(objectPool, node3);
+          case MASK0 | MASK1 | MASK3:
+            return tripleAVLFilePhases[TI_3012].findTuples(objectPool, node3);
+          case MASK2 | MASK3:
+            return tripleAVLFilePhases[TI_3201].findTuples(objectPool, node3);
+          case MASK0 | MASK2 | MASK3:
+            return tripleAVLFilePhases[TI_3201].findTuples(objectPool, node3);
+          case MASK1 | MASK2 | MASK3:
+            return tripleAVLFilePhases[TI_3120].findTuples(objectPool, node3);
+          case MASK0 | MASK1 | MASK2 | MASK3:
+            return tripleAVLFilePhases[TI_3012].findTuples(objectPool, node3);
+          default:
+            throw new AssertionError();
+        }
+      } catch (IOException ex) {
+        throw new StatementStoreException("I/O error", ex);
+      }
+    }
+
     /**
      * Finds triples matching the given specification.
      *
@@ -1744,10 +1853,10 @@
       }
 
       int variableMask =
-          (node0 != NONE ? MASK0 : 0) |
-          (node1 != NONE ? MASK1 : 0) |
-          (node2 != NONE ? MASK2 : 0) |
-          (node3 != NONE ? MASK3 : 0);
+        (node0 != NONE ? MASK0 : 0) |
+        (node1 != NONE ? MASK1 : 0) |
+        (node2 != NONE ? MASK2 : 0) |
+        (node3 != NONE ? MASK3 : 0);
 
       try {
         switch (variableMask) {




More information about the Mulgara-svn mailing list