You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/06/12 21:10:53 UTC
svn commit: r1492380 -
/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java
Author: andy
Date: Wed Jun 12 19:10:53 2013
New Revision: 1492380
URL: http://svn.apache.org/r1492380
Log:
Sync example to OpExecutor changes.
Modified:
jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java
Modified: jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java?rev=1492380&r1=1492379&r2=1492380&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java Wed Jun 12 19:10:53 2013
@@ -16,19 +16,14 @@
* limitations under the License.
*/
-package opexec;
+package opexec ;
import java.io.StringReader ;
import org.apache.jena.atlas.lib.StrUtils ;
import org.apache.jena.atlas.logging.Log ;
-import com.hp.hpl.jena.query.ARQ ;
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryExecution ;
-import com.hp.hpl.jena.query.QueryExecutionFactory ;
-import com.hp.hpl.jena.query.QueryFactory ;
-import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.query.* ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.ModelFactory ;
import com.hp.hpl.jena.sparql.algebra.op.OpBGP ;
@@ -39,39 +34,37 @@ import com.hp.hpl.jena.sparql.engine.Que
import com.hp.hpl.jena.sparql.engine.main.OpExecutor ;
import com.hp.hpl.jena.sparql.engine.main.OpExecutorFactory ;
import com.hp.hpl.jena.sparql.engine.main.QC ;
-import com.hp.hpl.jena.sparql.engine.main.StageBuilder ;
-/** Example skeleton for a query engine.
- * To just extend ARQ by custom basic graph pattern matching (a very common case)
- * see the arq.examples.bgpmatching package */
+/**
+ * Example skeleton for a query engine. To just extend ARQ by custom basic graph
+ * pattern matching (a very common case) see the arq.examples.bgpmatching
+ * package
+ */
-public class OpExecutorExample //extends QueryEngineMain
+public class OpExecutorExample // extends QueryEngineMain
{
// UNFINISHED
// Check where OpExecutorFactory.create happens.
-
- /* To install a custom OpExecutor, the application needs
+
+ /*
+ * To install a custom OpExecutor, the application needs
*
- *
- * The example MyQueryEngine shows how to take over the
- * execution of a SPARQL algebra expression. This allows
- * customization of optimizations running before query execution
- * starts.
*
- * An OpExecutor controls the running of an algebra expression.
- * An executor needs to cope with the fact a dataset might be composed
- * of a mixture of graphs, and that it might be be being called for any
- * kind of storage unit, not just one it is designed for.
+ * The example MyQueryEngine shows how to take over the execution of a
+ * SPARQL algebra expression. This allows customization of optimizations
+ * running before query execution starts.
*
- * Thsi is done by having a chain (via subclassing) of OpExecutors,
- * with the base class being hthe general purpose one for ARQ that can
- * operate on any data storage layer.
+ * An OpExecutor controls the running of an algebra expression. An executor
+ * needs to cope with the fact a dataset might be composed of a mixture of
+ * graphs, and that it might be be being called for any kind of storage
+ * unit, not just one it is designed for.
*
+ * Thsi is done by having a chain (via subclassing) of OpExecutors, with the
+ * base class being hthe general purpose one for ARQ that can operate on any
+ * data storage layer.
*/
-
-
- static void init()
- {
+
+ static void init() {
// Wire the new factory into the system.
ARQ.init() ;
// *** Where is the factory choosen?
@@ -79,70 +72,65 @@ public class OpExecutorExample //extends
// maybe null
QC.setFactory(ARQ.getContext(), new MyOpExecutorFactory(current)) ;
}
-
-
- public static void main(String ...argv)
- {
+
+ public static void main(String... argv) {
Log.setLog4j() ;
init() ;
Model m = data() ;
-
+
String s = "SELECT DISTINCT ?s { ?s ?p ?o FILTER (?o=12) } " ;
Query query = QueryFactory.create(s) ;
QueryExecution qExec = QueryExecutionFactory.create(query, m) ;
ResultSetFormatter.out(qExec.execSelect()) ;
qExec.close() ;
}
-
-
-
- private static Model data()
- {
- String s = StrUtils.strjoinNL("<s> <p> 12 .",
- "<s> <p> 15 .") ;
+
+ private static Model data() {
+ String s = StrUtils.strjoinNL("<s> <p> 12 .", "<s> <p> 15 .") ;
Model m = ModelFactory.createDefaultModel() ;
- m.read(new StringReader(s), null , "TTL") ;
- return m ;
+ m.read(new StringReader(s), null, "TTL") ;
+ return m ;
}
-
// This is a simple example.
// For execution logging, see:
- // http://openjena.org/wiki/ARQ/Explain
- // which printout more information.
+ // http://openjena.org/wiki/ARQ/Explain
+ // which printout more information.
static class MyOpExecutor extends OpExecutor
{
protected MyOpExecutor(ExecutionContext execCxt)
{
super(execCxt) ;
}
-
+
@Override
- protected QueryIterator execute(OpBGP opBGP, QueryIterator input)
- {
- System.out.print("Execute: "+opBGP) ;
- // This is an illustration - it's a copy of the default implementation
+ protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {
+ System.out.print("Execute: " + opBGP) ;
+ // This is an illustration - it's a copy of the default
+ // implementation
BasicPattern pattern = opBGP.getPattern() ;
- return StageBuilder.execute(pattern, input, execCxt) ;
+ return stageGenerator.execute(pattern, input, execCxt) ;
}
-
+
@Override
- protected QueryIterator execute(OpFilter opFilter, QueryIterator input)
- {
- System.out.print("Execute: "+opFilter) ;
+ protected QueryIterator execute(OpFilter opFilter, QueryIterator input) {
+ System.out.print("Execute: " + opFilter) ;
return super.execute(opFilter, input) ;
}
}
-
+
/** A factory to make OpExecutors */
static class MyOpExecutorFactory implements OpExecutorFactory
{
private final OpExecutorFactory other ;
-
- public MyOpExecutorFactory(OpExecutorFactory other) { this.other = other ; }
- @Override
- public OpExecutor create(ExecutionContext execCxt)
+
+ public MyOpExecutorFactory(OpExecutorFactory other)
{
+ this.other = other ;
+ }
+
+ @Override
+ public OpExecutor create(ExecutionContext execCxt) {
return new MyOpExecutor(execCxt) ;
}
}