Skip to content

Commit

Permalink
数据库类型归类优化
Browse files Browse the repository at this point in the history
  • Loading branch information
qmdx committed Apr 2, 2024
1 parent a38c105 commit 95a196f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public enum DbType {
/**
* Sinodb
*/
SINODB("sinodb","星瑞格数据库"),
SINODB("sinodb", "星瑞格数据库"),
/**
* Oscar
*/
Expand All @@ -154,7 +154,7 @@ public enum DbType {
* CUBRID
*/
CUBRID("cubrid", "CUBRID数据库"),
/**
/**
* SUNDB
*/
SUNDB("sundb", "SUNDB数据库"),
Expand Down Expand Up @@ -233,4 +233,42 @@ public static DbType getDbType(String dbType) {
}
return OTHER;
}

public boolean mysqlSameType() {
return this == DbType.MYSQL
|| this == DbType.MARIADB
|| this == DbType.GBASE
|| this == DbType.OSCAR
|| this == DbType.XU_GU
|| this == DbType.CLICK_HOUSE
|| this == DbType.OCEAN_BASE
|| this == DbType.CUBRID
|| this == DbType.SUNDB;
}

public boolean oracleSameType() {
return this == DbType.ORACLE
|| this == DbType.DM
|| this == DbType.GAUSS;
}

public boolean postgresqlSameType() {
return this == DbType.POSTGRE_SQL
|| this == DbType.H2
|| this == DbType.LEALONE
|| this == DbType.SQLITE
|| this == DbType.HSQL
|| this == DbType.KINGBASE_ES
|| this == DbType.PHOENIX
|| this == DbType.SAP_HANA
|| this == DbType.IMPALA
|| this == DbType.HIGH_GO
|| this == DbType.VERTICA
|| this == DbType.REDSHIFT
|| this == DbType.OPENGAUSS
|| this == DbType.TDENGINE
|| this == DbType.UXDB
|| this == DbType.GBASE8S_PG
|| this == DbType.GBASE_8C;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,47 +147,22 @@ public static ScriptRunner getScriptRunner(Connection connection, boolean autoCo

protected static IDdlGenerator getDdlGenerator(String jdbcUrl) throws RuntimeException {
DbType dbType = JdbcUtils.getDbType(jdbcUrl);
switch (dbType) {
case MYSQL:
case MARIADB:
case GBASE:
case OSCAR:
case XU_GU:
case CLICK_HOUSE:
case OCEAN_BASE:
case CUBRID:
case SUNDB:
return MysqlDdlGenerator.newInstance();
case ORACLE:
case DM:
case GAUSS:
case ORACLE_12C:
case FIREBIRD:
case SQL_SERVER:
return OracleDdlGenerator.newInstance();
case SQLITE:
return SQLiteDdlGenerator.newInstance();
case POSTGRE_SQL:
case H2:
case LEALONE:
case HSQL:
case KINGBASE_ES:
case PHOENIX:
case SAP_HANA:
case IMPALA:
case HIGH_GO:
case VERTICA:
case REDSHIFT:
case OPENGAUSS:
case TDENGINE:
case UXDB:
case GBASE8S_PG:
case GBASE_8C:
return PostgreDdlGenerator.newInstance();
default:
throw ExceptionUtils.mpe("%s database not supported.", dbType.getDb());
// mysql same type
if (dbType.mysqlSameType()) {
return MysqlDdlGenerator.newInstance();
}

// oracle same type
else if (dbType.oracleSameType()) {
return OracleDdlGenerator.newInstance();
}
else if (DbType.SQLITE == dbType){
return SQLiteDdlGenerator.newInstance();
}
// postgresql same type
else if (dbType.postgresqlSameType()) {
return PostgreDdlGenerator.newInstance();
}
throw new RuntimeException("Unsupported database type: " + jdbcUrl);
}

public static String getDatabase(String jdbcUrl) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
/*
* Copyright (c) 2011-2023, baomidou ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.baomidou.mybatisplus.extension.ddl.history;

import org.springframework.stereotype.Component;

import java.util.function.Function;


/**
* SQLite DDL 生成器
*
* @author 呆猫
* @since 2024-04-01
*/
@Component
public class SQLiteDdlGenerator implements IDdlGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,15 @@ public static IDialect getDialect(DbType dbType) {
throw ExceptionUtils.mpe("%s database not supported.", dbType.getDb());
}
// mysql same type
else if (dbType == DbType.MYSQL
|| dbType == DbType.MARIADB
|| dbType == DbType.GBASE
|| dbType == DbType.OSCAR
|| dbType == DbType.XU_GU
|| dbType == DbType.CLICK_HOUSE
|| dbType == DbType.OCEAN_BASE
|| dbType == DbType.CUBRID
|| dbType == DbType.SUNDB) {
else if (dbType.mysqlSameType()) {
dialect = new MySqlDialect();
}
// oracle same type
else if (dbType == DbType.ORACLE
|| dbType == DbType.DM
|| dbType == DbType.GAUSS) {
else if (dbType.oracleSameType()) {
dialect = new OracleDialect();
}
// postgresql same type
else if (dbType == DbType.POSTGRE_SQL
|| dbType == DbType.H2
|| dbType == DbType.LEALONE
|| dbType == DbType.SQLITE
|| dbType == DbType.HSQL
|| dbType == DbType.KINGBASE_ES
|| dbType == DbType.PHOENIX
|| dbType == DbType.SAP_HANA
|| dbType == DbType.IMPALA
|| dbType == DbType.HIGH_GO
|| dbType == DbType.VERTICA
|| dbType == DbType.REDSHIFT
|| dbType == DbType.OPENGAUSS
|| dbType == DbType.TDENGINE
|| dbType == DbType.UXDB
|| dbType == DbType.GBASE8S_PG
|| dbType == DbType.GBASE_8C) {
else if (dbType.postgresqlSameType()) {
dialect = new PostgreDialect();
}
// other types
Expand Down

0 comments on commit 95a196f

Please sign in to comment.