001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EDbVendor;
004import gudusoft.gsqlparser.ESqlStatementType;
005import gudusoft.gsqlparser.TCustomSqlStatement;
006import gudusoft.gsqlparser.nodes.*;
007
008/**
009 * Statement class for StarRocks Routine Load job action statements.
010 *
011 * This class represents PAUSE, RESUME, and STOP ROUTINE LOAD statements.
012 *
013 * Syntax:
014 * PAUSE ROUTINE LOAD FOR [db_name.]job_name
015 * RESUME ROUTINE LOAD FOR [db_name.]job_name
016 * STOP ROUTINE LOAD FOR [db_name.]job_name
017 */
018public class TRoutineLoadJobActionStmt extends TCustomSqlStatement {
019
020    public enum ActionType {
021        PAUSE,
022        RESUME,
023        STOP
024    }
025
026    private ActionType actionType;
027    private TObjectName jobName;
028
029    public TRoutineLoadJobActionStmt(EDbVendor dbvendor) {
030        super(dbvendor);
031    }
032
033    public TRoutineLoadJobActionStmt(EDbVendor dbvendor, ESqlStatementType stmtType) {
034        super(dbvendor);
035        this.sqlstatementtype = stmtType;
036    }
037
038    public ActionType getActionType() {
039        return actionType;
040    }
041
042    public TObjectName getJobName() {
043        return jobName;
044    }
045
046    @Override
047    public int doParseStatement(TCustomSqlStatement psql) {
048        if (rootNode == null) return -1;
049        super.doParseStatement(psql);
050
051        TRoutineLoadJobActionSqlNode node = (TRoutineLoadJobActionSqlNode) rootNode;
052
053        // Map node action type to statement action type
054        if (node.getActionType() != null) {
055            switch (node.getActionType()) {
056                case PAUSE:
057                    this.actionType = ActionType.PAUSE;
058                    break;
059                case RESUME:
060                    this.actionType = ActionType.RESUME;
061                    break;
062                case STOP:
063                    this.actionType = ActionType.STOP;
064                    break;
065            }
066        }
067
068        this.jobName = node.getJobName();
069
070        return 0;
071    }
072
073    @Override
074    public void accept(TParseTreeVisitor v) {
075        v.preVisit(this);
076        v.postVisit(this);
077    }
078
079    @Override
080    public void acceptChildren(TParseTreeVisitor v) {
081        v.preVisit(this);
082        v.postVisit(this);
083    }
084}