com.hp.hpl.jena.rdql
Class Query

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

public class Query
extends java.lang.Object

The data structure for a query. 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 a query engine.

Version:
$Id: Query.java,v 1.20 2005/07/13 10:06:27 chris-dollin Exp $
Author:
Andy Seaborne
See Also:
QueryEngine, QueryResults

Field Summary
 long buildTime
           
 long executeTime
           
 long loadTime
           
 long parseTime
           
 
Constructor Summary
Query()
          Create a blank query.
Query(java.lang.String s)
          Create a query from the given string by calling the parser.
 
Method Summary
 void addBoundVar(java.lang.String varName)
          Programmatic API operation: declare a variable used by the query
 void addConstraint(Constraint c)
          Programmatic API operation: add a constraint
 void addResultVar(java.lang.String varName)
          Programmatic API operation: add a SELECT variable
 void addTriplePattern(Node s, Node p, Node o)
           
 void addTriplePattern(Triple t)
          Programmatic API operation
static QueryResults exec(java.lang.String queryString)
          Convenience function to parse and execute a query.
static QueryResults exec(java.lang.String queryString, Model model)
          Convenience function to parse and execute a query against an existing model.
static QueryResults exec(java.lang.String queryString, java.lang.String dataURL)
          Convenience function to parse and execute a query against a remote model.
 java.util.List getBoundVars()
          Programmatic API operation: get all the variabes used by this query
 java.util.List getConstraints()
          Programmatic API operation: get all the constraints
 java.util.Map getDefaultPrefixMap()
          Return the default prefix map
 java.lang.String getPrefix(java.lang.String prefix)
          Lookup a prefix for this query, including the default prefixes
 java.util.Map getPrefixMap()
          Return the prefix map fro the parsed query
 java.util.List getResultVars()
          Programmatic API operation: return the SELECT variables.
 Model getSource()
          Return the model that this query executes against.
 java.lang.String getSourceURL()
           
 java.util.List getTriplePatterns()
          Programmatic API operation: get the query graph pattern
 void setPrefix(java.lang.String prefix, java.lang.String expansion)
          Set a prefix for this query
 void setSource(Model m)
          The data target for the query as a Jena model.
 void setSourceURL(java.lang.String s)
          Location of the source for the data.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parseTime

public long parseTime

buildTime

public long buildTime

loadTime

public long loadTime

executeTime

public long executeTime
Constructor Detail

Query

public Query(java.lang.String s)
Create a query from the given string by calling the parser. After it has been created, an application should set the data source, then call the QueryEngine.

Parameters:
s - The query string
Throws:
QueryException - Thrown when a parse error occurs

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

exec

public static QueryResults exec(java.lang.String queryString)
Convenience function to parse and execute a query.

Parameters:
queryString - The query: should include FROM clause to provide the data
Throws:
QueryException - Runtime exception

exec

public static QueryResults exec(java.lang.String queryString,
                                Model model)
Convenience function to parse and execute a query against an existing model.

Parameters:
queryString - The query: the FROM clause will be overridden
model - The data
Throws:
QueryException - Runtime exception

exec

public static QueryResults exec(java.lang.String queryString,
                                java.lang.String dataURL)
Convenience function to parse and execute a query against a remote model. The remote data is loaded into the local application.

Parameters:
queryString - The query: the FROM clause will be overridden
dataURL - The remote data source
Throws:
QueryException - Runtime exception

setSource

public void setSource(Model m)
The data target for the query as a Jena model. Applications must call this whther using the parser or not.


getSource

public Model getSource()
Return the model that this query executes against.


setSourceURL

public void setSourceURL(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 this URL.


getSourceURL

public java.lang.String getSourceURL()

getResultVars

public java.util.List getResultVars()
Programmatic API operation: return the SELECT variables.


addResultVar

public void addResultVar(java.lang.String varName)
Programmatic API operation: add a SELECT variable


getBoundVars

public java.util.List getBoundVars()
Programmatic API operation: get all the variabes used by this query


addBoundVar

public void addBoundVar(java.lang.String varName)
Programmatic API operation: declare a variable used by the query


addConstraint

public void addConstraint(Constraint c)
Programmatic API operation: add a constraint


getConstraints

public java.util.List getConstraints()
Programmatic API operation: get all the constraints


addTriplePattern

public void addTriplePattern(Triple t)
Programmatic API operation


addTriplePattern

public void addTriplePattern(Node s,
                             Node p,
                             Node o)

getTriplePatterns

public java.util.List getTriplePatterns()
Programmatic API operation: get the query graph pattern


setPrefix

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


getPrefix

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


getPrefixMap

public java.util.Map getPrefixMap()
Return the prefix map fro the parsed query


getDefaultPrefixMap

public java.util.Map getDefaultPrefixMap()
Return the default prefix map


toString

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


Copyright © 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP