org.d2rq.db
Class SelectStatementBuilder

java.lang.Object
  extended by org.d2rq.db.op.OpVisitor.Default
      extended by org.d2rq.db.SelectStatementBuilder
All Implemented Interfaces:
OpVisitor

public class SelectStatementBuilder
extends OpVisitor.Default

Turns a DatabaseOp into a SQL SELECT statement. Works by doing a depth-first traversal of the query tree, collecting information in a SimpleQuery object. Such an object can contain a non-nested SQL query. Once nesting is necessary, the current SimpleQuery is put on a stack, a new one is allocated and information collected in it, and then it is "flattened" by turning it into a raw SQL string that becomes a FROM clause in the upper instance. The list of SELECT clauses is not built while working the tree, but computed in the end from the DatabaseOp's column list.

Author:
Richard Cyganiak (richard@cyganiak.de)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.d2rq.db.op.OpVisitor
OpVisitor.Default
 
Constructor Summary
SelectStatementBuilder(DatabaseOp input, Vendor vendor)
           
 
Method Summary
 List<ProjectionSpec> getColumnSpecs()
           
 String getSQL()
           
 void visit(SQLOp table)
           
 void visit(TableOp table)
           
 boolean visitEnter(AliasOp table)
           
 void visitLeave(AliasOp table)
           
 void visitLeave(DistinctOp table)
           
 void visitLeave(EmptyOp table)
           
 void visitLeave(InnerJoinOp table)
           
 void visitLeave(LimitOp table)
           
 void visitLeave(OrderOp table)
           
 void visitLeave(ProjectOp table)
           
 void visitLeave(SelectOp table)
           
 void visitOpTrue()
           
 
Methods inherited from class org.d2rq.db.op.OpVisitor.Default
visitEnter, visitEnter, visitEnter, visitEnter, visitEnter, visitEnter, visitEnter, visitEnter, visitLeave
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectStatementBuilder

public SelectStatementBuilder(DatabaseOp input,
                              Vendor vendor)
Method Detail

getSQL

public String getSQL()

getColumnSpecs

public List<ProjectionSpec> getColumnSpecs()

visit

public void visit(TableOp table)
Specified by:
visit in interface OpVisitor
Overrides:
visit in class OpVisitor.Default

visit

public void visit(SQLOp table)
Specified by:
visit in interface OpVisitor
Overrides:
visit in class OpVisitor.Default

visitOpTrue

public void visitOpTrue()
Specified by:
visitOpTrue in interface OpVisitor
Overrides:
visitOpTrue in class OpVisitor.Default

visitLeave

public void visitLeave(ProjectOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(LimitOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(DistinctOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(SelectOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(OrderOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(EmptyOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitEnter

public boolean visitEnter(AliasOp table)
Specified by:
visitEnter in interface OpVisitor
Overrides:
visitEnter in class OpVisitor.Default

visitLeave

public void visitLeave(AliasOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default

visitLeave

public void visitLeave(InnerJoinOp table)
Specified by:
visitLeave in interface OpVisitor
Overrides:
visitLeave in class OpVisitor.Default