001package gudusoft.gsqlparser.stmt;
002/*
003 * Date: 12-1-8
004 */
005
006import gudusoft.gsqlparser.*;
007import gudusoft.gsqlparser.nodes.*;
008
009public class TTruncateStatement extends TCustomSqlStatement {
010
011    private TPartitionExtensionClause partitionExtensionClause;
012    private TObjectNameList columns;
013
014    public TPartitionExtensionClause getPartitionExtensionClause() {
015        return partitionExtensionClause;
016    }
017
018    public TTruncateStatement(EDbVendor dbvendor) {
019        super(dbvendor);
020        sqlstatementtype = ESqlStatementType.sstTruncate;
021    }
022
023    public TObjectName getTableName() {
024        return tableName;
025    }
026
027    public TObjectNameList getColumns() {
028        return columns;
029    }
030
031    public int doParseStatement(TCustomSqlStatement psql) {
032        if (rootNode == null) return -1;
033        super.doParseStatement(psql);
034        TTruncateTableSqlNode node = (TTruncateTableSqlNode)rootNode;
035
036        if (node.getFromTableList() != null){//postgresql
037            TFromTable lcFromTable = null;
038            TJoin lcJoin = null;
039            for(int i=0; i<node.getFromTableList().size();i++){
040                 lcFromTable = node.getFromTableList().getFromTable(i);
041                if (lcFromTable.getFromtableType() != ETableSource.join){
042                    lcJoin = new TJoin();
043                    lcJoin.setTable(analyzeFromTable(lcFromTable,true));
044                    lcJoin.setStartToken(lcJoin.getTable().getStartToken());
045                    lcJoin.setEndToken(lcJoin.getTable().getEndToken());
046                    lcJoin.setGsqlparser(getGsqlparser());
047                }else{
048                    lcJoin = analyzeJoin(lcFromTable.getJoinExpr(),null,true);
049                    lcJoin.doParse(this, ESqlClause.join);
050                }
051                joins.addJoin(lcJoin);
052            }
053            if (this.tables.size() > 0){
054                this.tables.getTable(0).setEffectType(ETableEffectType.tetTruncate);
055                this.tableName = this.tables.getTable(0).getTableName();
056            }
057        }else{
058            this.tableName = node.getTableName();
059            TTable t = analyzeTablename(tableName);
060            if (t != null){
061                t.setEffectType(ETableEffectType.tetTruncate);
062            }
063        }
064
065        partitionExtensionClause = node.getPartitionExtensionClause();
066        columns =node.getColumns();
067
068        return 0;
069    }
070
071    private TObjectName tableName;
072
073    public void accept(TParseTreeVisitor v){
074        v.preVisit(this);
075        v.postVisit(this);
076    }
077
078    public void acceptChildren(TParseTreeVisitor v){
079        v.preVisit(this);
080        v.postVisit(this);
081    }
082
083    public void setPartitionExtensionClause(TPartitionExtensionClause partitionExtensionClause) {
084        this.partitionExtensionClause = partitionExtensionClause;
085    }
086
087    public void setColumns(TObjectNameList columns) {
088        this.columns = columns;
089    }
090
091    public void setTableName(TObjectName tableName) {
092        this.tableName = tableName;
093    }
094}