001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.EJoinType;
004import gudusoft.gsqlparser.ESqlClause;
005import gudusoft.gsqlparser.ETableSource;
006
007/**
008 * @deprecated As of v2.7.4.0, Please use  {@link TJoinExpr} instead.
009 * <p>SQL 1:
010 *<blockquote><pre> select f from t1 left join t2 on t1.f1 = t2.f1 right join t3 on t1.f1 = t3.f1</pre></blockquote>
011 * In above SQL, the whole from clause can be represented by a {@link TJoin} class.
012 * <p>And "left join t2 on t1.f1 = t2.f1 right join t3 on t1.f1 = t3.f1" was represented by 2 instance of class {@link TJoinItem}.
013 * <p>These 2 instance can be accessed via {@link TJoin#getJoinItems}.
014 * <p>One for: "left join t2 on t1.f1 = t2.f1", the other is "right join t3 on t1.f1 = t3.f1".
015*/
016public class TJoinItem extends TParseTreeNode {
017    private int kind;
018    private TJoin join;
019    private TTable table;
020
021    /**
022     * Valid when {@link #getKind()} = {@link gudusoft.gsqlparser.TBaseType#join_source_join}, means this joinitem start with a join.
023     */
024    public TJoin getJoin() {
025        return join;
026    }
027
028    /**
029     * 
030     * @return join type of this join, such as left join, right join.
031     */
032    public EJoinType getJoinType() {
033        return joinType;
034    }
035
036    /**
037     * Valid when {@link #getKind()} = {@link gudusoft.gsqlparser.TBaseType#join_source_table}, means this joinitem start with a table.
038     * @return
039     */
040    public TTable getTable() {
041        return table;
042    }
043
044    public void setJoin(TJoin join) {
045
046        this.join = join;
047    }
048
049    public void setKind(int kind) {
050        this.kind = kind;
051    }
052
053    /**
054     * According to the table source in from clause, there are 2 kinds of joinitem.
055     * <ul>
056     * <li>{@link gudusoft.gsqlparser.TBaseType#join_source_table} means this joinitem start with a table.
057     * <blockquote>select f from t1 join t2 on t1.f1 = t2.f1</blockquote>
058     * <p>Text representation of this class is: "join t2 on t1.f1 = t2.f1"
059     * <p>"t2" can be fetch from {@link #getTable}.</li>
060     * <li>{@link gudusoft.gsqlparser.TBaseType#join_source_join}  means this joinitem start with a join.
061     * <blockquote><pre>
062     * select f1 from a  join (c join c1 on c.f1 = c1.f1) c2   on a.f1=c2.f1</pre>
063     * </blockquote>
064     * <p>Text representation of this class is: "join (c join c1 on c.f1 = c1.f1) c2 on a.f1=c2.f1"
065     * <p>"(c join c1 on c.f1 = c1.f1)" can be fetched from {@link #getJoin}.
066     * </li>
067     * </ul>
068     * @return
069     */
070
071    public int getKind() {
072        return kind;
073    }
074
075    public void setTable(TTable table) {
076        this.table = table;
077//        if (table == null) return;
078//        if (this.table.getTableType() == ETableSource.subquery){
079//            this.table.getSubquery().setLocation(ESqlClause.join);
080//        }
081    }
082
083
084    public void setUsingColumns(TObjectNameList usingColumns) {
085        this.usingColumns = usingColumns;
086    }
087
088    public TObjectNameList getUsingColumns() {
089
090        return usingColumns;
091    }
092
093    /**
094     * using (column list)
095     */
096    private TObjectNameList usingColumns;
097
098    public void setOnCondition(TExpression onCondition) {
099        this.onCondition = onCondition;
100    }
101
102    /**
103     * @return join condition, is type of {@link TExpression}.
104     */
105    public TExpression getOnCondition() {
106
107        return onCondition;
108    }
109
110    /**
111     * on condition;
112     */
113    private TExpression onCondition;
114
115    private EJoinType joinType;
116
117
118    public void setJoinType(EJoinType joinType) {
119        this.joinType = joinType;
120    }
121
122    public void accept(TParseTreeVisitor v){
123        v.preVisit(this);
124        v.postVisit(this);
125    }
126
127    public void acceptChildren(TParseTreeVisitor v){
128        v.preVisit(this);
129
130
131            if (getTable() != null){
132                getTable().acceptChildren(v);
133            }else if (getJoin() != null){
134                getJoin().acceptChildren(v);
135            }
136
137            if (getOnCondition() != null){
138                getOnCondition().acceptChildren(v);
139            }
140
141            if (getUsingColumns() != null){
142                getUsingColumns().acceptChildren(v);
143            }
144
145        v.postVisit(this);
146    }
147
148
149}