Search in sources :

Example 1 with QueryIterCommonParent

use of org.apache.jena.sparql.engine.iterator.QueryIterCommonParent in project jena by apache.

the class QueryIterService method nextStage.

@Override
protected QueryIterator nextStage(Binding outerBinding) {
    boolean silent = opService.getSilent();
    ExecutionContext execCxt = getExecContext();
    Context cxt = execCxt.getContext();
    ServiceExecutorRegistry registry = ServiceExecutorRegistry.get(cxt);
    ServiceExecution svcExec = null;
    OpService substitutedOp = (OpService) QC.substitute(opService, outerBinding);
    try {
        // ---- Find handler
        if (registry != null) {
            for (ServiceExecutorFactory factory : registry.getFactories()) {
                // Internal consistency check
                if (factory == null) {
                    Log.warn(this, "SERVICE <" + opService.getService().toString() + ">: Null item in custom ServiceExecutionRegistry");
                    continue;
                }
                svcExec = factory.createExecutor(substitutedOp, opService, outerBinding, execCxt);
                if (svcExec != null)
                    break;
            }
        }
        // ---- Execute
        if (svcExec == null)
            throw new QueryExecException("No SERVICE handler");
        QueryIterator qIter = svcExec.exec();
        qIter = QueryIter.makeTracked(qIter, getExecContext());
        // There should be no variables in common because of the OpSubstitute.substitute
        return new QueryIterCommonParent(qIter, outerBinding, getExecContext());
    } catch (RuntimeException ex) {
        if (silent) {
            Log.warn(this, "SERVICE " + NodeFmtLib.strTTL(substitutedOp.getService()) + " : " + ex.getMessage());
            // Return the input
            return QueryIterSingleton.create(outerBinding, getExecContext());
        }
        throw ex;
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ServiceExecutorFactory(org.apache.jena.sparql.service.ServiceExecutorFactory) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ServiceExecution(org.apache.jena.sparql.service.ServiceExecution) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) QueryIterCommonParent(org.apache.jena.sparql.engine.iterator.QueryIterCommonParent) OpService(org.apache.jena.sparql.algebra.op.OpService) ServiceExecutorRegistry(org.apache.jena.sparql.service.ServiceExecutorRegistry) QueryExecException(org.apache.jena.query.QueryExecException)

Aggregations

QueryExecException (org.apache.jena.query.QueryExecException)1 OpService (org.apache.jena.sparql.algebra.op.OpService)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)1 QueryIterCommonParent (org.apache.jena.sparql.engine.iterator.QueryIterCommonParent)1 ServiceExecution (org.apache.jena.sparql.service.ServiceExecution)1 ServiceExecutorFactory (org.apache.jena.sparql.service.ServiceExecutorFactory)1 ServiceExecutorRegistry (org.apache.jena.sparql.service.ServiceExecutorRegistry)1 Context (org.apache.jena.sparql.util.Context)1