[Mulgara-svn] r1432 - branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11
pag at mulgara.org
pag at mulgara.org
Mon Jan 12 21:12:38 UTC 2009
Author: pag
Date: 2009-01-12 13:12:37 -0800 (Mon, 12 Jan 2009)
New Revision: 1432
Modified:
branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java
Log:
Added new joinGraphedTuples to deal with ordered selections of the entire index. Ordering entails finding the correct index.
Modified: branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java 2009-01-12 21:10:26 UTC (rev 1431)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java 2009-01-12 21:12:37 UTC (rev 1432)
@@ -465,7 +465,7 @@
public synchronized StoreTuples findTuples(boolean node0Bound, boolean node1Bound, boolean node2Bound, boolean node3Bound) throws StatementStoreException {
checkInitialized();
dirty = false;
- return currentPhase.findTuples(node0Bound, node1Bound, node2Bound);
+ return currentPhase.findTuples(node0Bound, node1Bound, node2Bound, node3Bound);
}
@@ -1070,8 +1070,7 @@
* @throws StatementStoreException if something exceptional happens
*/
public synchronized StoreTuples findTuples(boolean node0Bound, boolean node1Bound, boolean node2Bound, boolean node3Bound) throws StatementStoreException {
- if (!node3Bound) throw new IllegalArgumentException("The graph must be bound");
- return phase.findTuples(node0Bound, node1Bound, node2Bound);
+ return phase.findTuples(node0Bound, node1Bound, node2Bound, node3Bound);
}
@@ -1485,17 +1484,29 @@
}
- StoreTuples findTuples(boolean node0Bound, boolean node1Bound, boolean node2Bound) throws StatementStoreException {
+ StoreTuples findTuples(boolean node0Bound, boolean node1Bound, boolean node2Bound, boolean node3Bound) throws StatementStoreException {
// The variable mask does not need MASK3, as this has been taken into account in selectIndex[]
int variableMask =
(node0Bound ? MASK0 : 0) |
(node1Bound ? MASK1 : 0) |
(node2Bound ? MASK2 : 0);
-
- return tripleAVLFilePhases[selectIndex[variableMask]].allTuples();
+ if (node3Bound) {
+ return tripleAVLFilePhases[selectIndex[variableMask]].allTuples();
+ } else {
+ return joinGraphedTuples(variableMask);
+ }
}
+ /**
+ * Iterates over all graphs, finding requested tuples, and joining all the results together into a single tuples.
+ * @param variableMask Pre-calculated from the bound node parameters.
+ * @param node0 The bound value for node0, or < 0 if not bound.
+ * @param node1 The bound value for node1, or < 0 if not bound.
+ * @param node2 The bound value for node2, or < 0 if not bound.
+ * @return A StoreTuples with all the intermediate tuples appended.
+ * @throws StatementStoreException On an error accessing the store.
+ */
StoreTuples joinGraphedTuples(int variableMask, long node0, long node1, long node2) throws StatementStoreException {
try {
assert (variableMask & MASK3) == 0 : "Must not be asking to join on multiple graphs unless graph is variable.";
@@ -1549,7 +1560,55 @@
}
}
+
/**
+ * Iterates over all graphs, getting all tuples in the requested order,
+ * and joining all the results together into a single tuples.
+ * @param variableMask Determines the required ordering of the data.
+ * @return A StoreTuples with all the intermediate tuples appended.
+ * @throws StatementStoreException On an error accessing the store.
+ */
+ StoreTuples joinGraphedTuples(int variableMask) throws StatementStoreException {
+ try {
+ assert (variableMask & MASK3) == 0 : "Must not be asking to join on multiple graphs unless graph is variable.";
+
+ // get the graphNodes if not already configured
+ if (graphNodes.isEmpty()) throw new IllegalStateException("Unable to query for variable graphs until graphs are initialized");
+
+ ArrayList<StoreTuples> graphedTuples = new ArrayList<StoreTuples>();
+ for (long graphNode: graphNodes) {
+ int phaseIndex;
+ switch (variableMask) {
+ case 0:
+ case MASK0:
+ case MASK0 | MASK1:
+ case MASK0 | MASK1 | MASK2:
+ phaseIndex = TI_3012;
+ break;
+ case MASK1:
+ case MASK1 | MASK2:
+ phaseIndex = TI_3120;
+ break;
+ case MASK2:
+ case MASK0 | MASK2:
+ phaseIndex = TI_3201;
+ break;
+ default:
+ throw new AssertionError("Search structure incorrectly calculated");
+ }
+ StoreTuples partialResult = tripleAVLFilePhases[phaseIndex].findTuplesForMeta(graphNode);
+ graphedTuples.add(partialResult);
+ }
+ return TuplesOperations.appendCompatible(graphedTuples);
+ } catch (TuplesException te) {
+ throw new StatementStoreException("Error accessing Tuples", te);
+ } catch (IOException ex) {
+ throw new StatementStoreException("I/O error", ex);
+ }
+ }
+
+
+ /**
* Test is there exist triples according to a given pattern
* @param node0 A subject gNode, or NONE
* @param node1 A predicate gNode, or NONE
More information about the Mulgara-svn
mailing list