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 resource option inside a {@code CREATE RESOURCE
011 * UNIT} / {@code CREATE RESOURCE POOL} / {@code ALTER RESOURCE ...}
012 * option list.
013 *
014 * <p>Represents one of the forms documented in the OceanBase 4.x admin
015 * guide:
016 * <ul>
017 *   <li><b>Resource unit:</b> {@code MIN_CPU}, {@code MAX_CPU},
018 *       {@code MEMORY_SIZE}, {@code LOG_DISK_SIZE}, {@code MAX_IOPS},
019 *       {@code MIN_IOPS}, {@code IOPS_WEIGHT}, {@code MAX_SESSION_NUM}</li>
020 *   <li><b>Resource pool:</b> {@code UNIT = 'name'},
021 *       {@code UNIT_NUM = N}, {@code ZONE_LIST = ('z1', 'z2', ...)}</li>
022 * </ul>
023 *
024 * <p>Parallels {@link TOceanbaseTenantOption} in shape but is kept as a
025 * distinct class so tenant and resource DDL trees never mix — callers
026 * switching on option kind can rely on the type itself rather than a
027 * secondary field.
028 *
029 * @since 4.0.1.4
030 */
031public class TOceanbaseResourceOption extends TParseTreeNode {
032
033    private String name;
034    private ArrayList<TObjectName> values = new ArrayList<TObjectName>();
035
036    public TOceanbaseResourceOption() {
037    }
038
039    public String getName() {
040        return name;
041    }
042
043    public void setName(String name) {
044        this.name = name;
045    }
046
047    public ArrayList<TObjectName> getValues() {
048        return values;
049    }
050
051    public void addValue(TObjectName value) {
052        if (value != null) {
053            this.values.add(value);
054        }
055    }
056
057    public TObjectName getFirstValue() {
058        return values.isEmpty() ? null : values.get(0);
059    }
060
061    @Override
062    public void accept(TParseTreeVisitor v) {
063        v.preVisit(this);
064        v.postVisit(this);
065    }
066
067    @Override
068    public void acceptChildren(TParseTreeVisitor v) {
069        v.preVisit(this);
070        if (values != null) {
071            for (TObjectName value : values) {
072                if (value != null) {
073                    value.acceptChildren(v);
074                }
075            }
076        }
077        v.postVisit(this);
078    }
079}