com.hp.hpl.jena.query
Class Query

java.lang.Object
  extended by com.hp.hpl.jena.sparql.core.Prologue
      extended by com.hp.hpl.jena.query.Query
All Implemented Interfaces:
java.lang.Cloneable

public class Query
extends com.hp.hpl.jena.sparql.core.Prologue
implements java.lang.Cloneable

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 quyery 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.

Author:
Andy Seaborne
See Also:
QueryExecutionFactory, ResultSet

Field Summary
static long NOLIMIT
           
static int ORDER_ASCENDING
           
static int ORDER_DEFAULT
           
static int ORDER_DESCENDING
           
static int ORDER_UNKNOW
           
static int QueryTypeAsk
           
static int QueryTypeConstruct
           
static int QueryTypeDescribe
           
static int QueryTypeSelect
           
static int QueryTypeUnknown
           
 
Constructor Summary
Query()
           
Query(com.hp.hpl.jena.sparql.core.Prologue prologue)
           
 
Method Summary
 void addDescribeNode(com.hp.hpl.jena.graph.Node node)
           
 void addGraphURI(java.lang.String s)
          Location of the source for the data.
 void addGroupBy(com.hp.hpl.jena.sparql.expr.Expr expr)
           
 void addGroupBy(com.hp.hpl.jena.graph.Node v)
           
 void addGroupBy(java.lang.String varName)
           
 void addGroupBy(com.hp.hpl.jena.sparql.core.Var v, com.hp.hpl.jena.sparql.expr.Expr expr)
           
 void addHavingCondition(com.hp.hpl.jena.sparql.expr.Expr expr)
           
 void addNamedGraphURI(java.lang.String uri)
          Location of the source for the data.
 void addOrderBy(com.hp.hpl.jena.sparql.expr.Expr expr, int direction)
           
 void addOrderBy(com.hp.hpl.jena.graph.Node var, int direction)
           
 void addOrderBy(SortCondition condition)
           
 void addOrderBy(java.lang.String varName, int direction)
           
 void addProjectVars(java.util.Collection<?> vars)
          Add a collection of projection variables to a SELECT query
 void addResultVar(com.hp.hpl.jena.sparql.expr.Expr expr)
          Add an to a SELECT query (a name will be created for it)
 void addResultVar(com.hp.hpl.jena.graph.Node v)
           
 void addResultVar(com.hp.hpl.jena.graph.Node v, com.hp.hpl.jena.sparql.expr.Expr expr)
           
 void addResultVar(java.lang.String varName)
          Add a projection variable to a SELECT query
 void addResultVar(java.lang.String varName, com.hp.hpl.jena.sparql.expr.Expr expr)
          Add a named expression to a SELECT query
 com.hp.hpl.jena.sparql.expr.E_Aggregator allocAggregate(com.hp.hpl.jena.sparql.expr.aggregate.AggregateFactory agg)
           
 java.lang.Object clone()
           
 Query cloneQuery()
           
 boolean equals(java.lang.Object other)
          Are two queries equals - tests shape and details.
 java.util.List<com.hp.hpl.jena.sparql.expr.E_Aggregator> getAggregators()
           
 com.hp.hpl.jena.sparql.syntax.Template getConstructTemplate()
          Get the template pattern for a construct query
 java.util.List<java.lang.String> getGraphURIs()
          Return the list of URIs (strings) for the unnamed graph
 com.hp.hpl.jena.sparql.core.VarExprList getGroupBy()
           
 java.util.List<com.hp.hpl.jena.sparql.expr.Expr> getHavingExprs()
           
 long getLimit()
           
 java.util.List<java.lang.String> getNamedGraphURIs()
          Return the list of URIs (strings) for the named graphs (FROM NAMED clause)
 long getOffset()
           
 java.util.List<SortCondition> getOrderBy()
           
 com.hp.hpl.jena.sparql.core.VarExprList getProject()
           
 com.hp.hpl.jena.sparql.syntax.Element getQueryPattern()
           
 int getQueryType()
           
 java.util.List<com.hp.hpl.jena.graph.Node> getResultURIs()
          Get the result list (things wanted - not the results themselves) of a DESCRIBE query.
 java.util.List<java.lang.String> getResultVars()
          Return a list of the variables requested (SELECT)
 Syntax getSyntax()
           
 boolean hasAggregators()
           
 boolean hasDatasetDescription()
          Return true if the query has either some graph URIs or some named graph URIs in its description.
 boolean hasGroupBy()
           
 boolean hasHaving()
           
 int hashCode()
           
 boolean hasLimit()
           
 boolean hasOffset()
           
 boolean hasOrderBy()
           
 boolean isAskType()
           
 boolean isConstructType()
           
 boolean isDescribeType()
           
 boolean isDistinct()
           
 boolean isQueryResultStar()
          Answer whether the query had SELECT/DESCRIBE/CONSTRUCT *
 boolean isReduced()
           
 boolean isSelectType()
           
 boolean isStrict()
           
 boolean isUnknownType()
           
 java.lang.String serialize()
          Convert the query to a string
 void serialize(com.hp.hpl.jena.sparql.util.IndentedLineBuffer buff)
          Format the query into the buffer
 void serialize(com.hp.hpl.jena.sparql.util.IndentedLineBuffer buff, Syntax outSyntax)
          Format the query
 void serialize(com.hp.hpl.jena.sparql.util.IndentedWriter writer)
          Format the query
 void serialize(com.hp.hpl.jena.sparql.util.IndentedWriter writer, Syntax outSyntax)
          Format the query
 void serialize(java.io.OutputStream out)
          Output the query
 void serialize(java.io.OutputStream out, Syntax syntax)
          Output the query
 java.lang.String serialize(Syntax syntax)
          Convert the query to a string in the given syntax
 void setConstructTemplate(com.hp.hpl.jena.sparql.syntax.Template templ)
          Set triple patterns for a construct query
 void setDistinct(boolean b)
           
 void setLimit(long limit)
           
 void setOffset(long offset)
           
 void setQueryAskType()
           
 void setQueryConstructType()
           
 void setQueryDescribeType()
           
 void setQueryPattern(com.hp.hpl.jena.sparql.syntax.Element elt)
           
 void setQueryResultStar(boolean isQueryStar)
          Set whether the query had SELECT/DESCRIBE/CONSTRUCT *
 void setQuerySelectType()
           
 void setQueryType(int qType)
           
 void setReduced(boolean b)
           
 void setResultVars()
          Fix up when the query has "*" (when SELECT * or DESCRIBE *) and for a construct query.
 void setStrict(boolean isStrict)
           
 void setSyntax(Syntax syntax)
           
 java.lang.String toString()
           
 java.lang.String toString(Syntax syntax)
           
 boolean usesGraphURI(java.lang.String uri)
          Test whether the query mentions a URI in forming the default graph (FROM clause)
 boolean usesNamedGraphURI(java.lang.String uri)
          Test whether the query mentions a URI for a named graph.
 void validate()
          Perform some check on the query
 void visit(QueryVisitor visitor)
           
 
Methods inherited from class com.hp.hpl.jena.sparql.core.Prologue
copy, expandPrefixedName, explicitlySetBaseURI, getBaseURI, getPrefix, getPrefixMapping, getResolver, setBaseURI, setBaseURI, setPrefix, setPrefixMapping, setResolver, shortForm, sub, sub, sub, usePrologueFrom
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

QueryTypeUnknown

public static final int QueryTypeUnknown
See Also:
Constant Field Values

QueryTypeSelect

public static final int QueryTypeSelect
See Also:
Constant Field Values

QueryTypeConstruct

public static final int QueryTypeConstruct
See Also:
Constant Field Values

QueryTypeDescribe

public static final int QueryTypeDescribe
See Also:
Constant Field Values

QueryTypeAsk

public static final int QueryTypeAsk
See Also:
Constant Field Values

NOLIMIT

public static final long NOLIMIT
See Also:
Constant Field Values

ORDER_ASCENDING

public static final int ORDER_ASCENDING
See Also:
Constant Field Values

ORDER_DESCENDING

public static final int ORDER_DESCENDING
See Also:
Constant Field Values

ORDER_DEFAULT

public static final int ORDER_DEFAULT
See Also:
Constant Field Values

ORDER_UNKNOW

public static final int ORDER_UNKNOW
See Also:
Constant Field Values
Constructor Detail

Query

public Query()

Query

public Query(com.hp.hpl.jena.sparql.core.Prologue prologue)
Method Detail

setQueryType

public void setQueryType(int qType)

setQuerySelectType

public void setQuerySelectType()

setQueryConstructType

public void setQueryConstructType()

setQueryDescribeType

public void setQueryDescribeType()

setQueryAskType

public void setQueryAskType()

getQueryType

public int getQueryType()

isSelectType

public boolean isSelectType()

isConstructType

public boolean isConstructType()

isDescribeType

public boolean isDescribeType()

isAskType

public boolean isAskType()

isUnknownType

public boolean isUnknownType()

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

public Syntax getSyntax()
Returns:
Returns the syntax.

setSyntax

public void setSyntax(Syntax syntax)
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()

addOrderBy

public void addOrderBy(SortCondition condition)

addOrderBy

public void addOrderBy(com.hp.hpl.jena.sparql.expr.Expr expr,
                       int direction)

addOrderBy

public void addOrderBy(com.hp.hpl.jena.graph.Node var,
                       int direction)

addOrderBy

public void addOrderBy(java.lang.String varName,
                       int direction)

getOrderBy

public java.util.List<SortCondition> 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/CONSTRUCT *

Parameters:
isQueryStar -

setQueryPattern

public void setQueryPattern(com.hp.hpl.jena.sparql.syntax.Element elt)

getQueryPattern

public com.hp.hpl.jena.sparql.syntax.Element getQueryPattern()

addGraphURI

public void addGraphURI(java.lang.String s)
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 (unamed) graph.


addNamedGraphURI

public void addNamedGraphURI(java.lang.String uri)
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

public java.util.List<java.lang.String> getGraphURIs()
Return the list of URIs (strings) for the unnamed graph

Returns:
List of strings

usesGraphURI

public boolean usesGraphURI(java.lang.String uri)
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

public java.util.List<java.lang.String> getNamedGraphURIs()
Return the list of URIs (strings) for the named graphs (FROM NAMED clause)

Returns:
List of strings

usesNamedGraphURI

public boolean usesNamedGraphURI(java.lang.String uri)
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.


getResultVars

public java.util.List<java.lang.String> getResultVars()
Return a list of the variables requested (SELECT)


getProject

public com.hp.hpl.jena.sparql.core.VarExprList getProject()

addProjectVars

public void addProjectVars(java.util.Collection<?> vars)
Add a collection of projection variables to a SELECT query


addResultVar

public void addResultVar(java.lang.String varName)
Add a projection variable to a SELECT query


addResultVar

public void addResultVar(com.hp.hpl.jena.graph.Node v)

addResultVar

public void addResultVar(com.hp.hpl.jena.graph.Node v,
                         com.hp.hpl.jena.sparql.expr.Expr expr)

addResultVar

public void addResultVar(com.hp.hpl.jena.sparql.expr.Expr expr)
Add an to a SELECT query (a name will be created for it)


addResultVar

public void addResultVar(java.lang.String varName,
                         com.hp.hpl.jena.sparql.expr.Expr expr)
Add a named expression to a SELECT query


hasGroupBy

public boolean hasGroupBy()

hasHaving

public boolean hasHaving()

getGroupBy

public com.hp.hpl.jena.sparql.core.VarExprList getGroupBy()

getHavingExprs

public java.util.List<com.hp.hpl.jena.sparql.expr.Expr> getHavingExprs()

addGroupBy

public void addGroupBy(java.lang.String varName)

addGroupBy

public void addGroupBy(com.hp.hpl.jena.graph.Node v)

addGroupBy

public void addGroupBy(com.hp.hpl.jena.sparql.expr.Expr expr)

addGroupBy

public void addGroupBy(com.hp.hpl.jena.sparql.core.Var v,
                       com.hp.hpl.jena.sparql.expr.Expr expr)

addHavingCondition

public void addHavingCondition(com.hp.hpl.jena.sparql.expr.Expr expr)

hasAggregators

public boolean hasAggregators()

getAggregators

public java.util.List<com.hp.hpl.jena.sparql.expr.E_Aggregator> getAggregators()

allocAggregate

public com.hp.hpl.jena.sparql.expr.E_Aggregator allocAggregate(com.hp.hpl.jena.sparql.expr.aggregate.AggregateFactory agg)

getConstructTemplate

public com.hp.hpl.jena.sparql.syntax.Template getConstructTemplate()
Get the template pattern for a construct query


setConstructTemplate

public void setConstructTemplate(com.hp.hpl.jena.sparql.syntax.Template templ)
Set triple patterns for a construct query


addDescribeNode

public void addDescribeNode(com.hp.hpl.jena.graph.Node node)

getResultURIs

public java.util.List<com.hp.hpl.jena.graph.Node> getResultURIs()
Get the result list (things wanted - not the results themselves) of a DESCRIBE query.


setResultVars

public void setResultVars()
Fix up when the query has "*" (when SELECT * or DESCRIBE *) and for a construct query. This operation is idempotent.


visit

public void visit(QueryVisitor visitor)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

cloneQuery

public Query cloneQuery()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(Syntax syntax)

validate

public void validate()
Perform some check on the query


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
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 that a query is different. Two instances of a query parsed from the same string are equal.

Overrides:
equals in class java.lang.Object

serialize

public java.lang.String serialize()
Convert the query to a string


serialize

public java.lang.String serialize(Syntax syntax)
Convert the query to a string in the given syntax

Parameters:
syntax -

serialize

public void serialize(java.io.OutputStream out)
Output the query

Parameters:
out - OutputStream

serialize

public void serialize(java.io.OutputStream out,
                      Syntax syntax)
Output the query

Parameters:
out - OutputStream
syntax - Syntax URI

serialize

public void serialize(com.hp.hpl.jena.sparql.util.IndentedLineBuffer buff)
Format the query into the buffer

Parameters:
buff - IndentedLineBuffer

serialize

public void serialize(com.hp.hpl.jena.sparql.util.IndentedLineBuffer buff,
                      Syntax outSyntax)
Format the query

Parameters:
buff - IndentedLineBuffer in which to place the unparsed query
outSyntax - Syntax URI

serialize

public void serialize(com.hp.hpl.jena.sparql.util.IndentedWriter writer)
Format the query

Parameters:
writer - IndentedWriter

serialize

public void serialize(com.hp.hpl.jena.sparql.util.IndentedWriter writer,
                      Syntax outSyntax)
Format the query

Parameters:
writer - IndentedWriter
outSyntax - Syntax URI


Copyright © 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP