001/* 002 * Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.dialect; 017 018import com.mybatisflex.core.util.StringUtil; 019import java.util.Arrays; 020import java.util.List; 021 022public enum DbType { 023 024 /** ClickHouse */ 025 CLICK_HOUSE("clickhouse", "clickhouse 数据库"), 026 027 /** CSIIDB */ 028 CSIIDB("csiidb", "CSIIDB 数据库"), 029 030 /** CUBRID */ 031 CUBRID("cubrid", "CUBRID 数据库"), 032 033 /** DB2 */ 034 DB2("db2", "DB2 数据库"), 035 DB2_1005("db2_1005", "DB2 10.5版本数据库"), 036 037 /** derby */ 038 DERBY("derby", "Derby 数据库"), 039 040 /** DM */ 041 DM("dm", "达梦数据库"), 042 043 /** Doris 兼容 Mysql,使用 MySql 驱动和协议 */ 044 DORIS("doris", "doris 数据库"), 045 046 /** Duckdb */ 047 DUCKDB("duckdb", "duckdb 数据库"), 048 049 /** Firebird */ 050 FIREBIRD("Firebird", "Firebird 数据库"), 051 052 /** Gauss */ 053 GAUSS("gauss", "Gauss 数据库"), 054 055 /** GBase */ 056 GBASE("gbase", "南大通用(华库)数据库"), 057 058 /** GBase-8c */ 059 GBASE_8C("gbase-8c", "南大通用数据库 GBase 8c"), 060 061 /** GBase-8s */ 062 GBASE_8S("gbase-8s", "南大通用数据库 GBase 8s"), 063 064 /** GBase-8s-pg */ 065 GBASE_8S_PG("gbase-8s-pg", "南大通用数据库 GBase 8s兼容pg"), 066 067 /** GOLDENDB */ 068 GOLDENDB("goldendb", "GoldenDB数据库"), 069 070 /** GOLDILOCKS */ 071 GOLDILOCKS("goldilocks", "GOLDILOCKS 数据库"), 072 073 /** greenplum */ 074 GREENPLUM("greenplum", "greenplum 数据库"), 075 076 /** H2 */ 077 H2("h2", "H2 数据库"), 078 079 /** HighGo */ 080 HIGH_GO("highgo", "瀚高数据库"), 081 082 /** Hive SQL */ 083 HIVE("Hive", "Hive SQL"), 084 085 /** HSQL */ 086 HSQL("hsql", "HSQL 数据库"), 087 088 /** Impala */ 089 IMPALA("impala", "impala 数据库"), 090 091 /** Informix */ 092 INFORMIX("informix", "Informix 数据库"), 093 094 /** Kingbase */ 095 KINGBASE_ES("kingbasees", "人大金仓数据库"), 096 097 /** lealone */ 098 LEALONE("lealone", "lealone 数据库"), 099 100 /** MARIADB */ 101 MARIADB("mariadb", "MariaDB 数据库"), 102 103 /** MYSQL */ 104 MYSQL("mysql", "MySql 数据库"), 105 106 /** OceanBase */ 107 OCEAN_BASE("oceanbase", "OceanBase 数据库"), 108 109 /** openGauss */ 110 OPENGAUSS("openGauss", "华为 openGauss 数据库"), 111 112 /** ORACLE */ 113 ORACLE("oracle", "Oracle11g 及以下数据库"), 114 115 /** oracle12c */ 116 ORACLE_12C("oracle12c", "Oracle12c 及以上数据库"), 117 118 /** Oscar */ 119 OSCAR("oscar", "神通数据库"), 120 121 /** Phoenix */ 122 PHOENIX("phoenix", "Phoenix HBase 数据库"), 123 124 /** POSTGRE_SQL */ 125 POSTGRE_SQL("postgresql", "PostgreSQL 数据库"), 126 127 /** presto */ 128 PRESTO("presto", "Presto数据库"), 129 130 /** redshift */ 131 REDSHIFT("redshift", "亚马逊 redshift 数据库"), 132 133 /** SAP_HANA */ 134 SAP_HANA("hana", "SAP_HANA 数据库"), 135 136 /** sinodb */ 137 SINODB("sinodb", "SinoDB 数据库"), 138 139 /** SQLITE */ 140 SQLITE("sqlite", "SQLite 数据库"), 141 142 /** SQLSERVER */ 143 SQLSERVER("sqlserver", "SQLServer 数据库"), 144 145 /** SqlServer 2005 数据库 */ 146 SQLSERVER_2005("sqlserver_2005", "SQLServer 数据库"), 147 148 /** SUNDB */ 149 SUNDB("sundb", "SUNDB数据库"), 150 151 /** Sybase */ 152 SYBASE("sybase", "Sybase ASE 数据库"), 153 154 /** TDengine */ 155 TDENGINE("TDengine", "TDengine 数据库"), 156 157 /** Trino */ 158 TRINO("trino", "trino 数据库"), 159 160 /** uxdb */ 161 UXDB("uxdb", "优炫数据库"), 162 163 /** VASTBASE */ 164 VASTBASE("vastbase", "Vastbase数据库"), 165 166 /** Vertica */ 167 VERTICA("vertica", "vertica数据库"), 168 169 /** XCloud */ 170 XCloud("xcloud", "行云数据库"), 171 172 /** xugu */ 173 XUGU("xugu", "虚谷数据库"), 174 175 /** yasdb */ 176 YASDB("yasdb", "崖山数据库"), 177 178 /** OTHER */ 179 OTHER("other", "其他数据库"); 180 181 /** 数据库名称 */ 182 private final String name; 183 184 /** 描述 */ 185 private final String remarks; 186 187 DbType(String name, String remarks) { 188 this.name = name; 189 this.remarks = remarks; 190 } 191 192 public String getName() { 193 return name; 194 } 195 196 /** 197 * 根据数据库类型名称自动识别数据库类型 198 * 199 * @param name 名称 200 * @return 数据库类型 201 */ 202 public static DbType findByName(String name) { 203 if (StringUtil.noText(name)) { 204 return null; 205 } 206 207 return Arrays.stream(values()) 208 .filter(em -> em.getName().equalsIgnoreCase(name)) 209 .findFirst() 210 .orElse(null); 211 } 212 213 /** 214 * 获取所有数据库类型 215 * 216 * @return 包含所有数据库类型的列表 217 */ 218 public static List<DbType> all() { 219 return Arrays.asList(DbType.values()); 220 } 221 222 /** 223 * 判断当前数据库语法是否与MySQL属于同一类型 224 */ 225 public boolean mysqlSameType() { 226 return this == MYSQL || this == MARIADB || this == GBASE || this == OSCAR || this == XUGU || this == CLICK_HOUSE || this == OCEAN_BASE || this == CUBRID || this == SUNDB || this == GOLDENDB || this == YASDB; 227 } 228 229 /** 230 * 判断当前数据库语法是否与Oracle属于同一类型 231 */ 232 public boolean oracleSameType() { 233 return this == ORACLE || this == DM; 234 } 235 236 /** 237 * 判断当前数据库语法是否与PostgreSQL属于同一类型 238 */ 239 public boolean postgresqlSameType() { 240 return this == POSTGRE_SQL || this == H2 || this == LEALONE || this == SQLITE || this == HSQL || this == KINGBASE_ES || this == PHOENIX || this == SAP_HANA || this == IMPALA || this == HIGH_GO || this == VERTICA || this == REDSHIFT || this == GAUSS || this == OPENGAUSS || this == TDENGINE || this == UXDB || this == GBASE_8S_PG || this == GBASE_8C || this == VASTBASE || this == DUCKDB; 241 } 242 243 /** 244 * 是否为已兼容的数据库类型 245 * 允许的数据库类型包括MySQL系列、Oracle系列和PostgreSQL系列 246 * 247 * @return 如果是允许的数据库类型返回true,否则返回false 248 */ 249 public boolean isSupportDb() { 250 return mysqlSameType() || oracleSameType() || postgresqlSameType(); 251 } 252}