001package gudusoft.gsqlparser.catalog.input.model; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.List; 006import java.util.Objects; 007 008/** 009 * Catalog (database) entry inside a {@link UnifiedCatalogModel}. 010 * 011 * <p>Plan ยง6.</p> 012 */ 013public final class CatalogModel { 014 015 private final String name; 016 private final List<SchemaModel> schemas; 017 018 private CatalogModel(Builder b) { 019 if (b.name == null || b.name.isEmpty()) { 020 throw new IllegalArgumentException("CatalogModel.name is required"); 021 } 022 this.name = b.name; 023 this.schemas = Collections.unmodifiableList(new ArrayList<SchemaModel>(b.schemas)); 024 } 025 026 public static Builder builder() { 027 return new Builder(); 028 } 029 030 public String name() { 031 return name; 032 } 033 034 public List<SchemaModel> schemas() { 035 return schemas; 036 } 037 038 @Override 039 public boolean equals(Object o) { 040 if (this == o) return true; 041 if (!(o instanceof CatalogModel)) return false; 042 CatalogModel that = (CatalogModel) o; 043 return name.equals(that.name) && schemas.equals(that.schemas); 044 } 045 046 @Override 047 public int hashCode() { 048 return Objects.hash(name, schemas); 049 } 050 051 @Override 052 public String toString() { 053 return "CatalogModel{name=" + name + ", schemas=" + schemas.size() + '}'; 054 } 055 056 public static final class Builder { 057 058 private String name; 059 private final List<SchemaModel> schemas = new ArrayList<SchemaModel>(); 060 061 private Builder() { 062 } 063 064 public Builder name(String v) { 065 this.name = v; 066 return this; 067 } 068 069 public Builder addSchema(SchemaModel v) { 070 if (v == null) { 071 throw new IllegalArgumentException("CatalogModel schema may not be null"); 072 } 073 this.schemas.add(v); 074 return this; 075 } 076 077 public CatalogModel build() { 078 return new CatalogModel(this); 079 } 080 } 081}