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
FieldsModifier and TypeFieldDescriptionstatic final longstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDescribeNode(org.apache.jena.graph.Node node) voidLocation of the source for the data.voidaddGroupBy(String varName) voidaddGroupBy(org.apache.jena.graph.Node v) voidaddGroupBy(Var v, Expr expr) voidaddGroupBy(Expr expr) voidaddHavingCondition(Expr expr) voidaddJsonMapping(String key, org.apache.jena.graph.Node value) voidaddNamedGraphURI(String uri) Location of the source for the data.voidaddOrderBy(String varName, int direction) voidaddOrderBy(org.apache.jena.graph.Node var, int direction) voidaddOrderBy(SortCondition condition) voidaddOrderBy(Expr expr, int direction) voidaddProjectVars(Collection<?> vars) Add a collection of projection variables to a SELECT queryvoidaddResultVar(String varName) Add a projection variable to a SELECT queryvoidaddResultVar(String varName, Expr expr) Add a named expression to a SELECT queryvoidaddResultVar(org.apache.jena.graph.Node v) voidaddResultVar(org.apache.jena.graph.Node v, Expr expr) voidaddResultVar(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.voidbooleanAre 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 graphlonggetLimit()Return the list of URIs (strings) for the named graphs (FROM NAMED clause)longReturn a list of the variables requested (SELECT)List<org.apache.jena.graph.Node>Get the result list URI 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 blockbooleanbooleanReturn true if the query has either some graph URIs or some named graph URIs in its description.booleanbooleaninthashCode()booleanhasLimit()booleanbooleanbooleanDoes the query have a VALUES trailing block?booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanAnswer whether the query had SELECT/DESCRIBE/CONSTRUCT *booleanbooleanbooleanisStrict()booleanvoidoutput(org.apache.jena.atlas.io.IndentedWriter out) Return theQueryTypevoidIf modifying a query, it may be necessary to reset the calculated result variables of the query forSELECT *andDESCRIBE *andCONSTRUCT.Convert the query to a stringvoidserialize(OutputStream out) Output the queryvoidserialize(OutputStream out, Syntax syntax) Output the queryvoidserialize(org.apache.jena.atlas.io.IndentedWriter writer) Format the queryvoidFormat the queryConvert the query to a string in the given syntaxvoidsetConstructTemplate(Template templ) Set triple patterns for a construct queryvoidsetDistinct(boolean b) voidsetJsonMapping(Map<String, org.apache.jena.graph.Node> newJsonMapping) Overwrite all prior JSON mappings with new ones.voidsetLimit(long limit) voidsetOffset(long offset) voidvoidvoidvoidvoidsetQueryPattern(Element elt) voidsetQueryResultStar(boolean isQueryStar) Set whether the query had SELECT/DESCRIBE *voidvoidsetReduced(boolean b) voidDeprecated, for removal: This API element is subject to removal in a future version.voidsetStrict(boolean isStrict) voidvoidsetValuesDataBlock(List<Var> variables, List<Binding> values) toString()booleanusesGraphURI(String uri) Test whether the query mentions a URI in forming the default graph (FROM clause)booleanusesNamedGraphURI(String uri) Test whether the query mentions a URI for a named graph.voidvisit(QueryVisitor visitor) Methods inherited from class org.apache.jena.sparql.core.Prologue
copy, expandPrefixedName, explicitlySetBaseURI, getBase, getBaseURI, getPrefix, getPrefixMapping, getResolver, getVersion, hash, samePrologue, setBase, setBaseURI, setPrefix, setPrefixMapping, setVersion, 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 -
setResultVars
Deprecated, for removal: This API element is subject to removal in a future version.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. -
ensureResultVars
public void ensureResultVars() -
resetResultVars
public void resetResultVars()If modifying a query, it may be necessary to reset the calculated result variables of the query forSELECT *andDESCRIBE *andCONSTRUCT. -
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
-
setJsonMapping
Overwrite all prior JSON mappings with new ones.- Parameters:
newJsonMapping- The new JSON mappings. Must not be null.
-
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 URI of a DESCRIBE query. -
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:
outputin 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
-
ensureResultVars()