org.openanzo.server.repository.query
Class ServerBGPQuery

java.lang.Object
  extended by org.openanzo.server.repository.query.ServerBGPQuery

public class ServerBGPQuery
extends java.lang.Object

ServerBGPQuery creates SQL queries against the Anzo relational schema from conjoined triple patterns. The entire context of a single ServerBGPQuery instance can be constrained with a GRAPH clause (with either an IRI reference or 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, Matthew Roy ( mroy@cambridgesemantics.com )

Constructor Summary
ServerBGPQuery(RepositoryConnection connection, QueryInformation qi)
          Create a new ServerBGPQuery
 
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
 java.lang.String getExtraSQL(java.lang.String tempTable, java.util.ArrayList<Bindable> bindableColumns, java.util.ArrayList<Bindable> resultColumns, java.lang.Long lastTransactionTime)
          Get the SQL string for this query for the extra triple patterns.
 java.lang.String getOuterJoinString(java.lang.String leftSideSql, java.util.ArrayList<Bindable> leftSelectedColumns, java.util.List<org.openanzo.server.repository.query.ServerBGPQuery.TripleInstance> rightSideTriples, java.util.ArrayList<Bindable> resultColumns, boolean useDefaultDataset, int depth, java.lang.Long lastTransactionTime)
          This returns a new sql string, which does an outer join between a provided sql select statement, and a set of optional triple patterns
 java.lang.String getSQL(boolean extras, java.lang.String tableName, java.util.ArrayList<Bindable> bindableColumns, java.lang.Long lastTransactionTime)
          Get the SQL string for this query.
 void setGraphVariable(Variable variable)
          Set the graph variable for the current node
 void setNamedGraph(IRIReference iri)
          Set the graph URI for the current node
 void setThisNode(TreeNode node)
          Set the TreeNode that this query is processing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerBGPQuery

public ServerBGPQuery(RepositoryConnection connection,
                      QueryInformation qi)
Create a new ServerBGPQuery

Parameters:
connection - connection to database
qi - query
Method Detail

setThisNode

public void setThisNode(TreeNode node)
Set the TreeNode that this query is processing

Parameters:
node - the TreeNode that this query is processing

setGraphVariable

public void setGraphVariable(Variable variable)
Set the graph variable for the current node

Parameters:
variable - the graph variable for the current node

setNamedGraph

public void setNamedGraph(IRIReference iri)
                   throws NoSolutionsException
Set the graph URI for the current node

Parameters:
iri - the graph URI for the current node
Throws:
NoSolutionsException - if the provided named graph URI does not exist in the system

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,
                               java.lang.Long lastTransactionTime)
                        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
lastTransactionTime - timestamp of last transaction to include in queries
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,
                                    java.lang.Long lastTransactionTime)
                             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
lastTransactionTime - timestamp of last transaction to include in queries
Returns:
the SQL string for this query
Throws:
NoSolutionsException

getOuterJoinString

public java.lang.String getOuterJoinString(java.lang.String leftSideSql,
                                           java.util.ArrayList<Bindable> leftSelectedColumns,
                                           java.util.List<org.openanzo.server.repository.query.ServerBGPQuery.TripleInstance> rightSideTriples,
                                           java.util.ArrayList<Bindable> resultColumns,
                                           boolean useDefaultDataset,
                                           int depth,
                                           java.lang.Long lastTransactionTime)
                                    throws NoSolutionsException
This returns a new sql string, which does an outer join between a provided sql select statement, and a set of optional triple patterns

Parameters:
leftSideSql - sql select statement text which makes up left side of join,
leftSelectedColumns - columns that are to be returned from the left side of the join
rightSideTriples - triple patterns that make up the optional
resultColumns - columns that are to be returned from the right side of the join
useDefaultDataset - does this query go against the defaultDataset
depth - how many nested outerJoins are we currently at
lastTransactionTime - timestamp of last transaction to include in queries
Returns:
new SQL string containing the join
Throws:
NoSolutionsException


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