[Mulgara-svn] r1453 - branches/xa11/src/jar/resolver/java/org/mulgara/resolver

pag at mulgara.org pag at mulgara.org
Sat Jan 24 01:05:25 UTC 2009


Author: pag
Date: 2009-01-23 17:05:24 -0800 (Fri, 23 Jan 2009)
New Revision: 1453

Added:
   branches/xa11/src/jar/resolver/java/org/mulgara/resolver/TuplesBasedOperation.java
Modified:
   branches/xa11/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java
   branches/xa11/src/jar/resolver/java/org/mulgara/resolver/OutputOperation.java
   branches/xa11/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
Log:
Now handling when a selection of everything comes back in Graph-Subject-Predicate-Object order instead of Subject-Predicate-Object-Graph

Modified: branches/xa11/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java
===================================================================
--- branches/xa11/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java	2009-01-22 11:17:12 UTC (rev 1452)
+++ branches/xa11/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java	2009-01-24 01:05:24 UTC (rev 1453)
@@ -163,22 +163,19 @@
         StatementStore.VARIABLES[3]));
     assert tuples != null;
     try {
-      assert tuples.getVariables()[0] == StatementStore.VARIABLES[0];
-      assert tuples.getVariables()[1] == StatementStore.VARIABLES[1];
-      assert tuples.getVariables()[2] == StatementStore.VARIABLES[2];
-      assert tuples.getVariables()[3] == StatementStore.VARIABLES[3];
+      int[] colMap = mapColumnsToStd(tuples.getVariables());
       writer.write("TRIPLES\n");
 
       long preallocationModelNode = metadata.getPreallocationModelNode();
       for (tuples.beforeFirst(); tuples.next(); ) {
         // Suppress output of the preallocation model.
-        long modelNode = tuples.getColumnValue(3);
+        long modelNode = tuples.getColumnValue(colMap[3]);
         if (modelNode != preallocationModelNode) {
-          writer.write(Long.toString(tuples.getColumnValue(0)));
+          writer.write(Long.toString(tuples.getColumnValue(colMap[0])));
           writer.write(' ');
-          writer.write(Long.toString(tuples.getColumnValue(1)));
+          writer.write(Long.toString(tuples.getColumnValue(colMap[1])));
           writer.write(' ');
-          writer.write(Long.toString(tuples.getColumnValue(2)));
+          writer.write(Long.toString(tuples.getColumnValue(colMap[2])));
           writer.write(' ');
           writer.write(Long.toString(modelNode));
           writer.write('\n');

Modified: branches/xa11/src/jar/resolver/java/org/mulgara/resolver/OutputOperation.java
===================================================================
--- branches/xa11/src/jar/resolver/java/org/mulgara/resolver/OutputOperation.java	2009-01-22 11:17:12 UTC (rev 1452)
+++ branches/xa11/src/jar/resolver/java/org/mulgara/resolver/OutputOperation.java	2009-01-24 01:05:24 UTC (rev 1453)
@@ -27,7 +27,7 @@
  * @copyright &copy; 2008 <a href="http://www.revelytix.com">Revelytix, Inc.</a>
  * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
  */
-public abstract class OutputOperation implements Operation {
+public abstract class OutputOperation extends TuplesBasedOperation implements Operation {
   
   protected final OutputStream outputStream;
   protected final URI destinationURI;

Modified: branches/xa11/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
===================================================================
--- branches/xa11/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java	2009-01-22 11:17:12 UTC (rev 1452)
+++ branches/xa11/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java	2009-01-24 01:05:24 UTC (rev 1453)
@@ -80,8 +80,7 @@
  *   Technology, Inc</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-class RestoreOperation implements BackupConstants, Operation
-{
+class RestoreOperation extends TuplesBasedOperation implements BackupConstants, Operation {
 
   /** Logger.  */
   private static final Logger logger =
@@ -221,23 +220,20 @@
                                      StatementStore.VARIABLES[1],
                                      StatementStore.VARIABLES[2],
                                      StatementStore.VARIABLES[3]));
-    assert tuples.getVariables()[0] == StatementStore.VARIABLES[0];
-    assert tuples.getVariables()[1] == StatementStore.VARIABLES[1];
-    assert tuples.getVariables()[2] == StatementStore.VARIABLES[2];
-    assert tuples.getVariables()[3] == StatementStore.VARIABLES[3];
+    int[] colMap = mapColumnsToStd(tuples.getVariables());
 
     try {
       tuples.beforeFirst();
 
       long preallocationModelNode = metadata.getPreallocationModelNode();
       while (tuples.next()) {
-        long modelNode = tuples.getColumnValue(3);
+        long modelNode = tuples.getColumnValue(colMap[3]);
         if (modelNode != preallocationModelNode) {
           resolver.modifyModel(
               modelNode,
-              new SingletonStatements(tuples.getColumnValue(0),
-                                      tuples.getColumnValue(1),
-                                      tuples.getColumnValue(2)),
+              new SingletonStatements(tuples.getColumnValue(colMap[0]),
+                                      tuples.getColumnValue(colMap[1]),
+                                      tuples.getColumnValue(colMap[2])),
               DatabaseSession.DENY_STATEMENTS
           );
         }
@@ -541,23 +537,20 @@
                                      StatementStore.VARIABLES[1],
                                      StatementStore.VARIABLES[2],
                                      StatementStore.VARIABLES[3]));
-    assert tuples.getVariables()[0] == StatementStore.VARIABLES[0];
-    assert tuples.getVariables()[1] == StatementStore.VARIABLES[1];
-    assert tuples.getVariables()[2] == StatementStore.VARIABLES[2];
-    assert tuples.getVariables()[3] == StatementStore.VARIABLES[3];
+    int[] colMap = mapColumnsToStd(tuples.getVariables());
 
     try {
       tuples.beforeFirst();
 
       long preallocationModelNode = metadata.getPreallocationModelNode();
       while (tuples.next()) {
-        long modelNode = tuples.getColumnValue(3);
+        long modelNode = tuples.getColumnValue(colMap[3]);
         if (modelNode != preallocationModelNode) {
           resolver.modifyModel(
               modelNode,
-              new SingletonStatements(tuples.getColumnValue(0),
-                                      tuples.getColumnValue(1),
-                                      tuples.getColumnValue(2)),
+              new SingletonStatements(tuples.getColumnValue(colMap[0]),
+                                      tuples.getColumnValue(colMap[1]),
+                                      tuples.getColumnValue(colMap[2])),
               DatabaseSession.DENY_STATEMENTS
           );
         }

Added: branches/xa11/src/jar/resolver/java/org/mulgara/resolver/TuplesBasedOperation.java
===================================================================
--- branches/xa11/src/jar/resolver/java/org/mulgara/resolver/TuplesBasedOperation.java	                        (rev 0)
+++ branches/xa11/src/jar/resolver/java/org/mulgara/resolver/TuplesBasedOperation.java	2009-01-24 01:05:24 UTC (rev 1453)
@@ -0,0 +1,52 @@
+/*
+ * 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.resolver;
+
+import java.util.Arrays;
+
+import org.mulgara.query.Variable;
+import org.mulgara.store.statement.StatementStore;
+
+/**
+ * Handles mapping of Tuples to expected columns, when necessary.
+ *
+ * @created Jan 23, 2009
+ * @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 abstract class TuplesBasedOperation {
+
+  /**
+   * Check a variable array to see if it is in SPOG or GSPO order, and return a mapping array
+   * to allow the columns to be accessed in SPOG order. If assertions are enabled, then the
+   * entire structure is tested, otherwise the first column is all that is tested.
+   * @param vars The variables to test for order.
+   * @return A mapping array used to access variables in SPOG order.
+   */
+  protected static final int[] mapColumnsToStd(Variable[] vars) {
+    assert vars.length == 4 : "Wrong number of variables. Expected {Subject,Predicate,Object,Meta} got " + Arrays.toString(vars);
+    if (vars[0] == StatementStore.VARIABLES[0]) {
+      assert vars[1] == StatementStore.VARIABLES[1] : "Expected '" + StatementStore.VARIABLES[1] + "' got '" + vars[1];
+      assert vars[2] == StatementStore.VARIABLES[2] : "Expected '" + StatementStore.VARIABLES[2] + "' got '" + vars[2];
+      assert vars[3] == StatementStore.VARIABLES[3] : "Expected '" + StatementStore.VARIABLES[3] + "' got '" + vars[3];
+      return new int[] { 0, 1, 2, 3 };
+    } else {
+      assert vars[0] == StatementStore.VARIABLES[3] : "Expected '" + StatementStore.VARIABLES[3] + "' got '" + vars[0];
+      assert vars[1] == StatementStore.VARIABLES[0] : "Expected '" + StatementStore.VARIABLES[0] + "' got '" + vars[1];
+      assert vars[2] == StatementStore.VARIABLES[1] : "Expected '" + StatementStore.VARIABLES[1] + "' got '" + vars[2];
+      assert vars[3] == StatementStore.VARIABLES[2] : "Expected '" + StatementStore.VARIABLES[2] + "' got '" + vars[3];
+      return new int[] { 1, 2, 3, 0 };
+    }
+  }
+}




More information about the Mulgara-svn mailing list