Class QueryExecutionAdapter
- java.lang.Object
-
- org.apache.jena.sparql.exec.QueryExecutionAdapter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,QueryExecution
- Direct Known Subclasses:
QueryExecutionCompat
,QueryExecutionHTTP
public class QueryExecutionAdapter extends java.lang.Object implements QueryExecution
QueryExecution for a QueryExec working at the Graph-Node-Triple level.- See Also:
QueryExecution
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Stop in mid execution.static QueryExecution
adapt(QueryExec qExec)
void
close()
Close the query execution and stop query evaluation as soon as convenient.boolean
execAsk()
Execute an ASK queryModel
execConstruct()
Execute a CONSTRUCT queryModel
execConstruct(Model model)
Execute a CONSTRUCT query, putting the statements into a graph.Dataset
execConstructDataset()
Execute a CONSTRUCT query, putting the statements into 'dataset'.Dataset
execConstructDataset(Dataset dataset)
Execute a CONSTRUCT query, putting the statements into 'dataset'.java.util.Iterator<Quad>
execConstructQuads()
Execute a CONSTRUCT query, returning the results as an iterator ofQuad
.java.util.Iterator<Triple>
execConstructTriples()
Execute a CONSTRUCT query, returning the results as an iterator ofTriple
.Model
execDescribe()
Execute a DESCRIBE queryModel
execDescribe(Model model)
Execute a DESCRIBE query, putting the statements into a graph.java.util.Iterator<Triple>
execDescribeTriples()
Execute a DESCRIBE query, returning the results as an iterator ofTriple
.JsonArray
execJson()
Execute a JSON query and return a json arrayjava.util.Iterator<JsonObject>
execJsonItems()
Execute a JSON query and return an iteratorResultSet
execSelect()
Execute a SELECT queryContext
getContext()
The properties associated with a query execution - implementation specific parameters This includes Java objects (so it is not an RDF graph).Dataset
getDataset()
The dataset against which the query will execute.Query
getQuery()
The query associated with a query execution.java.lang.String
getQueryString()
The query as a string.long
getTimeout1()
Return the first timeout (time to first result), in milliseconds: negative if unsetlong
getTimeout2()
Return the second timeout (overall query execution after first result), in milliseconds: negative if unsetboolean
isClosed()
Answer whether this QueryExecution object has been closed or not.void
setInitialBinding(QuerySolution binding)
Set the initial association of variables and values.void
setInitialBinding(Binding binding)
Set the initial association of variables and values.void
setTimeout(long timeout)
Set time, in millisecondsvoid
setTimeout(long timeout1, long timeout2)
Set time, in millisecondsvoid
setTimeout(long timeout, java.util.concurrent.TimeUnit timeoutUnits)
Set a timeout on the query execution.void
setTimeout(long timeout1, java.util.concurrent.TimeUnit timeUnit1, long timeout2, java.util.concurrent.TimeUnit timeUnit2)
Set timeouts on the query execution; the first timeout refers to time to first result, the second refers to overall query execution after the first result.
-
-
-
Method Detail
-
adapt
public static QueryExecution adapt(QueryExec qExec)
-
setInitialBinding
public void setInitialBinding(Binding binding)
Set the initial association of variables and values. May not be supported by all QueryExecution implementations.- Specified by:
setInitialBinding
in interfaceQueryExecution
- Parameters:
binding
-
-
getDataset
public Dataset getDataset()
The dataset against which the query will execute. May be null, implying it is expected that the query itself has a dataset description.- Specified by:
getDataset
in interfaceQueryExecution
-
getContext
public Context getContext()
The properties associated with a query execution - implementation specific parameters This includes Java objects (so it is not an RDF graph). Keys should be URIs as strings. May be null (this implementation does not provide any configuration).- Specified by:
getContext
in interfaceQueryExecution
-
getQuery
public Query getQuery()
The query associated with a query execution. May be null (QueryExecution may have been created by other means)- Specified by:
getQuery
in interfaceQueryExecution
-
getQueryString
public java.lang.String getQueryString()
The query as a string. This may be null (QueryExec may have been created by other means). This may contain non-Jena extensions and can not be parsed by Jena. IfgetQuery()
is not null, this is a corresponding string that parses to the same query.- Specified by:
getQueryString
in interfaceQueryExecution
-
execSelect
public ResultSet execSelect()
Execute a SELECT queryImportant: The name of this method is somewhat of a misnomer in that depending on the underlying implementation this typically does not execute the SELECT query but rather answers a wrapper over an internal data structure that can be used to answer the query. In essence calling this method only returns a plan for executing this query which only gets evaluated when you actually start iterating over the results.
- Specified by:
execSelect
in interfaceQueryExecution
-
execConstruct
public Model execConstruct()
Execute a CONSTRUCT query- Specified by:
execConstruct
in interfaceQueryExecution
-
execConstruct
public Model execConstruct(Model model)
Execute a CONSTRUCT query, putting the statements into a graph.- Specified by:
execConstruct
in interfaceQueryExecution
- Returns:
- Graph The model argument for cascaded code.
-
execConstructTriples
public java.util.Iterator<Triple> execConstructTriples()
Execute a CONSTRUCT query, returning the results as an iterator ofTriple
.Caution: This method may return duplicate Triples. This method may be useful if you only need the results for stream processing, as it can avoid having to place the results in a Model.
Important: The name of this method is somewhat of a misnomer in that depending on the underlying implementation this typically does not execute the CONSTRUCT query but rather answers a wrapper over an internal data structure that can be used to answer the query. In essence calling this method only returns a plan for executing this query which only gets evaluated when you actually start iterating over the results.
- Specified by:
execConstructTriples
in interfaceQueryExecution
- Returns:
- An iterator of Triple objects (possibly containing duplicates) generated by applying the CONSTRUCT template of the query to the bindings in the WHERE clause.
-
execConstructQuads
public java.util.Iterator<Quad> execConstructQuads()
Execute a CONSTRUCT query, returning the results as an iterator ofQuad
.Caution: This method may return duplicate Quads. This method may be useful if you only need the results for stream processing, as it can avoid having to place the results in a Model.
- Specified by:
execConstructQuads
in interfaceQueryExecution
- Returns:
- An iterator of Quad objects (possibly containing duplicates) generated
by applying the CONSTRUCT template of the query to the bindings in the WHERE clause.
See
execConstructTriples()
for usage and features.
-
execConstructDataset
public Dataset execConstructDataset()
Execute a CONSTRUCT query, putting the statements into 'dataset'. This maybe an extended syntax query (if supported).- Specified by:
execConstructDataset
in interfaceQueryExecution
-
execConstructDataset
public Dataset execConstructDataset(Dataset dataset)
Execute a CONSTRUCT query, putting the statements into 'dataset'. This may be an extended syntax query (if supported).- Specified by:
execConstructDataset
in interfaceQueryExecution
-
execDescribe
public Model execDescribe()
Execute a DESCRIBE query- Specified by:
execDescribe
in interfaceQueryExecution
-
execDescribe
public Model execDescribe(Model model)
Execute a DESCRIBE query, putting the statements into a graph.- Specified by:
execDescribe
in interfaceQueryExecution
- Returns:
- Graph The model argument for cascaded code.
-
execDescribeTriples
public java.util.Iterator<Triple> execDescribeTriples()
Execute a DESCRIBE query, returning the results as an iterator ofTriple
.Caution: This method may return duplicate Triples. This method may be useful if you only need the results for stream processing, as it can avoid having to place the results in a Model.
Important: The name of this method is somewhat of a misnomer in that depending on the underlying implementation this typically does not execute the DESCRIBE query but rather answers a wrapper over an internal data structure that can be used to answer the query. In essence calling this method only returns a plan for executing this query which only gets evaluated when you actually start iterating over the results.
- Specified by:
execDescribeTriples
in interfaceQueryExecution
- Returns:
- An iterator of Triple objects (possibly containing duplicates) generated as the output of the DESCRIBE query.
-
execAsk
public boolean execAsk()
Execute an ASK query- Specified by:
execAsk
in interfaceQueryExecution
-
execJson
public JsonArray execJson()
Execute a JSON query and return a json array- Specified by:
execJson
in interfaceQueryExecution
-
execJsonItems
public java.util.Iterator<JsonObject> execJsonItems()
Execute a JSON query and return an iterator- Specified by:
execJsonItems
in interfaceQueryExecution
-
abort
public void abort()
Stop in mid execution. This method can be called in parallel with other methods on the QueryExecution object. There is no guarantee that the concrete implementation actual will stop or that it will do so immediately. No operations on the query execution or any associated result set are permitted after this call and may cause exceptions to be thrown.- Specified by:
abort
in interfaceQueryExecution
-
close
public void close()
Close the query execution and stop query evaluation as soon as convenient. QueryExecution objects, and aResultSet
fromexecSelect()
, can not be used once the QueryExecution is closed. Model results fromexecConstruct()
andexecDescribe()
are still valid. It is important to close query execution objects in order to release resources such as working memory and to stop the query execution. Some storage subsystems require explicit ends of operations and this operation will cause those to be called where necessary. No operations on the query execution or any associated result set are permitted after this call.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceQueryExecution
-
isClosed
public boolean isClosed()
Answer whether this QueryExecution object has been closed or not.- Specified by:
isClosed
in interfaceQueryExecution
- Returns:
- boolean
-
setTimeout
public void setTimeout(long timeout, java.util.concurrent.TimeUnit timeoutUnits)
Set a timeout on the query execution. Processing will be aborted after the timeout (which starts when the appropriate exec call is made). Not all query execution systems support timeouts. A timeout of less than zero means no timeout.- Specified by:
setTimeout
in interfaceQueryExecution
- See Also:
QueryExecutionDatasetBuilder.timeout(long, java.util.concurrent.TimeUnit)
-
setTimeout
public void setTimeout(long timeout)
Set time, in milliseconds- Specified by:
setTimeout
in interfaceQueryExecution
- See Also:
setTimeout(long, TimeUnit)
-
setTimeout
public void setTimeout(long timeout1, java.util.concurrent.TimeUnit timeUnit1, long timeout2, java.util.concurrent.TimeUnit timeUnit2)
Set timeouts on the query execution; the first timeout refers to time to first result, the second refers to overall query execution after the first result. Processing will be aborted if a timeout expires. Not all query execution systems support timeouts. A timeout of less than zero means no timeout; this can be used for timeout1 or timeout2.- Specified by:
setTimeout
in interfaceQueryExecution
-
setTimeout
public void setTimeout(long timeout1, long timeout2)
Set time, in milliseconds- Specified by:
setTimeout
in interfaceQueryExecution
- See Also:
setTimeout(long, TimeUnit, long, TimeUnit)
-
getTimeout1
public long getTimeout1()
Return the first timeout (time to first result), in milliseconds: negative if unset- Specified by:
getTimeout1
in interfaceQueryExecution
-
getTimeout2
public long getTimeout2()
Return the second timeout (overall query execution after first result), in milliseconds: negative if unset- Specified by:
getTimeout2
in interfaceQueryExecution
-
setInitialBinding
public void setInitialBinding(QuerySolution binding)
Description copied from interface:QueryExecution
Set the initial association of variables and values. May not be supported by all QueryExecution implementations.The preferred way is to use
QueryExecutionDatasetBuilder.substitution(QuerySolution)
which is supported uniformly for local and remote queries.- Specified by:
setInitialBinding
in interfaceQueryExecution
-
-