001package gudusoft.gsqlparser.nodes;
002
003import java.util.ArrayList;
004
005public class TAlterRoleSqlNode extends TParseTreeNode {
006
007    public enum EAlterRoleType {
008        RENAME,
009        SET,
010        RESET,
011        OPTIONS
012    }
013
014    private EAlterRoleType alterType;
015
016    private TObjectName roleSpecification; // Can be TObjectName or a TSourceToken for ALL
017    private TObjectName inDatabase;
018    private TObjectName newRoleName;
019    private ArrayList<TRoleOption> roleOptions;
020
021    // for SET/RESET
022    private TObjectName parameterName;
023    private TExpression parameterValue; // can be TExpressionList or TSourceToken for DEFAULT/CURRENT
024    private boolean isResetAll = false;
025
026    public EAlterRoleType getAlterType() {
027        return alterType;
028    }
029
030    public TObjectName getRoleSpecification() {
031        return roleSpecification;
032    }
033
034    public TObjectName getInDatabase() {
035        return inDatabase;
036    }
037
038    public TObjectName getNewRoleName() {
039        return newRoleName;
040    }
041
042    public ArrayList<TRoleOption> getRoleOptions() {
043        return roleOptions;
044    }
045
046    public TObjectName getParameterName() {
047        return parameterName;
048    }
049
050    public TExpression getParameterValue() {
051        return parameterValue;
052    }
053
054    public boolean isResetAll() {
055        return isResetAll;
056    }
057
058    // RENAME
059    public void init(Object alterType, Object roleSpec, Object newName) {
060        this.alterType = (EAlterRoleType) alterType;
061        this.roleSpecification = (TObjectName) roleSpec;
062        this.newRoleName = (TObjectName) newName;
063    }
064
065    // SET
066    public void init(Object alterType, Object roleSpec, Object inDb, Object paramName, Object paramVal) {
067        this.alterType = (EAlterRoleType)alterType;
068        this.roleSpecification = (TObjectName) roleSpec;
069        if (inDb != null) {
070            this.inDatabase = (TObjectName)inDb;
071        }
072        this.parameterName = (TObjectName) paramName;
073        this.parameterValue = (TExpression) paramVal;
074    }
075    
076    // RESET
077    public void init(Object alterType, Object roleSpec, Object inDb, Object paramName) {
078        this.alterType = (EAlterRoleType)alterType;
079        this.roleSpecification = (TObjectName) roleSpec;
080        if (inDb != null) {
081            this.inDatabase = (TObjectName)inDb;
082        }
083        if (paramName instanceof TObjectName) {
084            this.parameterName = (TObjectName) paramName;
085        } else {
086            this.isResetAll = true;
087        }
088    }
089
090    // OPTIONS
091    public void initOptions(Object roleSpec, Object options) {
092        this.alterType = EAlterRoleType.OPTIONS;
093        this.roleSpecification = (TObjectName)roleSpec;
094        if(options != null){
095            this.roleOptions = (ArrayList<TRoleOption>)options;
096        }
097    }
098
099
100}