001package gudusoft.gsqlparser; 002 003import java.util.ArrayList; 004import java.util.Arrays; 005import java.util.HashMap; 006import java.util.List; 007import java.util.Map; 008 009/** 010 * Database vendors supported: 011 * <br> 012 * {@link #dbvmssql},{@link #dbvoracle},{@link #dbvmysql},{@link #dbvdb2}, 013 * {@link #dbvsybase}, {@link #dbvinformix},{@link #dbvpostgresql},{@link #dbvteradata}, 014 * {@link #dbvmdx},{@link #dbvnetezza},{@link #dbvhive},{@link #dbvgreenplum},{@link #dbvredshift} 015 * <br><br> 016 * No specific engine for Microsoft ACCESS {@link #dbvaccess}, use {@link #dbvmssql} instead. 017 * <br><br> 018 * Database engine not supported: 019 *<br>{@link #dbvgeneric},{@link #dbvfirebird},{@link #dbvansi},{@link #dbvodbc} 020 */ 021public enum EDbVendor { 022 dbvaccess(new String[]{"access"}, "Microsoft Access", 0), 023 dbvansi(new String[]{"ansi"}, "ANSI SQL", 0), 024 dbvathena(new String[]{"athena"}, "AWS Athena", 1), //aws,2021/9/18 025 dbvazuresql(new String[]{"azuresql", "azure"}, "Azure SQL", 1), 026 dbvbigquery(new String[]{"bigquery"}, "Google BigQuery", 1), 027 dbvclickhouse(new String[]{"clickhouse"}, "ClickHouse", 1), 028 dbvcouchbase(new String[]{"couchbase"}, "Couchbase", 1), 029 dbvdax(new String[]{"dax"}, "AWS DAX", 0), 030 dbvdb2(new String[]{"db2"}, "IBM DB2", 1), 031 dbvdoris(new String[]{"doris"}, "Apache Doris", 1), 032 dbvduckdb(new String[]{"duckdb"}, "DuckDB", 1), 033 dbvexasol(new String[]{"exasol"}, "Exasol", 0), 034 dbvfirebird(new String[]{"firebird"}, "Firebird", 0), 035 dbvflink(new String[]{"flink"}, "Apache Flink SQL", 1), 036 dbvgeneric(new String[]{"generic"}, "Generic SQL", 0), 037 dbvgreenplum(new String[]{"greenplum"}, "Greenplum", 1), 038 dbvhana(new String[]{"hana"}, "SAP HANA", 1), 039 dbvhive(new String[]{"hive"}, "Apache Hive", 1), 040 dbvimpala(new String[]{"impala"}, "Apache Impala", 1), 041 dbvinformix(new String[]{"informix"}, "IBM Informix", 1), 042 dbvmdx(new String[]{"mdx"}, "MDX", 1), 043 dbvmysql(new String[]{"mysql"}, "MySQL", 1), 044 dbvmssql(new String[]{"mssql", "sqlserver"}, "Microsoft SQL Server", 1), 045 dbvnetezza(new String[]{"netezza"}, "IBM Netezza", 1), 046 dbvodbc(new String[]{"odbc"}, "ODBC", 1), 047 dbvopenedge(new String[]{"openedge"}, "Progress OpenEdge", 1), 048 dbvoracle(new String[]{"oracle"}, "Oracle", 1), 049 dbvpostgresql(new String[]{"postgresql", "postgres"}, "PostgreSQL", 1), 050 dbvpresto(new String[]{"presto"}, "Presto", 1), //2021/9/18 051 dbvredshift(new String[]{"redshift"}, "Amazon Redshift", 1), 052 dbvsnowflake(new String[]{"snowflake"}, "Snowflake", 1), 053 dbvsoql(new String[]{"soql"}, "Salesforce SOQL", 1), 054 dbvsparksql(new String[]{"sparksql", "spark"}, "Apache Spark SQL", 1), 055 dbvsqlite(new String[]{"sqlite"}, "SQLite", 1), 056 dbvstarrocks(new String[]{"starrocks"}, "StarRocks", 1), 057 dbvsybase(new String[]{"sybase"}, "Sybase", 1), 058 dbvteradata(new String[]{"teradata"}, "Teradata", 1), 059 dbvtrino(new String[]{"trino"}, "Trino", 1), //2021/9/18 060 dbvvertica(new String[]{"vertica"}, "Vertica", 1), 061 dbvdatabricks(new String[]{"databricks"}, "Databricks", 1), //2022/10/30 062 dbvgaussdb(new String[]{"gaussdb"}, "GaussDB", 1), //2023/9/28 063 dbvedb(new String[]{"edb", "epas"}, "EDB Postgres Advanced Server", 1), //2026/3/18 064 dbvdameng(new String[]{"dameng", "dm"}, "Dameng Database", 1), //2026/4/10 065 dbvoceanbase(new String[]{"oceanbase", "ob"}, "OceanBase", 1); //2026/4/11 — Phase 3 landed: dual-fork active (oceanbasemysql/ + oceanbaseoracle/), status=1 (publicly visible) 066 067 private final String[] aliases; 068 private final String description; 069 private final int status; // 0 means not implemented, 1 means implemented 070 private static final Map<String, EDbVendor> aliasMap = new HashMap<>(); 071 072 static { 073 for (EDbVendor vendor : values()) { 074 for (String alias : vendor.aliases) { 075 aliasMap.put(alias.toLowerCase(), vendor); 076 } 077 } 078 } 079 080 EDbVendor(String[] aliases, String description, int status) { 081 this.aliases = aliases; 082 this.description = description; 083 this.status = status; 084 } 085 086 /** 087 * Get the primary string representation of this database vendor 088 * @return the primary alias (first in the list) 089 */ 090 public String getPrimaryAlias() { 091 return aliases[0]; 092 } 093 094 /** 095 * Get all string representations of this database vendor 096 * @return array of all aliases 097 */ 098 public String[] getAliases() { 099 return aliases; 100 } 101 102 /** 103 * Get the description of this database vendor 104 * @return the description 105 */ 106 public String getDescription() { 107 return description; 108 } 109 110 /** 111 * Get the implementation status of this database vendor 112 * @return 0 for not implemented, 1 for implemented 113 */ 114 public int getStatus() { 115 return status; 116 } 117 118 /** 119 * Check if this database vendor is implemented 120 * @return true if implemented, false otherwise 121 */ 122 public boolean isImplemented() { 123 return status == 1; 124 } 125 126 /** 127 * Get the database vendor from a string representation 128 * @param alias the string representation 129 * @return the corresponding database vendor or null if not found 130 */ 131 public static EDbVendor fromAlias(String alias) { 132 if (alias == null) { 133 return null; 134 } 135 return aliasMap.get(alias.toLowerCase()); 136 } 137 138 /** 139 * Get the database vendor from a string representation, returning dbvoracle as default if not found 140 * @param alias the string representation 141 * @return the corresponding database vendor or dbvoracle if not found 142 */ 143 public static EDbVendor valueOfWithDefault(String alias) { 144 EDbVendor vendor = fromAlias(alias); 145 return vendor != null ? vendor : dbvoracle; 146 } 147 148 /** 149 * Returns an array of strings representing all database vendors 150 * using their primary aliases (first alias), sorted alphabetically 151 * @return array of all primary database vendor aliases 152 */ 153 public static String[] getAllVendorAliases() { 154 return getAllVendorAliases(false); 155 } 156 157 /** 158 * Returns an array of strings representing database vendors 159 * using their primary aliases (first alias), sorted alphabetically 160 * @param implementedOnly if true, only implemented vendors are included 161 * @return array of primary database vendor aliases 162 */ 163 public static String[] getAllVendorAliases(boolean implementedOnly) { 164 EDbVendor[] allVendors = values(); 165 List<String> aliasList = new ArrayList<>(); 166 167 for (EDbVendor vendor : allVendors) { 168 if (!implementedOnly || vendor.isImplemented()) { 169 aliasList.add(vendor.getPrimaryAlias()); 170 } 171 } 172 173 String[] aliases = aliasList.toArray(new String[0]); 174 Arrays.sort(aliases); 175 return aliases; 176 } 177 178 /** 179 * Check if a string representation corresponds to this database vendor 180 * @param alias the string to check 181 * @return true if the string represents this vendor, false otherwise 182 */ 183 public boolean matchesAlias(String alias) { 184 if (alias == null) { 185 return false; 186 } 187 return Arrays.asList(getAliases()).contains(alias.toLowerCase()); 188 } 189}