gudusoft.gsqlparser.nodes
Class TJoin

java.lang.Object
  extended by gudusoft.gsqlparser.nodes.TParseTreeNode
      extended by gudusoft.gsqlparser.nodes.TNodeWithAliasClause
          extended by gudusoft.gsqlparser.nodes.TJoin
All Implemented Interfaces:
Visitable

public class TJoin
extends TNodeWithAliasClause

A list of join TCustomSqlStatement.joins represents table sources in following clauses of SQL statement:

Each table source in from clause was treated as a join which is type of TJoin.

The reason for this design is that we can treat all table sources in from clause in a uniform way.

SQL 1:

select f from t1

size of joins will be 1, t1 information can be fetch via joins.getJoin(0).getTable()

SQL 2:

select f from t1,t2

size of joins will be 2,

t1 information can be fetch via joins.getJoin(0).getTable()

t2 information can be fetch via joins.getJoin(1).getTable()

SQL 3:

select f from t1 join t2 on t1.f1 = t2.f1

size of joins will be 1,

t1 information can be fetch via joins.getJoin(0).getTable()

In order to access t2, we need to introduce a new class TJoinItem which includes all information about t2 and join condition after on keyword.

There is a property named joinItems of TJoin which is type of TJoinItemList that includes a list of TJoinItem.

this property can be access via getJoinItems().

Now, t2 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(0).getTable()

SQL 4:

select f from t1 join t2 on t1.f1 = t2.f1 join t3 on t1.f1 = t3.f1

size of joins will be 1,

t1 can be fetch via joins.getJoin(0).getTable()

t2 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(0).getTable()

t3 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(1).getTable()


Constructor Summary
TJoin()
           
 
Method Summary
 void accept(TParseTreeVisitor v)
           
 TAliasClause getAliasClause()
           
 TJoin getJoin()
           
 TJoinItemList getJoinItems()
          List of joinItems.
 int getKind()
          According to the table source in from clause, there are 3 kinds of join.
 TTable getTable()
           
 void setJoin(TJoin join)
           
 void setJoinItems(TJoinItemList joinItems)
           
 void setKind(int kind)
           
 void setTable(TTable table)
           
 
Methods inherited from class gudusoft.gsqlparser.nodes.TNodeWithAliasClause
setAliasClause, toString
 
Methods inherited from class gudusoft.gsqlparser.nodes.TParseTreeNode
addAllMyTokensToTokenList, doParse, getColumnNo, getDummyTag, getEndToken, getGsqlparser, getLineNo, getNodeType, getStartToken, init, init, init, init, init, init, setDummyTag, setEndToken, setEndToken, setGsqlparser, setNodeType, setStartToken, setStartToken, setString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TJoin

public TJoin()
Method Detail

setJoinItems

public void setJoinItems(TJoinItemList joinItems)

setJoin

public void setJoin(TJoin join)

setTable

public void setTable(TTable table)

setKind

public void setKind(int kind)

getJoinItems

public TJoinItemList getJoinItems()
List of joinItems.

SQL 1:

 select f from t1 left join t2 on t1.f1 = t2.f1 right join t3 on t1.f1 = t3.f1
Text in Item 0 will be: left join t2 on t1.f1 = t2.f1

Text in Item 1 will be: right join t3 on t1.f1 = t3.f1

Check TJoinItem to see how information was organized.

Returns:

getJoin

public TJoin getJoin()
Returns:
this join start with another join( (a as a_alias left join a1 on a1.f1 = a_alias.f1) as a_join ) in SQL:
 select a_join.f1
 from (a as a_alias left join a1 on a1.f1 = a_alias.f1) as a_join
 join b on a_join.f1 = b.f1;
 

getTable

public TTable getTable()
Returns:
this join start with a table(t1) in SQL:
select f from t1 join t2 on t1.f1 = t2.f1

getKind

public int getKind()
According to the table source in from clause, there are 3 kinds of join.

Returns:

getAliasClause

public TAliasClause getAliasClause()
Overrides:
getAliasClause in class TNodeWithAliasClause
Returns:
alias of getJoin(), valid only when = TBaseType#join_source_join. In this SQL, alias is "as a_join"
 select a_join.f1
 from (a as a_alias left join a1 on a1.f1 = a_alias.f1) as a_join
 join b on a_join.f1 = b.f1;
 

But in this SQL, alias is null, "as t1" is the alias of t1.

 select f from t as t1 join t2 on t1.f1 = t2.f1
 

accept

public void accept(TParseTreeVisitor v)
Specified by:
accept in interface Visitable
Overrides:
accept in class TParseTreeNode