001package gudusoft.gsqlparser.nodes.oceanbase; 002 003import gudusoft.gsqlparser.EDbObjectType; 004import gudusoft.gsqlparser.nodes.TObjectName; 005import gudusoft.gsqlparser.nodes.TParseTreeNode; 006import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 007 008import java.util.ArrayList; 009 010/** 011 * AST node for OceanBase {@code ALTER TENANT} (Phase 4 Batch 1). 012 * 013 * <p>Covers all the documented forms: {@code ALTER TENANT t SET ...}, 014 * {@code ALTER TENANT t ADD PRIMARY_ZONE 'z'}, {@code ALTER TENANT t 015 * RENAME TO t2}, and the lock/unlock verbs. The {@link #getActionType()} 016 * enum indicates which variant was matched so downstream tools can 017 * dispatch without re-parsing. 018 * 019 * @since 4.0.1.4 020 */ 021public class TOceanbaseAlterTenantSqlNode extends TParseTreeNode { 022 023 /** 024 * The {@code ALTER TENANT} sub-form matched by the grammar. 025 */ 026 public enum EAction { 027 /** {@code ALTER TENANT t SET name=value [, ...]} */ 028 SET_OPTIONS, 029 /** {@code ALTER TENANT t ADD PRIMARY_ZONE 'z'} */ 030 ADD_PRIMARY_ZONE, 031 /** {@code ALTER TENANT t RENAME TO t_new} */ 032 RENAME, 033 /** {@code ALTER TENANT t LOCK} */ 034 LOCK, 035 /** {@code ALTER TENANT t UNLOCK} */ 036 UNLOCK 037 } 038 039 private TObjectName tenantName; 040 private EAction actionType; 041 private TObjectName newTenantName; 042 private TObjectName primaryZoneValue; 043 private ArrayList<TOceanbaseTenantOption> tenantOptions 044 = new ArrayList<TOceanbaseTenantOption>(); 045 046 public TObjectName getTenantName() { 047 return tenantName; 048 } 049 050 public void setTenantName(TObjectName tenantName) { 051 this.tenantName = tenantName; 052 if (tenantName != null) { 053 tenantName.setDbObjectType(EDbObjectType.database); 054 } 055 } 056 057 public EAction getActionType() { 058 return actionType; 059 } 060 061 public void setActionType(EAction actionType) { 062 this.actionType = actionType; 063 } 064 065 public TObjectName getNewTenantName() { 066 return newTenantName; 067 } 068 069 public void setNewTenantName(TObjectName newTenantName) { 070 this.newTenantName = newTenantName; 071 if (newTenantName != null) { 072 newTenantName.setDbObjectType(EDbObjectType.database); 073 } 074 } 075 076 public TObjectName getPrimaryZoneValue() { 077 return primaryZoneValue; 078 } 079 080 public void setPrimaryZoneValue(TObjectName primaryZoneValue) { 081 this.primaryZoneValue = primaryZoneValue; 082 } 083 084 public ArrayList<TOceanbaseTenantOption> getTenantOptions() { 085 return tenantOptions; 086 } 087 088 public void addTenantOption(TOceanbaseTenantOption option) { 089 if (option != null) { 090 this.tenantOptions.add(option); 091 } 092 } 093 094 @Override 095 public void init(Object arg1) { 096 setTenantName((TObjectName) arg1); 097 } 098 099 @Override 100 public void accept(TParseTreeVisitor v) { 101 v.preVisit(this); 102 v.postVisit(this); 103 } 104 105 @Override 106 public void acceptChildren(TParseTreeVisitor v) { 107 v.preVisit(this); 108 if (tenantName != null) { 109 tenantName.acceptChildren(v); 110 } 111 if (newTenantName != null) { 112 newTenantName.acceptChildren(v); 113 } 114 if (tenantOptions != null) { 115 for (TOceanbaseTenantOption opt : tenantOptions) { 116 if (opt != null) { 117 opt.acceptChildren(v); 118 } 119 } 120 } 121 v.postVisit(this); 122 } 123}