com.hp.hpl.jena.query
Class Query

java.lang.Object
  extended by com.hp.hpl.jena.query.Query

public class Query
extends java.lang.Object

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.

Version:
$Id: Query.java,v 1.63 2005/09/28 13:28:30 andy_seaborne Exp $
Author:
Andy Seaborne
See Also:
QueryExecutionFactory, ResultSet

Field Summary
static int ASCENDING
           
static int DESCENDING
           
static long NOLIMIT
           
static int QueryTypeAsk
           
static int QueryTypeConstruct
           
static int QueryTypeDescribe
           
static int QueryTypeSelect
           
static int QueryTypeUnknown
           
 
Constructor Summary
Query()
          Create a blank query.
 
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 addNamedGraphURI(java.lang.String s)
          Location of the source for the data.
 void addOrderBy(com.hp.hpl.jena.query.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 addResultURIs(com.hp.hpl.jena.graph.Node node)
          Add a result for a DESCRIBE query
 void addResultVar(com.hp.hpl.jena.graph.Node v)
           
 void addResultVar(java.lang.String varName)
          Add a projection variable to a SELECT query
 boolean equals(java.lang.Object other)
          Are two queries equals - tests shape and details.
 java.lang.String expandQName(java.lang.String qname)
          Expand QName
 boolean explicitlySetBaseURI()
           
 java.lang.String getBaseURI()
           
 com.hp.hpl.jena.query.core.Template getConstructTemplate()
          Get the template pattern for a construct query
 java.util.List getGraphURIs()
          Return the list of URIs (strings) for the unnamed graph
 long getLimit()
           
 java.util.List getNamedGraphURIs()
          Return the list of URIs (strings) for the named graphs
 long getOffset()
           
 java.util.List getOrderBy()
           
 java.lang.String getPrefix(java.lang.String prefix)
          Lookup a prefix for this query, including the default prefixes
 com.hp.hpl.jena.shared.PrefixMapping getPrefixMap()
          Deprecated. Use getPrefixMapping
 com.hp.hpl.jena.shared.PrefixMapping getPrefixMapping()
          Return the prefix map from the parsed query
 com.hp.hpl.jena.query.core.ElementBlock getQueryBlock()
           
 int getQueryType()
           
 java.util.List getResultURIs()
          Get the result list (things wanted - not the results themselves) of a DESCRIBE query.
 java.util.List getResultVars()
          Return a list of the variables requested (SELECT)
 Syntax getSyntax()
           
 boolean hasDatasetDescription()
          Return true if the query has either some graph URIs or some named graph URIs in its description.
 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 isSelectType()
           
 boolean isStrict()
           
 boolean isUnknownType()
           
 java.lang.String serialize()
           
 void serialize(com.hp.hpl.jena.query.util.IndentedLineBuffer buff)
          Format the query into the buffer
 void serialize(com.hp.hpl.jena.query.util.IndentedLineBuffer buff, Syntax outSyntax)
          Format the query
 void serialize(com.hp.hpl.jena.query.util.IndentedWriter writer)
          Format the query
 void serialize(com.hp.hpl.jena.query.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
 void setBaseURI(java.lang.String baseURI)
           
 void setConstructTemplate(com.hp.hpl.jena.query.core.Template templ)
          Add a triple patterns for a construct query
 void setDistinct(boolean b)
           
 void setLimit(long limit)
           
 void setOffset(long offset)
           
 void setPrefix(java.lang.String prefix, java.lang.String expansion)
          Set a prefix for this query
 void setPrefixMapping(com.hp.hpl.jena.shared.PrefixMapping pmap)
          Set the mapping
 void setQueryBlock(com.hp.hpl.jena.query.core.ElementBlock block)
           
 void setQueryElement(com.hp.hpl.jena.query.core.Element elt)
           
 void setQueryResultStar(boolean isQueryStar)
          Set whether the query had SELECT/DESCRIBE/CONSTRUCT *
 void setQueryType(int qType)
           
 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 shortForm(java.lang.String uri)
          Use the prefix map to turn a URI into a qname, or return the original URI
 java.lang.String toString()
           
 void visit(QueryVisitor visitor)
           
 
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 long NOLIMIT

ASCENDING

public static int ASCENDING

DESCENDING

public static int DESCENDING
Constructor Detail

Query

public Query()
Create a blank query. The application is expected to complete the query parts needed by calling the various "add" operations later,

Method Detail

setQueryType

public void setQueryType(int qType)

getQueryType

public int getQueryType()

setStrict

public void setStrict(boolean isStrict)

isStrict

public boolean isStrict()

setDistinct

public void setDistinct(boolean b)

isDistinct

public boolean isDistinct()

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.query.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 getOrderBy()

isSelectType

public boolean isSelectType()

isConstructType

public boolean isConstructType()

isDescribeType

public boolean isDescribeType()

isAskType

public boolean isAskType()

isUnknownType

public boolean isUnknownType()

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 -

setQueryElement

public void setQueryElement(com.hp.hpl.jena.query.core.Element elt)

setQueryBlock

public void setQueryBlock(com.hp.hpl.jena.query.core.ElementBlock block)

getQueryBlock

public com.hp.hpl.jena.query.core.ElementBlock getQueryBlock()

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 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 as named graphs in the dataset.


getGraphURIs

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

Returns:
List of strings

getNamedGraphURIs

public java.util.List getNamedGraphURIs()
Return the list of URIs (strings) for the named graphs

Returns:
List of strings

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 getResultVars()
Return a list of the variables requested (SELECT)


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)

addDescribeNode

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

getConstructTemplate

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


setConstructTemplate

public void setConstructTemplate(com.hp.hpl.jena.query.core.Template templ)
Add a triple patterns for a construct query


getResultURIs

public java.util.List getResultURIs()
Get the result list (things wanted - not the results themselves) of a DESCRIBE query.


addResultURIs

public void addResultURIs(com.hp.hpl.jena.graph.Node node)
Add a result for a DESCRIBE query


setResultVars

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


explicitlySetBaseURI

public boolean explicitlySetBaseURI()
Returns:
True if the query has an explicitly set base URI.

getBaseURI

public java.lang.String getBaseURI()
Returns:
Returns the baseURI.

setBaseURI

public void setBaseURI(java.lang.String baseURI)
Parameters:
baseURI - The baseURI to set.

setPrefix

public void setPrefix(java.lang.String prefix,
                      java.lang.String expansion)
Set a prefix for this query


getPrefixMap

public com.hp.hpl.jena.shared.PrefixMapping getPrefixMap()
Deprecated. Use getPrefixMapping


getPrefixMapping

public com.hp.hpl.jena.shared.PrefixMapping getPrefixMapping()
Return the prefix map from the parsed query


setPrefixMapping

public void setPrefixMapping(com.hp.hpl.jena.shared.PrefixMapping pmap)
Set the mapping


getPrefix

public java.lang.String getPrefix(java.lang.String prefix)
Lookup a prefix for this query, including the default prefixes


expandQName

public java.lang.String expandQName(java.lang.String qname)
Expand QName

Parameters:
qname - The QName to be expanded
Returns:
URI, or null if not expanded.

shortForm

public java.lang.String shortForm(java.lang.String uri)
Use the prefix map to turn a URI into a qname, or return the original URI


visit

public void visit(QueryVisitor visitor)

toString

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

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()

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.query.util.IndentedLineBuffer buff)
Format the query into the buffer

Parameters:
buff - IndentedLineBuffer

serialize

public void serialize(com.hp.hpl.jena.query.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.query.util.IndentedWriter writer)
Format the query

Parameters:
writer - IndentedWriter

serialize

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

Parameters:
writer - IndentedWriter
outSyntax - Syntax URI


Copyright © 2004, 2005 Hewlett-Packard Development Company, LP