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 or OPTIONS
059    public void init(Object alterType, Object roleSpec, Object newName) {
060        this.alterType = (EAlterRoleType) alterType;
061        this.roleSpecification = (TObjectName) roleSpec;
062        if (this.alterType == EAlterRoleType.OPTIONS) {
063            if (newName != null) {
064                this.roleOptions = (ArrayList<TRoleOption>) newName;
065            }
066        } else {
067            this.newRoleName = (TObjectName) newName;
068        }
069    }
070
071    // SET
072    public void init(Object alterType, Object roleSpec, Object inDb, Object paramName, Object paramVal) {
073        this.alterType = (EAlterRoleType)alterType;
074        this.roleSpecification = (TObjectName) roleSpec;
075        if (inDb != null) {
076            this.inDatabase = (TObjectName)inDb;
077        }
078        this.parameterName = (TObjectName) paramName;
079        this.parameterValue = (TExpression) paramVal;
080    }
081    
082    // RESET
083    public void init(Object alterType, Object roleSpec, Object inDb, Object paramName) {
084        this.alterType = (EAlterRoleType)alterType;
085        this.roleSpecification = (TObjectName) roleSpec;
086        if (inDb != null) {
087            this.inDatabase = (TObjectName)inDb;
088        }
089        if (paramName instanceof TObjectName) {
090            this.parameterName = (TObjectName) paramName;
091        } else {
092            this.isResetAll = true;
093        }
094    }
095
096    // OPTIONS
097    public void initOptions(Object roleSpec, Object options) {
098        this.alterType = EAlterRoleType.OPTIONS;
099        this.roleSpecification = (TObjectName)roleSpec;
100        if(options != null){
101            this.roleOptions = (ArrayList<TRoleOption>)options;
102        }
103    }
104
105
106}