java.lang.Object
org.apache.jena.sparql.core.Prologue
org.apache.jena.query.Query
- All Implemented Interfaces:
Cloneable
,org.apache.jena.atlas.io.Printable
The data structure for a query as presented externally.
There are two ways of creating a query - use the parser to turn
a string description of the query into the executable form, and
the programmatic way (the parser is calling the programmatic
operations driven by the query string). The declarative approach
of passing in a string is preferred.
Once a query is built, it can be passed to the QueryFactory to produce a query execution engine.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDescribeNode
(org.apache.jena.graph.Node node) void
Location of the source for the data.void
addGroupBy
(String varName) void
addGroupBy
(org.apache.jena.graph.Node v) void
addGroupBy
(Var v, Expr expr) void
addGroupBy
(Expr expr) void
addHavingCondition
(Expr expr) void
addJsonMapping
(String key, org.apache.jena.graph.Node value) void
addNamedGraphURI
(String uri) Location of the source for the data.void
addOrderBy
(String varName, int direction) void
addOrderBy
(org.apache.jena.graph.Node var, int direction) void
addOrderBy
(SortCondition condition) void
addOrderBy
(Expr expr, int direction) void
addProjectVars
(Collection<?> vars) Add a collection of projection variables to a SELECT queryvoid
addResultVar
(String varName) Add a projection variable to a SELECT queryvoid
addResultVar
(String varName, Expr expr) Add a named expression to a SELECT queryvoid
addResultVar
(org.apache.jena.graph.Node v) void
addResultVar
(org.apache.jena.graph.Node v, Expr expr) void
addResultVar
(Expr expr) Add an to a SELECT query (a name will be created for it)allocAggregate
(Aggregator agg) clone()
Makes a copy of this query using the syntax transform machinery.boolean
Are two queries equals - tests shape and details.Get the template pattern for a construct queryReturn a dataset description (FROM/FROM NAMED clauses) for the query.Return the list of URIs (strings) for the unnamed graphlong
getLimit()
Return the list of URIs (strings) for the named graphs (FROM NAMED clause)long
Return a list of the variables requested (SELECT)List<org.apache.jena.graph.Node>
Get the result list (things wanted - not the results themselves) of a DESCRIBE query.Return a list of the variables requested (SELECT)Data from a VALUES trailing block. null for a Node means undefVariables from a VALUES trailing blockboolean
boolean
Return true if the query has either some graph URIs or some named graph URIs in its description.boolean
boolean
int
hashCode()
boolean
hasLimit()
boolean
boolean
boolean
Does the query have a VALUES trailing block?boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
Answer whether the query had SELECT/DESCRIBE/CONSTRUCT *boolean
boolean
boolean
isStrict()
boolean
void
output
(org.apache.jena.atlas.io.IndentedWriter out) Return theQueryType
void
If modifying a query, it may be necessary to reset the calculate of the result variables of the query forSELECT *
andDESCRIBE *
andCONSTRUCT
.Convert the query to a stringvoid
serialize
(OutputStream out) Output the queryvoid
serialize
(OutputStream out, Syntax syntax) Output the queryvoid
serialize
(org.apache.jena.atlas.io.IndentedWriter writer) Format the queryvoid
Format the queryConvert the query to a string in the given syntaxvoid
setConstructTemplate
(Template templ) Set triple patterns for a construct queryvoid
setDistinct
(boolean b) void
setLimit
(long limit) void
setOffset
(long offset) void
void
void
void
void
setQueryPattern
(Element elt) void
setQueryResultStar
(boolean isQueryStar) Set whether the query had SELECT/DESCRIBE *void
void
setReduced
(boolean b) void
Set the results variables if necessary, when the query has "*" (SELECT *
orDESCRIBE *
) and for a construct query.void
setStrict
(boolean isStrict) void
void
setValuesDataBlock
(List<Var> variables, List<Binding> values) toString()
boolean
usesGraphURI
(String uri) Test whether the query mentions a URI in forming the default graph (FROM clause)boolean
usesNamedGraphURI
(String uri) Test whether the query mentions a URI for a named graph.void
visit
(QueryVisitor visitor) Methods inherited from class org.apache.jena.sparql.core.Prologue
copy, expandPrefixedName, explicitlySetBaseURI, getBase, getBaseURI, getPrefix, getPrefixMapping, getResolver, hash, samePrologue, setBase, setBaseURI, setPrefix, setPrefixMapping, shortForm
-
Field Details
-
QueryTypeUnknown
public static final int QueryTypeUnknown- See Also:
-
QueryTypeSelect
public static final int QueryTypeSelect- See Also:
-
QueryTypeConstruct
public static final int QueryTypeConstruct- See Also:
-
QueryTypeDescribe
public static final int QueryTypeDescribe- See Also:
-
QueryTypeAsk
public static final int QueryTypeAsk- See Also:
-
QueryTypeJson
public static final int QueryTypeJson- See Also:
-
NOLIMIT
public static final long NOLIMIT- See Also:
-
ORDER_ASCENDING
public static final int ORDER_ASCENDING- See Also:
-
ORDER_DESCENDING
public static final int ORDER_DESCENDING- See Also:
-
ORDER_DEFAULT
public static final int ORDER_DEFAULT- See Also:
-
ORDER_UNKNOW
public static final int ORDER_UNKNOW- See Also:
-
-
Constructor Details
-
Query
public Query()Creates a new empty query -
Query
Creates a new empty query with the given prologue
-
-
Method Details
-
setQuerySelectType
public void setQuerySelectType() -
setQueryConstructType
public void setQueryConstructType() -
setQueryDescribeType
public void setQueryDescribeType() -
setQueryAskType
public void setQueryAskType() -
setQueryJsonType
public void setQueryJsonType() -
queryType
Return theQueryType
-
isSelectType
public boolean isSelectType() -
isConstructType
public boolean isConstructType() -
isDescribeType
public boolean isDescribeType() -
isAskType
public boolean isAskType() -
isJsonType
public boolean isJsonType() -
isUnknownType
public boolean isUnknownType() -
isConstructQuad
public boolean isConstructQuad() -
getPrologue
-
setStrict
public void setStrict(boolean isStrict) -
isStrict
public boolean isStrict() -
setDistinct
public void setDistinct(boolean b) -
isDistinct
public boolean isDistinct() -
setReduced
public void setReduced(boolean b) -
isReduced
public boolean isReduced() -
getSyntax
- Returns:
- Returns the syntax.
-
setSyntax
- Parameters:
syntax
- The syntax to set.
-
getLimit
public long getLimit() -
setLimit
public void setLimit(long limit) -
hasLimit
public boolean hasLimit() -
getOffset
public long getOffset() -
setOffset
public void setOffset(long offset) -
hasOffset
public boolean hasOffset() -
hasOrderBy
public boolean hasOrderBy() -
isOrdered
public boolean isOrdered() -
addOrderBy
-
addOrderBy
-
addOrderBy
public void addOrderBy(org.apache.jena.graph.Node var, int direction) -
addOrderBy
-
getOrderBy
-
isQueryResultStar
public boolean isQueryResultStar()Answer whether the query had SELECT/DESCRIBE/CONSTRUCT *- Returns:
- boolean as to whether a * result form was seen
-
setQueryResultStar
public void setQueryResultStar(boolean isQueryStar) Set whether the query had SELECT/DESCRIBE *- Parameters:
isQueryStar
-
-
setQueryPattern
-
getQueryPattern
-
addGraphURI
Location of the source for the data. If the model is not set, then the QueryEngine will attempt to load the data from these URIs into the default (unnamed) graph. -
addNamedGraphURI
Location of the source for the data. If the model is not set, then the QueryEngine will attempt to load the data from these URIs as named graphs in the dataset. -
getGraphURIs
Return the list of URIs (strings) for the unnamed graph- Returns:
- List of strings
-
usesGraphURI
Test whether the query mentions a URI in forming the default graph (FROM clause)- Parameters:
uri
-- Returns:
- boolean True if the URI used in a FROM clause
-
getNamedGraphURIs
Return the list of URIs (strings) for the named graphs (FROM NAMED clause)- Returns:
- List of strings
-
usesNamedGraphURI
Test whether the query mentions a URI for a named graph.- Parameters:
uri
-- Returns:
- True if the URI used in a FROM NAMED clause
-
hasDatasetDescription
public boolean hasDatasetDescription()Return true if the query has either some graph URIs or some named graph URIs in its description. This does not mean these URIs will be used - just that they are noted as part of the query. -
getDatasetDescription
Return a dataset description (FROM/FROM NAMED clauses) for the query. -
getResultVars
Return a list of the variables requested (SELECT) -
getProjectVars
Return a list of the variables requested (SELECT) -
getProject
-
addProjectVars
Add a collection of projection variables to a SELECT query -
addResultVar
Add a projection variable to a SELECT query -
addResultVar
public void addResultVar(org.apache.jena.graph.Node v) -
addResultVar
-
addResultVar
Add an to a SELECT query (a name will be created for it) -
addResultVar
Add a named expression to a SELECT query -
hasGroupBy
public boolean hasGroupBy() -
hasHaving
public boolean hasHaving() -
getGroupBy
-
getHavingExprs
-
addGroupBy
-
addGroupBy
public void addGroupBy(org.apache.jena.graph.Node v) -
addGroupBy
-
addGroupBy
-
addHavingCondition
-
addJsonMapping
-
getJsonMapping
-
hasAggregators
public boolean hasAggregators() -
getAggregators
-
allocAggregate
-
hasValues
public boolean hasValues()Does the query have a VALUES trailing block? -
getValuesVariables
Variables from a VALUES trailing block -
getValuesData
Data from a VALUES trailing block. null for a Node means undef -
setValuesDataBlock
-
getConstructTemplate
Get the template pattern for a construct query -
setConstructTemplate
Set triple patterns for a construct query -
addDescribeNode
public void addDescribeNode(org.apache.jena.graph.Node node) -
getResultURIs
Get the result list (things wanted - not the results themselves) of a DESCRIBE query. -
setResultVars
public void setResultVars()Set the results variables if necessary, when the query has "*" (SELECT *
orDESCRIBE *
) and for a construct query. This operation is idempotent and can be called to ensure the results variables have been set. -
resetResultVars
public void resetResultVars()If modifying a query, it may be necessary to reset the calculate of the result variables of the query forSELECT *
andDESCRIBE *
andCONSTRUCT
. -
visit
-
clone
-
cloneQuery
Makes a copy of this query using the syntax transform machinery.- Returns:
- Copy of this query
-
toString
-
toString
-
hashCode
public int hashCode() -
equals
Are two queries equals - tests shape and details. Equality means that the queries do the same thing, including same variables, in the same places. Being unequals does not mean the queries do different things. For example, reordering a group or union means that a query is different. Two instances of a query parsed from the same string are equal. -
output
public void output(org.apache.jena.atlas.io.IndentedWriter out) - Specified by:
output
in interfaceorg.apache.jena.atlas.io.Printable
-
serialize
Convert the query to a string -
serialize
Convert the query to a string in the given syntax- Parameters:
syntax
-
-
serialize
Output the query- Parameters:
out
- OutputStream
-
serialize
Output the query- Parameters:
out
- OutputStreamsyntax
- Syntax URI
-
serialize
public void serialize(org.apache.jena.atlas.io.IndentedWriter writer) Format the query- Parameters:
writer
- IndentedWriter
-
serialize
Format the query- Parameters:
writer
- IndentedWriteroutSyntax
- Syntax URI
-