[Mulgara-svn] r845 - branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples
pag at mulgara.org
pag at mulgara.org
Thu Apr 24 17:32:52 UTC 2008
Author: pag
Date: 2008-04-24 10:32:51 -0700 (Thu, 24 Apr 2008)
New Revision: 845
Modified:
branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java
Log:
Updates filters with context whenever testing, as the Tuples and context may be cloned, but the filters are not
Modified: branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java
===================================================================
--- branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java 2008-04-24 08:48:52 UTC (rev 844)
+++ branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/FilteredTuples.java 2008-04-24 17:32:51 UTC (rev 845)
@@ -61,21 +61,21 @@
protected Filter filter;
/** The tuples context */
- protected Context context;
+ protected TuplesContext context;
/**
* Configure a tuples for filtering.
*
* @param unfiltered The original tuples.
* @param filter The filter to apply.
- * @param context The context to evaluate the tuples in.
+ * @param queryContext The context to evaluate the tuples in.
* @throws IllegalArgumentException If the <var>unfiltered</var> tuples is null.
*/
- FilteredTuples(Tuples unfiltered, Filter filter, QueryEvaluationContext context) throws IllegalArgumentException {
+ FilteredTuples(Tuples unfiltered, Filter filter, QueryEvaluationContext queryContext) throws IllegalArgumentException {
// store the operands
this.filter = filter;
this.unfiltered = (Tuples)unfiltered.clone();
- this.context = new TuplesContext(this.unfiltered, context.getResolverSession());
+ this.context = new TuplesContext(this.unfiltered, queryContext.getResolverSession());
filter.setContextOwner(this);
}
@@ -151,7 +151,7 @@
unfiltered.beforeFirst(prefix, suffixTruncation);
}
-
+
/**
* @return {@inheritDoc}
* @throws TuplesException {@inheritDoc}
@@ -164,7 +164,7 @@
// Short-circuit execution if this tuples' cursor is after the last row
if (!currentNext) return false;
// check if the filter passes the current row on the unfiltered
- } while (!filter.test(context));
+ } while (!testFilter());
} catch (QueryException qe) {
throw new TuplesException("Unable to iterate to the next tuples element while filtering", qe);
}
@@ -183,12 +183,9 @@
public Object clone() {
FilteredTuples cloned = (FilteredTuples)super.clone();
- // Copy mutable fields by value
+ // Clone the mutable fields as well
cloned.unfiltered = (Tuples)unfiltered.clone();
- // update the tuples in the context to the new value
- if (context instanceof TuplesContext) {
- ((TuplesContext)cloned.context).setTuples(cloned.unfiltered);
- }
+ cloned.context = new TuplesContext(cloned.unfiltered, context);
return cloned;
}
@@ -207,7 +204,18 @@
* @see org.mulgara.query.filter.ContextOwner#setCurrentContext(org.mulgara.query.filter.Context)
*/
public void setCurrentContext(Context context) {
- this.context = context;
+ if (!(context instanceof TuplesContext)) throw new IllegalArgumentException("FilteredTuples can only accept a TuplesContext.");
+ this.context = (TuplesContext)context;
}
+ /**
+ * Tests a filter using the current context.
+ * @return The test result.
+ * @throws QueryException If there was an error accessing data needed for the test.
+ */
+ private boolean testFilter() throws QueryException {
+ // re-root the filter expression to this Tuples
+ filter.setContextOwner(this);
+ return filter.test(context);
+ }
}
More information about the Mulgara-svn
mailing list