[Mulgara-svn] r1605 - in trunk/src/jar: query/java/org/mulgara/query/filter query/java/org/mulgara/query/filter/arithmetic query/java/org/mulgara/query/filter/value tuples/java/org/mulgara/store/tuples
pag at mulgara.org
pag at mulgara.org
Thu Mar 12 20:57:41 UTC 2009
Author: pag
Date: 2009-03-12 13:57:40 -0700 (Thu, 12 Mar 2009)
New Revision: 1605
Modified:
trunk/src/jar/query/java/org/mulgara/query/filter/AbstractContextOwner.java
trunk/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java
trunk/src/jar/query/java/org/mulgara/query/filter/ContextOwner.java
trunk/src/jar/query/java/org/mulgara/query/filter/Filter.java
trunk/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java
trunk/src/jar/query/java/org/mulgara/query/filter/TestContext.java
trunk/src/jar/query/java/org/mulgara/query/filter/TestContextOwner.java
trunk/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java
trunk/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java
trunk/src/jar/query/java/org/mulgara/query/filter/value/IRI.java
trunk/src/jar/query/java/org/mulgara/query/filter/value/Var.java
trunk/src/jar/query/java/org/mulgara/query/filter/value/VarUnitTest.java
trunk/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java
trunk/src/jar/tuples/java/org/mulgara/store/tuples/LeftJoin.java
Log:
Fixed filter contexts to propagate recursively. Also added a system to safely push out changes to all terms in an expression in a single step, so that recursive context discovery isn't needed over and over again as a Tuples iterates.
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/AbstractContextOwner.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/AbstractContextOwner.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/AbstractContextOwner.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -11,7 +11,10 @@
*/
package org.mulgara.query.filter;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Defines how to set and retrieve context
*
@@ -25,16 +28,36 @@
/** The more recent context */
private Context context = null;
+ /** A list of context owners that this owner provides the context for. */
+ private List<ContextOwner> contextListeners = new ArrayList<ContextOwner>();
+
/**
+ * Adds a context owner as a listener so that it will be updated with its context
+ * when this owner gets updated.
+ * @param l The context owner to register.
+ */
+ public void addContextListener(ContextOwner l) {
+ contextListeners.add(l);
+ }
+
+ /**
* Set the current context. This *must* be run at the start of every test else the underlying
* values will not resolve correctly.
* @param context The context for this test.
*/
- public void setCurrentContext(Context context) { this.context = context; }
+ public void setCurrentContext(Context context) {
+ this.context = context;
+ // update anyone who asked to be updated
+ for (ContextOwner l: contextListeners) l.setCurrentContext(context);
+ }
/**
* Get the current context. This is a callback that is used during a test.
* @return The context of the currently running test, or the most recent context if not in a test.
*/
- public Context getCurrentContext() { return context; }
+ public Context getCurrentContext() {
+ if (context != null) return context;
+ ContextOwner parent = getContextOwner();
+ return parent == null ? null : parent.getCurrentContext();
+ }
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -134,7 +134,10 @@
public ContextOwner getContextOwner() { return contextOwner; }
/** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
- public void setContextOwner(ContextOwner owner) { contextOwner = owner; }
+ public void setContextOwner(ContextOwner owner) {
+ contextOwner = owner;
+ owner.addContextListener(this);
+ }
/** @see org.mulgara.query.filter.ContextOwner#getCurrentContext() */
public Context getCurrentContext() { return contextOwner.getCurrentContext(); }
@@ -142,6 +145,7 @@
/** @see org.mulgara.query.filter.ContextOwner#setCurrentContext(org.mulgara.query.filter.Context) */
public void setCurrentContext(Context context) {
if (!(context.equals(contextOwner.getCurrentContext()))) throw new AssertionError("Filter context being set differently to initial calling context.");
+ super.setCurrentContext(context);
}
/**
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/ContextOwner.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/ContextOwner.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/ContextOwner.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -34,4 +34,24 @@
* @return The context of the currently running test, or the most recent context if not in a test.
*/
public Context getCurrentContext();
+
+ /**
+ * Sets the object that contains the current context to work in.
+ * @param owner The object that owns this context.
+ */
+ public void setContextOwner(ContextOwner owner);
+
+ /**
+ * Gets the object that contains the current context to work in.
+ * @return The object that owns this context.
+ */
+ public ContextOwner getContextOwner();
+
+ /**
+ * Adds a context owner as a listener so that it will be updated with its context
+ * when this owner gets updated.
+ * @param l The context owner to register.
+ */
+ public void addContextListener(ContextOwner l);
+
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/Filter.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/Filter.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/Filter.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -48,6 +48,7 @@
public boolean isURI() throws QueryException { return false; }
public boolean sameTerm(RDFTerm v) throws QueryException { return equals(v); }
public void setContextOwner(ContextOwner owner) { }
+ public void addContextListener(ContextOwner l) { }
};
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -24,7 +24,7 @@
* @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public interface RDFTerm extends Serializable {
+public interface RDFTerm extends Serializable, ContextOwner {
/**
* Returns the data represented by this expression.
@@ -70,15 +70,4 @@
*/
public boolean sameTerm(RDFTerm v) throws QueryException;
- /**
- * Sets the object that contains the current context to work in.
- * @param owner The object that owns this context.
- */
- public void setContextOwner(ContextOwner owner);
-
- /**
- * Gets the object that contains the current context to work in.
- * @return The object that owns this context.
- */
- public ContextOwner getContextOwner();
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/TestContext.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/TestContext.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/TestContext.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -108,6 +108,8 @@
/** @see org.mulgara.query.filter.Context#isBound(int) */
public boolean isBound(int columnNumber) throws QueryException {
if (columnNumber >= columnNames.size()) throw new QueryException("Unexpected column: " + columnNumber);
+ if (rowNumber < 0) throw new QueryException("beforeFirst() called on Context without next()");
+ if (rowNumber >= rows.length) throw new QueryException("called next() on Context too often");
return rows[rowNumber][columnNumber] != null;
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/TestContextOwner.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/TestContextOwner.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/TestContextOwner.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -11,7 +11,10 @@
*/
package org.mulgara.query.filter;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* A test class for emulating a context ownership.
*
@@ -24,6 +27,9 @@
/** The owned context */
private Context ctx;
+ /** A list of context owners that this owner provides the context for. */
+ private List<ContextOwner> contextListeners = new ArrayList<ContextOwner>();
+
/**
* Create the test ownership.
* @param ctx The context to own.
@@ -34,9 +40,37 @@
* Updates the owned context.
* @param ctx The context to update to.
*/
- public void setCurrentContext(Context ctx) { this.ctx = ctx; }
+ public void setCurrentContext(Context ctx) {
+ this.ctx = ctx;
+ for (ContextOwner l: contextListeners) l.setCurrentContext(ctx);
+ }
/** @return the current context. */
public Context getCurrentContext() { return ctx; }
+ /**
+ * Adds a context owner as a listener so that it will be updated with its context
+ * when this owner gets updated.
+ * @param l The context owner to register.
+ */
+ public void addContextListener(ContextOwner l) {
+ contextListeners.add(l);
+ }
+
+ /**
+ * This provides a context, and does not need to refer to a parent.
+ * @see org.mulgara.query.filter.ContextOwner#getContextOwner()
+ */
+ public ContextOwner getContextOwner() {
+ throw new IllegalStateException("Should never be asking for the context owner of a Tuples");
+ }
+
+ /**
+ * The owner of the context for a Tuples is never needed, since it is always provided by the Tuples.
+ * @see org.mulgara.query.filter.ContextOwner#setContextOwner(org.mulgara.query.filter.ContextOwner)
+ */
+ public void setContextOwner(ContextOwner owner) {
+ throw new IllegalStateException("Should never be setting the context owner of a Tuples");
+ }
+
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -63,6 +63,7 @@
/** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
public void setContextOwner(ContextOwner owner) {
this.owner = owner;
+ owner.addContextListener(this);
}
/** @see org.mulgara.query.filter.RDFTerm#getContextOwner() */
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -13,6 +13,7 @@
import org.jrdf.graph.BlankNode;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.Context;
import org.mulgara.query.filter.ContextOwner;
import org.mulgara.query.filter.RDFTerm;
@@ -73,4 +74,14 @@
/** This value does not need a context */
public void setContextOwner(ContextOwner owner) { }
+
+ /** This value does not need a context */
+ public Context getCurrentContext() { return null; }
+
+ /** This value does not need a context */
+ public void setCurrentContext(Context context) { }
+
+ /** This value does not need a context */
+ public void addContextListener(ContextOwner l) { }
+
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/value/IRI.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/value/IRI.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/value/IRI.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -14,6 +14,7 @@
import java.net.URI;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.Context;
import org.mulgara.query.filter.ContextOwner;
import org.mulgara.query.filter.RDFTerm;
@@ -85,4 +86,13 @@
/** This value does not need a context */
public void setContextOwner(ContextOwner owner) { }
+ /** This value does not need a context */
+ public Context getCurrentContext() { return null; }
+
+ /** This value does not need a context */
+ public void setCurrentContext(Context context) { }
+
+ /** This value does not need a context */
+ public void addContextListener(ContextOwner l) { }
+
}
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/value/Var.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/value/Var.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/value/Var.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -202,6 +202,7 @@
/** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
public void setContextOwner(ContextOwner owner) {
this.contextOwner = owner;
+ owner.addContextListener(this);
}
/**
Modified: trunk/src/jar/query/java/org/mulgara/query/filter/value/VarUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/filter/value/VarUnitTest.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/query/java/org/mulgara/query/filter/value/VarUnitTest.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -12,6 +12,8 @@
package org.mulgara.query.filter.value;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
import org.jrdf.graph.BlankNode;
import org.jrdf.graph.Literal;
@@ -52,6 +54,9 @@
/** A blank node used in the context */
BlankNode bn = new BlankNodeImpl();
+ /** A list of context owners that we may want to update if the context changes */
+ List<ContextOwner> contextListeners = new ArrayList<ContextOwner>();
+
/**
* Build the unit test.
* @param name The name of the test
@@ -311,6 +316,29 @@
return context;
}
- public void setCurrentContext(Context context) { /* no op */ }
-
+ public void setCurrentContext(Context context) {
+ for (ContextOwner l: contextListeners) l.setCurrentContext(context);
+ }
+
+ /**
+ * This provides a context, and does not need to refer to a parent.
+ * @see org.mulgara.query.filter.ContextOwner#getContextOwner()
+ */
+ public ContextOwner getContextOwner() {
+ throw new IllegalStateException("Should never be asking for the context owner of a Tuples");
+ }
+
+ /**
+ * The owner of the context for a Tuples is never needed, since it is always provided by the Tuples.
+ * @see org.mulgara.query.filter.ContextOwner#setContextOwner(org.mulgara.query.filter.ContextOwner)
+ */
+ public void setContextOwner(ContextOwner owner) { }
+
+ /**
+ * This provides a context and cannot be a parent
+ * @see org.mulgara.query.filter.ContextOwner#addContextListener(org.mulgara.query.filter.ContextOwner)
+ */
+ public void addContextListener(ContextOwner l) {
+ contextListeners.add(l);
+ }
}
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -63,6 +63,9 @@
/** The tuples context */
protected TuplesContext context;
+ /** A list of context owners that this owner provides the context for. */
+ private List<ContextOwner> contextListeners = new ArrayList<ContextOwner>();
+
/**
* Configure a tuples for filtering.
*
@@ -209,6 +212,7 @@
public void setCurrentContext(Context context) {
if (!(context instanceof TuplesContext)) throw new IllegalArgumentException("FilteredTuples can only accept a TuplesContext.");
this.context = (TuplesContext)context;
+ for (ContextOwner l: contextListeners) l.setCurrentContext(context);
}
/**
@@ -225,4 +229,32 @@
return false;
}
}
+
+
+ /**
+ * This provides a context, and does not need to refer to a parent.
+ * @see org.mulgara.query.filter.ContextOwner#getContextOwner()
+ */
+ public ContextOwner getContextOwner() {
+ throw new IllegalStateException("Should never be asking for the context owner of a Tuples");
+ }
+
+
+ /**
+ * The owner of the context for a Tuples is never needed, since it is always provided by the Tuples.
+ * @see org.mulgara.query.filter.ContextOwner#setContextOwner(org.mulgara.query.filter.ContextOwner)
+ */
+ public void setContextOwner(ContextOwner owner) {
+ }
+
+
+ /**
+ * Adds a context owner as a listener so that it will be updated with its context
+ * when this owner gets updated.
+ * @param l The context owner to register.
+ */
+ public void addContextListener(ContextOwner l) {
+ contextListeners.add(l);
+ }
+
}
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/LeftJoin.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/LeftJoin.java 2009-03-12 06:56:16 UTC (rev 1604)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/LeftJoin.java 2009-03-12 20:57:40 UTC (rev 1605)
@@ -65,6 +65,9 @@
/** The tuples context */
protected TuplesContext context = null;
+ /** A list of context owners that this owner provides the context for. */
+ private List<ContextOwner> contextListeners = new ArrayList<ContextOwner>();
+
/** The set of variables common to both the lhs and the rhs. */
protected Set<Variable> commonVars;
@@ -399,9 +402,35 @@
public void setCurrentContext(Context context) {
if (!(context instanceof TuplesContext)) throw new IllegalArgumentException("LeftJoin can only accept a TuplesContext.");
this.context = (TuplesContext)context;
+ for (ContextOwner l: contextListeners) l.setCurrentContext(context);
}
+ /**
+ * This provides a context, and does not need to refer to a parent.
+ * @see org.mulgara.query.filter.ContextOwner#getContextOwner()
+ */
+ public ContextOwner getContextOwner() {
+ throw new IllegalStateException("Should never be asking for the context owner of a Tuples");
+ }
+
+
+ /**
+ * The owner of the context for a Tuples is never needed, since it is always provided by the Tuples.
+ * @see org.mulgara.query.filter.ContextOwner#setContextOwner(org.mulgara.query.filter.ContextOwner)
+ */
+ public void setContextOwner(ContextOwner owner) {
+ }
+
+ /**
+ * Adds a context owner as a listener so that it will be updated with its context
+ * when this owner gets updated.
+ * @param l The context owner to register.
+ */
+ public void addContextListener(ContextOwner l) {
+ contextListeners.add(l);
+ }
+
//
// Internal methods and classes
//
More information about the Mulgara-svn
mailing list