org.openanzo.common.rdb.container.query
Class RdbBGPQuery

java.lang.Object
  extended by org.openanzo.common.rdb.container.query.RdbBGPQuery

public class RdbBGPQuery
extends java.lang.Object

RdbBGPQuery creates SQL queries agains the Anzo relational schema from conjoined triple patterns. The entire context of a single RdbBGPQuery instance can be constrainted with a GRAPH clause (with either an IRI reference of a variable.) It does not handle OPTIONAL patterns, UNION patterns, or FILTERs. The algorithms in this class are based on research in: http://www.cs.wayne.edu/~artem/main/research/TR-DB-052006-CLJF.pdf#search=%22sparql%20sql%20optional%20wayne%22 adjusted to the particulars of the Anzo relational schema. Other deviations from Chebotko et al.'s work are documented below.

Author:
lee

Constructor Summary
RdbBGPQuery(RDBConnection container, NodeConverter converter, QueryInformation queryInformation)
          Create a new RdbBGPQuery
 
Method Summary
 void addExtraTriplePattern(TriplePatternComponent s, TriplePatternComponent p, TriplePatternComponent o)
          Add an extra triple patter to this query.
 void addLikeMatch(Variable variable, java.lang.String matchText)
          Add an pattern for the special textLike predicate
 void addOptionalPattern(TriplePattern tp)
          Add an optional triple pattern to this query.
 void addOptionalPatterns(java.util.List<TriplePattern> tps)
          Add an optional triple patterns to this query.
 void addTriplePattern(TriplePattern tp)
          Add a regular triple pattern to this query
 void catalogTriples()
          Once all the triple patterns are added to the query, catalog them, determining things like what variables are need to fulfill optionals, likematches, and create maps between the variables and the patterns that they fulfill.
 java.lang.String getExtraSQL(java.lang.String tempTable, java.util.ArrayList<Bindable> bindableColumns, java.util.ArrayList<Bindable> resultColumns)
          Get the SQL string for this query for the extra triple patterns.
 java.lang.String getSQL(boolean extras, java.lang.String tableName, java.util.ArrayList<Bindable> bindableColumns)
          Get the SQL string for this query.
 void setGraphVariable(Variable variable)
          Set the named graph variable for this query, if there is one
 void setNamedGraph(IRIReference iri)
          Set the specific namedGraph on which this query is running
 void setThisNode(TreeNode node)
          Set the node on which this query is based
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RdbBGPQuery

public RdbBGPQuery(RDBConnection container,
                   NodeConverter converter,
                   QueryInformation queryInformation)
Create a new RdbBGPQuery

Parameters:
container - source of data
converter - converts between Glitter and Anzo types
queryInformation - Glitter queryInformation
Method Detail

setThisNode

public void setThisNode(TreeNode node)
Set the node on which this query is based

Parameters:
node - on which this query is based

setGraphVariable

public void setGraphVariable(Variable variable)
Set the named graph variable for this query, if there is one

Parameters:
variable - the named graph variable for this query

setNamedGraph

public void setNamedGraph(IRIReference iri)
                   throws NoSolutionsException
Set the specific namedGraph on which this query is running

Parameters:
iri - NamedGraph's URI in glitter IRI format
Throws:
NoSolutionsException

catalogTriples

public void catalogTriples()
Once all the triple patterns are added to the query, catalog them, determining things like what variables are need to fulfill optionals, likematches, and create maps between the variables and the patterns that they fulfill.


addTriplePattern

public void addTriplePattern(TriplePattern tp)
Add a regular triple pattern to this query

Parameters:
tp - triple pattern to add

addExtraTriplePattern

public void addExtraTriplePattern(TriplePatternComponent s,
                                  TriplePatternComponent p,
                                  TriplePatternComponent o)
Add an extra triple patter to this query. An "Extra" triple pattern means that this pattern contains only 1 variable. Thus, if there are triple patterns with multiple variables, those patterns are run first, and then these "Extra" patterns are run.

Parameters:
s - Subject value or variable
p - Property value or variable
o - Object value or variable

addOptionalPattern

public void addOptionalPattern(TriplePattern tp)
Add an optional triple pattern to this query. These optional patterns are joined to the results of the regular and extra pattern queries.

Parameters:
tp - triple pattern to add

addOptionalPatterns

public void addOptionalPatterns(java.util.List<TriplePattern> tps)
Add an optional triple patterns to this query. These optional patterns are joined to the results of the regular and extra pattern queries.

Parameters:
tps - triple patterns to add

addLikeMatch

public void addLikeMatch(Variable variable,
                         java.lang.String matchText)
Add an pattern for the special textLike predicate

Parameters:
variable - variable for subject of pattern
matchText - string to match in like query

getSQL

public java.lang.String getSQL(boolean extras,
                               java.lang.String tableName,
                               java.util.ArrayList<Bindable> bindableColumns)
                        throws NoSolutionsException
Get the SQL string for this query. If there are "Extra" triple patterns, the resulting sql string is an insert operation into a temporary table. If not, then this results in a select statement.

Parameters:
extras - true if there are "Extra" triple patterns besides the regular patterns.
tableName - temporary table to place results in, if extra is true
bindableColumns - names of the columns/bindings for the results
Returns:
the SQL string for this query
Throws:
NoSolutionsException

getExtraSQL

public java.lang.String getExtraSQL(java.lang.String tempTable,
                                    java.util.ArrayList<Bindable> bindableColumns,
                                    java.util.ArrayList<Bindable> resultColumns)
                             throws NoSolutionsException
Get the SQL string for this query for the extra triple patterns. This joins the results from the getSQL() statement, if any, and the results from the extra triple patterns. If there are any optional query patterns, outer joins are added to merge those results in as well.

Parameters:
tempTable - temporary table that holds results from getSQL call
bindableColumns - names of the columns/bindings that can are available due to the initial getSQL step
resultColumns - names of the columns/bindings for the results
Returns:
the SQL string for this query
Throws:
NoSolutionsException


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.