From 7289f698e5e4ab2e866ad6e592593be8187c6dd8 Mon Sep 17 00:00:00 2001 From: lijing03 <1481281891@qq.com> Date: Mon, 25 May 2026 09:08:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=90=AF=E7=94=A8ob=20mysql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataaccess/mysql/MySqlConfigData.java | 2 +- .../edp/caf/data/setting/CheckObMysql.java | 30 +++++++++++++++ .../edp/caf/data/setting/ObMySqlSetting.java | 9 +++++ .../data/source/DataSourceTypeRecognizer.java | 7 +++- .../data/source/DbConfigDataConvertor.java | 38 ++++++++++++------- .../source/RelationalServiceInfoFactory.java | 21 ++++++++-- 6 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java create mode 100644 caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/commons/dataaccess/mysql/MySqlConfigData.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/commons/dataaccess/mysql/MySqlConfigData.java index 808f954e1..1140327bf 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/commons/dataaccess/mysql/MySqlConfigData.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/commons/dataaccess/mysql/MySqlConfigData.java @@ -37,4 +37,4 @@ public class MySqlConfigData extends GSPDbConfigData { super(); this.setDbType(DbType.MySQL); } -} \ No newline at end of file +} diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java new file mode 100644 index 000000000..4bf09b352 --- /dev/null +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java @@ -0,0 +1,30 @@ +package io.iec.edp.caf.data.setting; + +import io.iec.edp.caf.commons.core.SerializerFactory; +import io.iec.edp.caf.commons.core.enums.SerializeType; +import io.iec.edp.caf.commons.runtime.CafEnvironment; +import io.iec.edp.caf.commons.runtime.FileOperator; + +import java.io.File; + +public class CheckObMysql { + private static final String settingFileName = "caf_oceanbase_mysql.json"; + public static boolean enableObMysql(){ + String filePath = CafEnvironment.getServerRTPath() + File.separator + "config" + + File.separator + "runtime" + File.separator + settingFileName; + String settingJson = FileOperator.readToBuffer(filePath); + ObMySqlSetting setting = null; + if(settingJson!=null) { + setting = SerializerFactory.getDeserializer(SerializeType.Json).deserialize(settingJson, ObMySqlSetting.class); + } + if (setting != null){ + if (setting.getEnableObMysql()) { + return true; + }else{ + return false; + } + } else { + return false; + } + } +} diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java new file mode 100644 index 000000000..b5c24bcc6 --- /dev/null +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java @@ -0,0 +1,9 @@ +package io.iec.edp.caf.data.setting; + +import lombok.Data; + + +@Data +public class ObMySqlSetting { + private Boolean enableObMysql; +} diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DataSourceTypeRecognizer.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DataSourceTypeRecognizer.java index c6fba8cc5..ebe271311 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DataSourceTypeRecognizer.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DataSourceTypeRecognizer.java @@ -19,6 +19,7 @@ package io.iec.edp.caf.data.source; import com.zaxxer.hikari.HikariConfig; import io.iec.edp.caf.commons.dataaccess.DbType; import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import io.iec.edp.caf.data.setting.CheckObMysql; import lombok.var; /** @@ -63,7 +64,11 @@ public class DataSourceTypeRecognizer { //可能判断不了 og使用的pg的url return DbType.OpenGauss; } else if(jdbcUrl.indexOf("oceanbase") !=-1){ - return DbType.OceanBase; + if (CheckObMysql.enableObMysql()) { + return DbType.MySQL;//开启oceanbase mysql后,数据库类型仍为MySQL + }else{ + return DbType.OceanBase; + } } else if(jdbcUrl.indexOf("gbase8s") !=-1){ return DbType.GBase8s; } else if(jdbcUrl.indexOf("gbase8c") !=-1){ diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DbConfigDataConvertor.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DbConfigDataConvertor.java index 51f308832..55d67e72e 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DbConfigDataConvertor.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/DbConfigDataConvertor.java @@ -35,6 +35,7 @@ import io.iec.edp.caf.commons.dataaccess.pgsql.PostgreSQLConfigData; import io.iec.edp.caf.commons.dataaccess.sqlserver.SqlConnectionStringBuilder; import io.iec.edp.caf.commons.dataaccess.sqlserver.SqlDbConfigData; import io.iec.edp.caf.commons.utils.StringUtils; +import io.iec.edp.caf.data.setting.CheckObMysql; import io.iec.edp.caf.data.source.db2.DB2ServiceInfo; import io.iec.edp.caf.data.source.dm.DmServiceInfo; import io.iec.edp.caf.data.source.gauss.GaussDB4PgServiceInfo; @@ -62,7 +63,7 @@ public class DbConfigDataConvertor { /** * 将EcpDbConnection中的连接字符串转为jdbcUrl格式 - * @param configData + * @param configData * @return */ public static JDBCConnectionInfo convert(SimpleDbConfigData configData){ @@ -71,15 +72,15 @@ public class DbConfigDataConvertor { JDBCConnectionInfo info = null; if(configData.getConnectionString().startsWith("jdbc:")){ - //解密UriString - String uriString = UriDecryptor.decrypt(configData.getConnectionString()); - RelationalServiceInfo serviceInfo = RelationalServiceInfoFactory.create(uriString); + //解密UriString + String uriString = UriDecryptor.decrypt(configData.getConnectionString()); + RelationalServiceInfo serviceInfo = RelationalServiceInfoFactory.create(uriString); info = JDBCConnectionInfo.builder() - .jdbcUrl(serviceInfo.getJdbcUrl()) - .userName(serviceInfo.getUserName()) - .password(serviceInfo.getPassword()) - .driverClassName(serviceInfo.getDriverClassName()) - .build(); + .jdbcUrl(serviceInfo.getJdbcUrl()) + .userName(serviceInfo.getUserName()) + .password(serviceInfo.getPassword()) + .driverClassName(serviceInfo.getDriverClassName()) + .build(); }else if(configData.getConnectionString().startsWith("custom:")){ //custom开头的是对CustomConnectionInfo(只塞上jdbcUrl,username,password值)对象序列化后加密的 //解密UriString @@ -249,9 +250,15 @@ public class DbConfigDataConvertor { url = String.format(url,configData.getSource(),configData.getCatalog()); break; case MySQL: - url = "jdbc:mysql://%s/%s?characterEncoding=utf8&useSSL=false"; - driverName= MysqlServiceInfo.MYSQL_DRIVER_CLASS_NAME; - url = String.format(url,configData.getSource(),configData.getCatalog()); + // 判断是否启用 MySQL 到 OceanBase MySQL 模式的切换 + if (CheckObMysql.enableObMysql()) { + url = "jdbc:oceanbase://%s/%s"; + driverName = OceanBaseServiceInfo.OCEANBASE_DRIVER_CLASS_NAME; + } else { + url = "jdbc:mysql://%s/%s?characterEncoding=utf8&useSSL=false"; + driverName = MysqlServiceInfo.MYSQL_DRIVER_CLASS_NAME; + } + url = String.format(url, configData.getSource(), configData.getCatalog()); break; case Oscar: url = "jdbc:oscar://%s/%s"; @@ -335,7 +342,12 @@ public class DbConfigDataConvertor { driverName= HighGoServiceInfo.HIGHGO_DRIVER_CLASS_NAME; break; case MySQL: - driverName= MysqlServiceInfo.MYSQL_DRIVER_CLASS_NAME; + // 判断是否启用 MySQL 到 OceanBase MySQL 模式的切换 + if (CheckObMysql.enableObMysql()) { + driverName = OceanBaseServiceInfo.OCEANBASE_DRIVER_CLASS_NAME; + } else { + driverName = MysqlServiceInfo.MYSQL_DRIVER_CLASS_NAME; + } break; case Oscar: driverName= OscarServiceInfo.OSCAR_DRIVER_CLASS_NAME; diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/RelationalServiceInfoFactory.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/RelationalServiceInfoFactory.java index 50b42adda..4539d1b87 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/RelationalServiceInfoFactory.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/source/RelationalServiceInfoFactory.java @@ -17,6 +17,7 @@ package io.iec.edp.caf.data.source; import io.iec.edp.caf.commons.dataaccess.DbType; +import io.iec.edp.caf.data.setting.CheckObMysql; import io.iec.edp.caf.data.source.db2.DB2ServiceInfo; import io.iec.edp.caf.data.source.dm.DmServiceInfo; import io.iec.edp.caf.data.source.gauss.GaussDB4PgServiceInfo; @@ -68,7 +69,11 @@ public class RelationalServiceInfoFactory { serviceInfo = new KingbaseServiceInfo(uriString); break; case MysqlServiceInfo.MYSQL_SCHEME: - serviceInfo = new MysqlServiceInfo(uriString); + if (CheckObMysql.enableObMysql()) { + serviceInfo = new OceanBaseServiceInfo(uriString); + } else { + serviceInfo = new MysqlServiceInfo(uriString); + } break; case OracleServiceInfo.ORACLE_SCHEME: serviceInfo = new OracleServiceInfo(uriString); @@ -139,7 +144,12 @@ public class RelationalServiceInfoFactory { serviceInfo = new KingbaseServiceInfo(host,port,userName,password,database,query); break; case MySQL: - serviceInfo = new MysqlServiceInfo(host,port,userName,password,database,query); + // 判断是否启用 MySQL 到 OceanBase MySQL 模式的切换 + if (CheckObMysql.enableObMysql()) { + serviceInfo = new OceanBaseServiceInfo(host, port, userName, password, database, query); + } else { + serviceInfo = new MysqlServiceInfo(host, port, userName, password, database, query); + } break; case Oracle: serviceInfo = new OracleServiceInfo(host,port,userName,password,database,query); @@ -195,7 +205,12 @@ public class RelationalServiceInfoFactory { serviceInfo = new KingbaseServiceInfo(jdbcUrl, userName, password); break; case MySQL: - serviceInfo = new MysqlServiceInfo(jdbcUrl, userName, password); + // 判断是否启用 MySQL 到 OceanBase MySQL 模式的切换 + if (CheckObMysql.enableObMysql()) { + serviceInfo = new OceanBaseServiceInfo(jdbcUrl, userName, password); + } else { + serviceInfo = new MysqlServiceInfo(jdbcUrl, userName, password); + } break; case Oracle: serviceInfo = new OracleServiceInfo(jdbcUrl, userName, password); -- Gitee From 0626d858dea89360af7bca2c2f1a2080323cde59 Mon Sep 17 00:00:00 2001 From: lijing03 <1481281891@qq.com> Date: Fri, 5 Jun 2026 09:12:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edp/caf/data/setting/CheckObMysql.java | 30 +++++-------------- .../edp/caf/data/setting/ObMySqlSetting.java | 9 ------ 2 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java index 4bf09b352..d2ddc4e8b 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java @@ -1,30 +1,16 @@ package io.iec.edp.caf.data.setting; -import io.iec.edp.caf.commons.core.SerializerFactory; -import io.iec.edp.caf.commons.core.enums.SerializeType; -import io.iec.edp.caf.commons.runtime.CafEnvironment; -import io.iec.edp.caf.commons.runtime.FileOperator; +import org.springframework.beans.factory.annotation.Value; + -import java.io.File; public class CheckObMysql { - private static final String settingFileName = "caf_oceanbase_mysql.json"; + @Value("${database.distributedObMysql:false}") + private static Boolean distributedObMysql; + public static boolean enableObMysql(){ - String filePath = CafEnvironment.getServerRTPath() + File.separator + "config" + - File.separator + "runtime" + File.separator + settingFileName; - String settingJson = FileOperator.readToBuffer(filePath); - ObMySqlSetting setting = null; - if(settingJson!=null) { - setting = SerializerFactory.getDeserializer(SerializeType.Json).deserialize(settingJson, ObMySqlSetting.class); - } - if (setting != null){ - if (setting.getEnableObMysql()) { - return true; - }else{ - return false; - } - } else { - return false; - } + + return distributedObMysql; + } } diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java deleted file mode 100644 index b5c24bcc6..000000000 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/ObMySqlSetting.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.iec.edp.caf.data.setting; - -import lombok.Data; - - -@Data -public class ObMySqlSetting { - private Boolean enableObMysql; -} -- Gitee From 585e2a95e54813a8701040636d5a91480a930390 Mon Sep 17 00:00:00 2001 From: lijing03 <1481281891@qq.com> Date: Fri, 5 Jun 2026 11:44:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/setting/CafDatabaseExtConfig.java | 53 +++++++++++++ .../edp/caf/data/setting/CheckObMysql.java | 75 +++++++++++++++++-- .../edp/caf/data/setting/DatabaseConfig.java | 61 +++++++++++++++ 3 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CafDatabaseExtConfig.java create mode 100644 caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/DatabaseConfig.java diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CafDatabaseExtConfig.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CafDatabaseExtConfig.java new file mode 100644 index 000000000..ec7b353fd --- /dev/null +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CafDatabaseExtConfig.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd. + * + * 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 io.iec.edp.caf.data.setting; + +import java.util.Map; + +public class CafDatabaseExtConfig { + + /** + * 数据库扩展配置Map,key为数据库标识(如 obmysql、gaussdb),value为对应配置 + */ + private Map databases; + + public Map getDatabases() { + return databases; + } + + public void setDatabases(Map databases) { + this.databases = databases; + } + + /** + * 判断指定数据库的扩展功能是否启用 + * @param dbKey 数据库标识,如 "obmysql"、"gaussdb" + * @return true表示已启用 + */ + public boolean isEnableDistributed(String dbKey) { + DatabaseConfig config = getDatabaseConfig(dbKey); + return config != null && config.isEnableDistributed(); + } + + + private DatabaseConfig getDatabaseConfig(String dbKey) { + if (databases == null || dbKey == null) { + return null; + } + return databases.get(dbKey); + } +} diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java index d2ddc4e8b..2d63fd8a1 100644 --- a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/CheckObMysql.java @@ -1,16 +1,79 @@ -package io.iec.edp.caf.data.setting; +/* + * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd. + * + * 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. + */ -import org.springframework.beans.factory.annotation.Value; +package io.iec.edp.caf.data.setting; +import io.iec.edp.caf.commons.core.SerializerFactory; +import io.iec.edp.caf.commons.core.enums.SerializeType; +import io.iec.edp.caf.commons.runtime.CafEnvironment; +import io.iec.edp.caf.commons.runtime.FileOperator; +import java.io.File; +/** + * 数据库扩展配置检查器,从 caf_database_ext.json 读取所有数据库的扩展配置。 + *

+ * 支持的能力: + *

    + *
  • OceanBase MySQL 分布式模式开关
  • + *
  • GaussDB 分布式模式开关
  • + *
  • 未来可通过 JSON 扩展任意数据库特有配置
  • + *
+ * + *

JSON 配置示例

+ *
+ * {
+ *   "databases": {
+ *     "obmysql": {
+ *       "enableDistributed": true,
+ *       "properties": {}
+ *     },
+ *     "gaussdb": {
+ *       "enableDistributed": true,
+ *       "properties": {
+ *         "xx": false
+ *       }
+ *     }
+ *   }
+ * }
+ * 
+ */ public class CheckObMysql { - @Value("${database.distributedObMysql:false}") - private static Boolean distributedObMysql; - public static boolean enableObMysql(){ + private static final String SETTING_FILE_NAME = "caf_database_ext.json"; + + public static final String DB_KEY_OB_MYSQL = "obmysql"; - return distributedObMysql; + /** + * 类加载时一次性初始化,有缓存 + */ + private static final CafDatabaseExtConfig CONFIG = loadConfig(); + + public static boolean enableObMysql() { + return CONFIG.isEnableDistributed(DB_KEY_OB_MYSQL); + } + private static CafDatabaseExtConfig loadConfig() { + String filePath = CafEnvironment.getServerRTPath() + File.separator + "config" + + File.separator + "runtime" + File.separator + SETTING_FILE_NAME; + String settingJson = FileOperator.readToBuffer(filePath); + if (settingJson == null || settingJson.trim().isEmpty()) { + return new CafDatabaseExtConfig(); + } + return SerializerFactory.getDeserializer(SerializeType.Json) + .deserialize(settingJson, CafDatabaseExtConfig.class); } } diff --git a/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/DatabaseConfig.java b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/DatabaseConfig.java new file mode 100644 index 000000000..0568428de --- /dev/null +++ b/caf-data/caf-data-jdbc/src/main/java/io/iec/edp/caf/data/setting/DatabaseConfig.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd. + * + * 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 io.iec.edp.caf.data.setting; + +import java.util.Map; + +/** + * { + * "databases": { + * "obmysql": { + * "enableDistributed": false, + * "properties": {} + * }, + * "gaussdb": { + * "enableDistributed": false, + * "properties": { + * "xx": true + * } + * } + * } + * } + */ +public class DatabaseConfig { + + private boolean enableDistributed = false; + + //代码先兼容后续添加其他配置,提交的配置文件先不体现 + private Map properties; + + public boolean isEnableDistributed() { + return enableDistributed; + } + + public void setEnableDistributed(boolean enableDistributed) { + this.enableDistributed = enableDistributed; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + +} -- Gitee