Browse Source

增加Firebird数据库支持

steven.ma 4 years ago
parent
commit
8ec3fa5528

+ 4 - 0
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/DbType.java

@@ -112,6 +112,10 @@ public enum DbType {
      * OceanBase
      */
     OCEAN_BASE("oceanbase", "OceanBase 数据库"),
+    /**
+     * Firebird
+     */
+    FIREBIRD("Firebird", "Firebird 数据库"),
     /**
      * UNKONWN DB
      */

+ 4 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java

@@ -138,7 +138,10 @@ public class DataSourceConfig {
             return DbType.GAUSS;
         } else if (str.contains("oscar")) {
             return DbType.OSCAR;
-        } else {
+        } else if (str.contains("firebird")) {
+            return DbType.FIREBIRD;
+        }
+        else {
             return DbType.OTHER;
         }
     }

+ 89 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/FirebirdTypeConvert.java

@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.generator.config.converts;
+
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.ITypeConvert;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
+
+import static com.baomidou.mybatisplus.generator.config.converts.TypeConverts.contains;
+import static com.baomidou.mybatisplus.generator.config.converts.TypeConverts.containsAny;
+import static com.baomidou.mybatisplus.generator.config.rules.DbColumnType.*;
+
+/**
+ * MYSQL 数据库字段类型转换
+ *
+ * @author hubin, hanchunlin
+ * @since 2017-01-20
+ */
+public class FirebirdTypeConvert implements ITypeConvert {
+    public static final FirebirdTypeConvert INSTANCE = new FirebirdTypeConvert();
+
+    /**
+     * @inheritDoc
+     */
+    @Override
+    public IColumnType processTypeConvert(GlobalConfig config, String fieldType) {
+        return TypeConverts.use(fieldType)
+            .test(containsAny("cstring", "text").then(STRING))
+            .test(contains("short").then(SHORT))
+            .test(contains("long").then(LONG))
+            .test(contains("float").then(FLOAT))
+            .test(contains("double").then(DOUBLE))
+            .test(contains("blob").then(BLOB))
+            .test(contains("int64").then(LONG))
+            .test(containsAny("date", "time", "year").then(t -> toDateType(config, t)))
+            .or(STRING);
+    }
+
+    /**
+     * 转换为日期类型
+     *
+     * @param config 配置信息
+     * @param type   类型
+     * @return 返回对应的列类型
+     */
+    public static IColumnType toDateType(GlobalConfig config, String type) {
+        switch (config.getDateType()) {
+            case ONLY_DATE:
+                return DbColumnType.DATE;
+            case SQL_PACK:
+                switch (type) {
+                    case "date":
+                    case "year":
+                        return DbColumnType.DATE_SQL;
+                    case "time":
+                        return DbColumnType.TIME;
+                    default:
+                        return DbColumnType.TIMESTAMP;
+                }
+            case TIME_PACK:
+                switch (type) {
+                    case "date":
+                        return DbColumnType.LOCAL_DATE;
+                    case "time":
+                        return DbColumnType.LOCAL_TIME;
+                    case "year":
+                        return DbColumnType.YEAR;
+                    default:
+                        return DbColumnType.LOCAL_DATE_TIME;
+                }
+        }
+        return STRING;
+    }
+
+}

+ 2 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/TypeConverts.java

@@ -57,6 +57,8 @@ public class TypeConverts {
                 return SqliteTypeConvert.INSTANCE;
             case SQL_SERVER:
                 return SqlServerTypeConvert.INSTANCE;
+            case FIREBIRD:
+                return FirebirdTypeConvert.INSTANCE;
         }
         return null;
     }

+ 1 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DbQueryRegistry.java

@@ -43,6 +43,7 @@ public class DbQueryRegistry {
         db_query_enum_map.put(DbType.MYSQL, new MySqlQuery());
         db_query_enum_map.put(DbType.GAUSS, new GaussQuery());
         db_query_enum_map.put(DbType.OSCAR, new OscarQuery());
+        db_query_enum_map.put(DbType.FIREBIRD, new FirebirdQuery());
     }
 
     public IDbQuery getDbQuery(DbType dbType) {

+ 88 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/FirebirdQuery.java

@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.generator.config.querys;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * MySql 表数据查询
+ *
+ * @author steven ma
+ * @since 2020-08-20
+ */
+public class FirebirdQuery extends AbstractDbQuery {
+
+    @Override
+    public String tablesSql() {
+        return "select rdb$relation_name as NAME " +
+            "from rdb$relations " +
+            "where rdb$view_blr is null " +
+            "and (rdb$system_flag is null or rdb$system_flag = 0)";
+    }
+
+
+    @Override
+    public String tableFieldsSql() {
+        return "select f.rdb$relation_name AS NAME, f.rdb$field_name AS FIELD, t.rdb$type_name AS  TYPE " +
+            "from rdb$relation_fields f " +
+            "join rdb$relations r on f.rdb$relation_name = r.rdb$relation_name " +
+            "JOIN rdb$fields fs ON f.rdb$field_source = fs.rdb$field_name " +
+            "JOIN rdb$types  t ON fs.rdb$field_type = t.rdb$type " +
+            "and r.rdb$view_blr is NULL " +
+            "AND t.rdb$field_name = 'RDB$FIELD_TYPE' " +
+            "and (r.rdb$system_flag is null or r.rdb$system_flag = 0) " +
+            "AND f.rdb$relation_name = `%s` " +
+            "order by 1, f.rdb$field_position";
+    }
+
+
+    @Override
+    public String tableName() {
+        return "NAME";
+    }
+
+
+    @Override
+    public String tableComment() {
+        return "COMMENT";
+    }
+
+
+    @Override
+    public String fieldName() {
+        return "FIELD";
+    }
+
+
+    @Override
+    public String fieldType() {
+        return "TYPE";
+    }
+
+
+    @Override
+    public String fieldComment() {
+        return "COMMENT";
+    }
+
+
+    @Override
+    public String fieldKey() {
+        return "KEY";
+    }
+
+}