001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.ESqlClause;
004import gudusoft.gsqlparser.ETableElementType;
005import gudusoft.gsqlparser.TCustomSqlStatement;
006import gudusoft.gsqlparser.nodes.flink.TFlinkWatermarkClause;
007import gudusoft.gsqlparser.nodes.oracle.TSupplementalLogging;
008import gudusoft.gsqlparser.nodes.teradata.TTeradataPeriodForClause;
009
010
011public class TTableElement extends TParseTreeNode {
012    public static final int type_column_def = 1;
013    public static final int type_table_constraint = 2;
014    public static final int type_table_like = 3;
015    public static final int type_supplemental_logging = 4;
016    public static final int type_period_for_clause = 5;
017    public static final int type_flink_watermark = 6;
018
019    private int type = type_column_def;
020
021    private TObjectName parentTable = null;
022
023    private ETableElementType tableElementType = ETableElementType.column_def;
024
025    public TObjectName getParentTable() {
026        return parentTable;
027    }
028
029    private TColumnDefinition columnDefinition = null;
030    private TConstraint constraint = null;
031    private TSupplementalLogging supplementalLogging = null;
032    private TTeradataPeriodForClause periodForClause = null;
033    private TFlinkWatermarkClause flinkWatermarkClause = null;
034
035    public TConstraint getConstraint() {
036        return constraint;
037    }
038
039    public void init(Object arg1, Object arg2){
040        tableElementType = (ETableElementType)arg1;
041        switch (tableElementType){
042            case column_def:
043                columnDefinition = (TColumnDefinition)arg2;
044                type  = type_column_def;
045                break;
046            case table_constraint:
047                constraint = (TConstraint)arg2;
048                type  = type_table_constraint;
049                break;
050            case table_like:
051                parentTable = (TObjectName)((TDummy)arg2).node1;
052                type  = type_table_like;
053                break;
054            case supplemental_logging:
055                supplementalLogging = (TSupplementalLogging)(arg2);
056                type  = type_supplemental_logging;
057                break;
058        }
059    }
060    public void init(Object arg1)
061    {
062        if (arg1 instanceof TColumnDefinition){
063            columnDefinition = (TColumnDefinition)arg1;
064            type  = type_column_def;
065        }else if (arg1 instanceof TConstraint){
066            constraint = (TConstraint)arg1;
067            type  = type_table_constraint;
068        }else if (arg1 instanceof TDummy){
069            parentTable = (TObjectName)((TDummy)arg1).node1;
070            type  = type_table_like;
071        }else if (arg1 instanceof TSupplementalLogging){
072            supplementalLogging = (TSupplementalLogging)(arg1);
073            type  = type_supplemental_logging;
074        }else if (arg1 instanceof TTeradataPeriodForClause){
075            periodForClause = (TTeradataPeriodForClause)(arg1);
076            type  = type_period_for_clause;
077        }else if (arg1 instanceof TFlinkWatermarkClause){
078            flinkWatermarkClause = (TFlinkWatermarkClause)(arg1);
079            type  = type_flink_watermark;
080        }
081    }
082
083    public TColumnDefinition getColumnDefinition() {
084        return columnDefinition;
085    }
086
087    public int getType() {
088
089        return type;
090    }
091
092    public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
093        if (this.columnDefinition != null)
094         this.columnDefinition.doParse(psql,plocation);
095        if (this.constraint != null){
096            this.constraint.doParse(psql,plocation);
097        }
098    }
099
100    public void accept(TParseTreeVisitor v)
101    {
102        v.preVisit(this);
103        v.postVisit(this);
104    }
105
106    public void acceptChildren(TParseTreeVisitor v)
107    {
108        v.preVisit(this);
109        v.postVisit(this);
110    }
111
112    public void setType(int type) {
113        this.type = type;
114    }
115
116    public void setParentTable(TObjectName parentTable) {
117        this.parentTable = parentTable;
118    }
119
120    public void setColumnDefinition(TColumnDefinition columnDefinition) {
121        this.columnDefinition = columnDefinition;
122    }
123
124    public void setConstraint(TConstraint constraint) {
125        this.constraint = constraint;
126    }
127
128    public void setSupplementalLogging(TSupplementalLogging supplementalLogging) {
129        this.supplementalLogging = supplementalLogging;
130    }
131
132    /**
133     * Gets the Teradata PERIOD FOR clause if this table element represents one.
134     *
135     * @return the PERIOD FOR clause, or null if this is not a period for element
136     */
137    public TTeradataPeriodForClause getPeriodForClause() {
138        return periodForClause;
139    }
140
141    public void setPeriodForClause(TTeradataPeriodForClause periodForClause) {
142        this.periodForClause = periodForClause;
143    }
144
145    /**
146     * Gets the Flink WATERMARK clause if this table element represents one.
147     *
148     * @return the WATERMARK clause, or null if this is not a watermark element
149     */
150    public TFlinkWatermarkClause getFlinkWatermarkClause() {
151        return flinkWatermarkClause;
152    }
153
154    public void setFlinkWatermarkClause(TFlinkWatermarkClause flinkWatermarkClause) {
155        this.flinkWatermarkClause = flinkWatermarkClause;
156    }
157}