Class QueryEngineHTTP
- java.lang.Object
-
- org.apache.jena.sparql.engine.http.QueryEngineHTTP
-
- All Implemented Interfaces:
java.lang.AutoCloseable,QueryExecution
public class QueryEngineHTTP extends java.lang.Object implements QueryExecution
A query execution implementation where queries are executed against a remote service
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringQUERY_MIME_TYPEstatic java.lang.String[]supportedAskContentTypesSupported content types for ASK queriesstatic java.lang.String[]supportedSelectContentTypesSupported content types for SELECT queries
-
Constructor Summary
Constructors Constructor Description QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString)QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString, org.apache.http.client.HttpClient client)QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString, org.apache.http.client.HttpClient client, org.apache.http.protocol.HttpContext httpContext)QueryEngineHTTP(java.lang.String serviceURI, Query query)QueryEngineHTTP(java.lang.String serviceURI, Query query, org.apache.http.client.HttpClient client)QueryEngineHTTP(java.lang.String serviceURI, Query query, org.apache.http.client.HttpClient client, org.apache.http.protocol.HttpContext httpContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Stop in mid execution.voidaddDefaultGraph(java.lang.String defaultGraph)voidaddNamedGraph(java.lang.String name)voidaddParam(java.lang.String field, java.lang.String value)voidcancel()Cancel query evaluationvoidclose()Close the query execution and stop query evaluation as soon as convenient.static java.lang.StringdefaultAskHeader()static java.lang.StringdefaultConstructDatasetHeader()static java.lang.StringdefaultConstructHeader()static java.lang.StringdefaultSelectHeader()booleanexecAsk()Execute an ASK queryModelexecConstruct()Execute a CONSTRUCT queryModelexecConstruct(Model model)Execute a CONSTRUCT query, putting the statements into 'model'.DatasetexecConstructDataset()Execute a CONSTRUCT query, putting the statements into 'dataset'.DatasetexecConstructDataset(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.ModelexecDescribe()Execute a DESCRIBE queryModelexecDescribe(Model model)Execute a DESCRIBE query, putting the statements into 'model'.java.util.Iterator<Triple>execDescribeTriples()Execute a DESCRIBE query, returning the results as an iterator ofTriple.JsonArrayexecJson()Execute a JSON query and return a json arrayjava.util.Iterator<JsonObject>execJsonItems()Execute a JSON query and return an interatorResultSetexecSelect()Execute a SELECT queryjava.lang.StringgetAcceptHeader()Get the HTTP Accept header for the request.booleangetAllowCompression()Gets whether HTTP requests will indicate to the remote server that compressed encoding of responses is acceptedorg.apache.http.client.HttpClientgetClient()Get the HTTP client in use, if none is set then null.ContextgetContext()The properties associated with a query execution - implementation specific parameters This includes Java objects (so it is not an RDF graph).DatasetgetDataset()The dataset against which the query will execute.org.apache.http.protocol.HttpContextgetHttpContext()Get the HTTP context in use, if none is set then null.java.lang.StringgetHttpResponseContentType()The Content-Type response header received (null before the remote operation is attempted).QuerygetQuery()The query associated with a query execution.java.lang.StringgetQueryString()Return the query string.longgetTimeout1()Return the first timeout (time to first result), in milliseconds: negative if unsetlonggetTimeout2()Return the second timeout (overall query execution after first result), in milliseconds: negative if unsetbooleanisClosed()Answer whether this QueryExecution object has been closed or not.voidsetAcceptHeader(java.lang.String acceptHeader)Set the HTTP Accept header for the request.voidsetAllowCompression(boolean allowed)Sets whether the HTTP requests will permit compressed encodingvoidsetAskContentType(java.lang.String contentType)Sets the Content Type for ASK queries provided that the format is supportedvoidsetClient(org.apache.http.client.HttpClient client)Sets the HTTP client to use, if none is set then the default client is used.voidsetDatasetContentType(java.lang.String contentType)voidsetDefaultGraphURIs(java.util.List<java.lang.String> defaultGraphURIs)voidsetHttpContext(org.apache.http.protocol.HttpContext context)Sets the HTTP context to use, if none is set then the default context is used.voidsetInitialBinding(QuerySolution binding)Set the initial association of variables and values.voidsetInitialBinding(Binding binding)Set the initial association of variables and values.voidsetModelContentType(java.lang.String contentType)Sets the Content Type for CONSTRUCT/DESCRIBE queries provided that the format is supportedvoidsetNamedGraphURIs(java.util.List<java.lang.String> namedGraphURIs)voidsetSelectContentType(java.lang.String contentType)Sets the Content Type for SELECT queries provided that the format is supportedvoidsetTimeout(long readTimeout)Set time, in millisecondsvoidsetTimeout(long readTimeout, long connectTimeout)Set time, in millisecondsvoidsetTimeout(long readTimeout, java.util.concurrent.TimeUnit timeoutUnits)Set a timeout on the query execution.voidsetTimeout(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.java.lang.StringtoString()
-
-
-
Field Detail
-
QUERY_MIME_TYPE
public static final java.lang.String QUERY_MIME_TYPE
- See Also:
- Constant Field Values
-
supportedSelectContentTypes
public static java.lang.String[] supportedSelectContentTypes
Supported content types for SELECT queries
-
supportedAskContentTypes
public static java.lang.String[] supportedAskContentTypes
Supported content types for ASK queries
-
-
Constructor Detail
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, Query query)
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, Query query, org.apache.http.client.HttpClient client)
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, Query query, org.apache.http.client.HttpClient client, org.apache.http.protocol.HttpContext httpContext)
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString)
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString, org.apache.http.client.HttpClient client)
-
QueryEngineHTTP
public QueryEngineHTTP(java.lang.String serviceURI, java.lang.String queryString, org.apache.http.client.HttpClient client, org.apache.http.protocol.HttpContext httpContext)
-
-
Method Detail
-
setInitialBinding
public void setInitialBinding(QuerySolution binding)
Description copied from interface:QueryExecutionSet the initial association of variables and values. May not be supported by all QueryExecution implementations.- Specified by:
setInitialBindingin interfaceQueryExecution
-
setInitialBinding
public void setInitialBinding(Binding binding)
Description copied from interface:QueryExecutionSet the initial association of variables and values. May not be supported by all QueryExecution implementations.- Specified by:
setInitialBindingin interfaceQueryExecution
-
setDefaultGraphURIs
public void setDefaultGraphURIs(java.util.List<java.lang.String> defaultGraphURIs)
- Parameters:
defaultGraphURIs- The defaultGraphURIs to set.
-
setNamedGraphURIs
public void setNamedGraphURIs(java.util.List<java.lang.String> namedGraphURIs)
- Parameters:
namedGraphURIs- The namedGraphURIs to set.
-
setAllowCompression
public void setAllowCompression(boolean allowed)
Sets whether the HTTP requests will permit compressed encoding
-
addParam
public void addParam(java.lang.String field, java.lang.String value)
-
addDefaultGraph
public void addDefaultGraph(java.lang.String defaultGraph)
- Parameters:
defaultGraph- The defaultGraph to add.
-
addNamedGraph
public void addNamedGraph(java.lang.String name)
- Parameters:
name- The URI to add.
-
setClient
public void setClient(org.apache.http.client.HttpClient client)
Sets the HTTP client to use, if none is set then the default client is used.- Parameters:
client- HTTP client
-
getClient
public org.apache.http.client.HttpClient getClient()
Get the HTTP client in use, if none is set then null.- Returns:
- client HTTP client
-
setHttpContext
public void setHttpContext(org.apache.http.protocol.HttpContext context)
Sets the HTTP context to use, if none is set then the default context is used.- Parameters:
context- HTTP context
-
getHttpContext
public org.apache.http.protocol.HttpContext getHttpContext()
Get the HTTP context in use, if none is set then null.- Returns:
- the
HttpContextin scope
-
getHttpResponseContentType
public java.lang.String getHttpResponseContentType()
The Content-Type response header received (null before the remote operation is attempted).
-
execSelect
public ResultSet execSelect()
Description copied from interface:QueryExecutionExecute 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:
execSelectin interfaceQueryExecution
-
execConstruct
public Model execConstruct()
Description copied from interface:QueryExecutionExecute a CONSTRUCT query- Specified by:
execConstructin interfaceQueryExecution
-
execConstruct
public Model execConstruct(Model model)
Description copied from interface:QueryExecutionExecute a CONSTRUCT query, putting the statements into 'model'.- Specified by:
execConstructin interfaceQueryExecution- Returns:
- Model The model argument for cascaded code.
-
execConstructTriples
public java.util.Iterator<Triple> execConstructTriples()
Description copied from interface:QueryExecutionExecute 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:
execConstructTriplesin 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()
Description copied from interface:QueryExecutionExecute 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:
execConstructQuadsin 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
QueryExecution.execConstructTriples()for usage and features.
-
execConstructDataset
public Dataset execConstructDataset()
Description copied from interface:QueryExecutionExecute a CONSTRUCT query, putting the statements into 'dataset'. This maybe an extended syntax query (if supported).- Specified by:
execConstructDatasetin interfaceQueryExecution
-
execConstructDataset
public Dataset execConstructDataset(Dataset dataset)
Description copied from interface:QueryExecutionExecute a CONSTRUCT query, putting the statements into 'dataset'. This maybe an extended syntax query (if supported).- Specified by:
execConstructDatasetin interfaceQueryExecution
-
execDescribe
public Model execDescribe()
Description copied from interface:QueryExecutionExecute a DESCRIBE query- Specified by:
execDescribein interfaceQueryExecution
-
execDescribe
public Model execDescribe(Model model)
Description copied from interface:QueryExecutionExecute a DESCRIBE query, putting the statements into 'model'.- Specified by:
execDescribein interfaceQueryExecution- Returns:
- Model The model argument for cascaded code.
-
execDescribeTriples
public java.util.Iterator<Triple> execDescribeTriples()
Description copied from interface:QueryExecutionExecute 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:
execDescribeTriplesin interfaceQueryExecution- Returns:
- An iterator of Triple objects (possibly containing duplicates) generated as the output of the DESCRIBE query.
-
execAsk
public boolean execAsk()
Description copied from interface:QueryExecutionExecute an ASK query- Specified by:
execAskin interfaceQueryExecution
-
execJson
public JsonArray execJson()
Description copied from interface:QueryExecutionExecute a JSON query and return a json array- Specified by:
execJsonin interfaceQueryExecution
-
execJsonItems
public java.util.Iterator<JsonObject> execJsonItems()
Description copied from interface:QueryExecutionExecute a JSON query and return an interator- Specified by:
execJsonItemsin interfaceQueryExecution
-
getContext
public Context getContext()
Description copied from interface:QueryExecutionThe 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:
getContextin interfaceQueryExecution
-
getDataset
public Dataset getDataset()
Description copied from interface:QueryExecutionThe dataset against which the query will execute. May be null, implying it is expected that the query itself has a dataset description.- Specified by:
getDatasetin interfaceQueryExecution
-
getQuery
public Query getQuery()
Description copied from interface:QueryExecutionThe query associated with a query execution. May be null (QueryExecution may have been created by other means)- Specified by:
getQueryin interfaceQueryExecution
-
getQueryString
public java.lang.String getQueryString()
Return the query string. If this was supplied in a constructor, there is no guaranttee this is legal SPARQL syntax.
-
setTimeout
public void setTimeout(long readTimeout)
Description copied from interface:QueryExecutionSet time, in milliseconds- Specified by:
setTimeoutin interfaceQueryExecution- See Also:
QueryExecution.setTimeout(long, TimeUnit)
-
setTimeout
public void setTimeout(long readTimeout, long connectTimeout)Description copied from interface:QueryExecutionSet time, in milliseconds- Specified by:
setTimeoutin interfaceQueryExecution- See Also:
QueryExecution.setTimeout(long, TimeUnit, long, TimeUnit)
-
setTimeout
public void setTimeout(long readTimeout, java.util.concurrent.TimeUnit timeoutUnits)Description copied from interface:QueryExecutionSet 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:
setTimeoutin interfaceQueryExecution
-
setTimeout
public void setTimeout(long timeout1, java.util.concurrent.TimeUnit timeUnit1, long timeout2, java.util.concurrent.TimeUnit timeUnit2)Description copied from interface:QueryExecutionSet 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:
setTimeoutin interfaceQueryExecution
-
getTimeout1
public long getTimeout1()
Description copied from interface:QueryExecutionReturn the first timeout (time to first result), in milliseconds: negative if unset- Specified by:
getTimeout1in interfaceQueryExecution
-
getTimeout2
public long getTimeout2()
Description copied from interface:QueryExecutionReturn the second timeout (overall query execution after first result), in milliseconds: negative if unset- Specified by:
getTimeout2in interfaceQueryExecution
-
getAllowCompression
public boolean getAllowCompression()
Gets whether HTTP requests will indicate to the remote server that compressed encoding of responses is accepted- Returns:
- True if compressed encoding will be accepted
-
cancel
public void cancel()
Cancel query evaluation
-
abort
public void abort()
Description copied from interface:QueryExecutionStop 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:
abortin interfaceQueryExecution
-
close
public void close()
Description copied from interface:QueryExecutionClose the query execution and stop query evaluation as soon as convenient. QueryExecution objects, and aResultSetfromQueryExecution.execSelect(), can not be used once the QueryExecution is closed. Model results fromQueryExecution.execConstruct()andQueryExecution.execDescribe()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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceQueryExecution
-
isClosed
public boolean isClosed()
Description copied from interface:QueryExecutionAnswer whether this QueryExecution object has been closed or not.- Specified by:
isClosedin interfaceQueryExecution- Returns:
- boolean
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setSelectContentType
public void setSelectContentType(java.lang.String contentType)
Sets the Content Type for SELECT queries provided that the format is supported- Parameters:
contentType-
-
setAskContentType
public void setAskContentType(java.lang.String contentType)
Sets the Content Type for ASK queries provided that the format is supported- Parameters:
contentType-
-
setModelContentType
public void setModelContentType(java.lang.String contentType)
Sets the Content Type for CONSTRUCT/DESCRIBE queries provided that the format is supported- Parameters:
contentType-
-
setDatasetContentType
public void setDatasetContentType(java.lang.String contentType)
-
defaultSelectHeader
public static java.lang.String defaultSelectHeader()
-
defaultAskHeader
public static java.lang.String defaultAskHeader()
-
defaultConstructHeader
public static java.lang.String defaultConstructHeader()
-
defaultConstructDatasetHeader
public static java.lang.String defaultConstructDatasetHeader()
-
getAcceptHeader
public java.lang.String getAcceptHeader()
Get the HTTP Accept header for the request.
-
setAcceptHeader
public void setAcceptHeader(java.lang.String acceptHeader)
Set the HTTP Accept header for the request. Unlike theset??ContentTypeoperations, this is not checked for validity.
-
-