001package gudusoft.gsqlparser.nodes.oceanbase;
002
003import gudusoft.gsqlparser.nodes.TObjectName;
004import gudusoft.gsqlparser.nodes.TParseTreeNode;
005import gudusoft.gsqlparser.nodes.TParseTreeVisitor;
006
007import java.util.ArrayList;
008
009/**
010 * A single OceanBase tenant option inside a {@code CREATE TENANT} /
011 * {@code ALTER TENANT} option list.
012 *
013 * <p>Represents one of the forms documented in the OceanBase 4.x admin guide:
014 * <ul>
015 *   <li>{@code RESOURCE_POOL_LIST = ('p1', 'p2')}</li>
016 *   <li>{@code PRIMARY_ZONE = 'zone1'}</li>
017 *   <li>{@code LOCALITY = 'F@zone1, F@zone2'}</li>
018 *   <li>{@code CHARSET = 'utf8mb4'}</li>
019 *   <li>{@code COMMENT = '...'}</li>
020 *   <li>{@code LOGONLY_REPLICA_NUM = 2} / {@code REPLICA_NUM = 3}</li>
021 *   <li>{@code SET ob_query_timeout = 100000000}
022 *       (the {@link #isSetVariable() setVariable} form)</li>
023 * </ul>
024 *
025 * <p>The option {@linkplain #getName() name} is stored as a plain string
026 * (uppercase canonical form) rather than an enum so the node can carry
027 * future options without a core-library recompile. Values are stored as
028 * a list of {@link TObjectName} tokens — identifiers, string literals,
029 * and numeric literals all surface here. Callers can use
030 * {@link #getFirstValue()} for single-valued options or iterate
031 * {@link #getValues()} for list-valued ones.
032 *
033 * @since 4.0.1.4
034 */
035public class TOceanbaseTenantOption extends TParseTreeNode {
036
037    private String name;
038    private ArrayList<TObjectName> values = new ArrayList<TObjectName>();
039    private boolean isSetVariable;
040
041    public TOceanbaseTenantOption() {
042    }
043
044    public String getName() {
045        return name;
046    }
047
048    public void setName(String name) {
049        this.name = name;
050    }
051
052    public ArrayList<TObjectName> getValues() {
053        return values;
054    }
055
056    public void addValue(TObjectName value) {
057        if (value != null) {
058            this.values.add(value);
059        }
060    }
061
062    public TObjectName getFirstValue() {
063        return values.isEmpty() ? null : values.get(0);
064    }
065
066    /**
067     * @return {@code true} when this option was introduced by the
068     *         {@code SET name = value} form (a session variable assignment
069     *         threaded into the tenant create/alter), {@code false} when it
070     *         was a plain {@code name = value} tenant option.
071     */
072    public boolean isSetVariable() {
073        return isSetVariable;
074    }
075
076    public void setSetVariable(boolean setVariable) {
077        this.isSetVariable = setVariable;
078    }
079
080    @Override
081    public void accept(TParseTreeVisitor v) {
082        v.preVisit(this);
083        v.postVisit(this);
084    }
085
086    @Override
087    public void acceptChildren(TParseTreeVisitor v) {
088        v.preVisit(this);
089        if (values != null) {
090            for (TObjectName value : values) {
091                if (value != null) {
092                    value.acceptChildren(v);
093                }
094            }
095        }
096        v.postVisit(this);
097    }
098}