public final class SelectQuery extends Object implements Serializable
This class models the specification of a SPARQL SELECT query, combining in a single object both
its query string representation (property getString()
) and its Sesame algebraic
representation (properties getExpression()
, getDataset()
).
A SelectQuery can be created either providing its string representation (method
from(String)
) or its algebraic expression together with the query dataset (method
from(TupleExpr, Dataset)
). In both case, the dual representation is automatically
derived, either via parsing or rendering to SPARQL language. The two from factory
methods provide for the caching and reuse of already created objects, thus reducing parsing
overhead. A MalformedQueryException
is thrown in case the supplied representation
(either the query string or the algebraic expression) does not denote a valid SPARQL SELECT
query.
Serialization is supported, with deserialization attempting to reuse existing objects from the cache. Note that only the string representation is serialized, with the algebraic expression obtained at deserialization time via parsing.
Instances have to considered to be immutable: while it is not possible to (efficiently) forbid
modifying the query tuple expression (getExpression()
), THE ALGEBRAIC EXPRESSION MUST
NOT BE MODIFIED, as this will interfere with caching.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Two instances are equal if they have the same string representation.
|
static SelectQuery |
from(String string)
Returns a SelectQuery for the specified SPARQL SELECT query string.
|
static SelectQuery |
from(org.openrdf.query.algebra.TupleExpr expression,
org.openrdf.query.Dataset dataset)
Returns an SelectQuery for the algebraic expression and optional dataset
specified.
|
org.openrdf.query.Dataset |
getDataset()
Returns the dataset expressed by the FROM and FROM NAMED clauses of the query, or
null if there are no such clauses.
|
org.openrdf.query.algebra.TupleExpr |
getExpression()
Returns the algebraic expression for the query - DON'T MODIFY THE RESULT.
|
String |
getString()
Returns the query string.
|
int |
hashCode()
The returned hash code depends only on the string representation.
|
SelectQuery |
replaceDataset(org.openrdf.query.Dataset dataset)
Replaces the dataset of this query with the one specified, returning the resulting
SelectQuery object.
|
SelectQuery |
replaceVariables(org.openrdf.query.BindingSet bindings)
Replaces some variables of this queries with the constant values specified, returning the
resulting SelectQuery object.
|
String |
toString()
Returns the query string.
|
public static SelectQuery from(String string) throws ParseException
string
- the query string, in SPARQL and without relative URIsParseException
- in case the string does not denote a valid SPARQL SELECT querypublic static SelectQuery from(org.openrdf.query.algebra.TupleExpr expression, @Nullable org.openrdf.query.Dataset dataset) throws ParseException
expression
- the algebraic expression for the querydataset
- the dataset optionally associated to the queryParseException
- in case the supplied algebraic expression does not denote a valid SPARQL SELECT
querypublic String getString()
public org.openrdf.query.algebra.TupleExpr getExpression()
@Nullable public org.openrdf.query.Dataset getDataset()
public SelectQuery replaceDataset(@Nullable org.openrdf.query.Dataset dataset)
dataset
- the new dataset; as usual, null denotes the default dataset (all the
graphs)public SelectQuery replaceVariables(org.openrdf.query.BindingSet bindings)
bindings
- the bindings to applypublic boolean equals(Object object)
public int hashCode()
Copyright © 2015–2016 FBK-irst. All rights reserved.