diff --git a/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java b/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java
new file mode 100644
index 0000000000000000000000000000000000000000..730c1074dd1c4be45c496419482e234a5061e9b5
--- /dev/null
+++ b/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.tenant.api.database;
+
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.auth.core.AuthAction;
+import neatlogic.framework.auth.label.DATA_WAREHOUSE_MODIFY;
+import neatlogic.framework.common.constvalue.ApiParamType;
+import neatlogic.framework.datawarehouse.utils.DriverHolder;
+import neatlogic.framework.restful.annotation.*;
+import neatlogic.framework.restful.constvalue.OperationTypeEnum;
+import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase;
+import org.springframework.stereotype.Service;
+
+@Service
+@AuthAction(action = DATA_WAREHOUSE_MODIFY.class)
+@OperationType(type = OperationTypeEnum.OPERATE)
+public class DestroyDataBaseDriverApi extends PrivateApiComponentBase {
+
+ @Override
+ public String getName() {
+ return "卸载数据库驱动";
+ }
+
+ @Input({
+ @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id")
+ })
+ @Output({})
+ @Description(desc = "卸载数据库驱动")
+ @Override
+ public Object myDoService(JSONObject paramObj) throws Exception {
+ Long id = paramObj.getLong("id");
+ DriverHolder.destroyDriver(id);
+ return null;
+ }
+
+ @Override
+ public String getToken() {
+ return "database/destroy";
+ }
+}
diff --git a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java
index e254d47a819007dc6ef46885718b6600f218518a..31acf784bfcd3d95908aa6a94830b1254282924b 100644
--- a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java
+++ b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java
@@ -21,16 +21,26 @@ import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.auth.core.AuthAction;
import neatlogic.framework.auth.label.DATA_WAREHOUSE_MODIFY;
import neatlogic.framework.common.constvalue.ApiParamType;
+import neatlogic.framework.datawarehouse.dao.mapper.DatabaseMapper;
import neatlogic.framework.datawarehouse.dto.DatabaseVo;
-import neatlogic.framework.datawarehouse.service.DatabaseService;
+import neatlogic.framework.datawarehouse.exceptions.DatabaseConnectionFailedException;
+import neatlogic.framework.datawarehouse.exceptions.DatabaseNotFoundException;
+import neatlogic.framework.datawarehouse.utils.DriverHolder;
+import neatlogic.framework.file.dao.mapper.FileMapper;
+import neatlogic.framework.file.dto.FileVo;
import neatlogic.framework.restful.annotation.*;
import neatlogic.framework.restful.constvalue.OperationTypeEnum;
import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
-import java.net.URLClassLoader;
import java.sql.Connection;
+import java.sql.Driver;
+import java.util.List;
+import java.util.Properties;
@Service
@AuthAction(action = DATA_WAREHOUSE_MODIFY.class)
@@ -38,7 +48,10 @@ import java.sql.Connection;
public class TestDataBaseApi extends PrivateApiComponentBase {
@Resource
- private DatabaseService databaseService;
+ private DatabaseMapper databaseMapper;
+
+ @Resource
+ private FileMapper fileMapper;
@Override
public String getName() {
@@ -55,15 +68,38 @@ public class TestDataBaseApi extends PrivateApiComponentBase {
@Override
public Object myDoService(JSONObject paramObj) throws Exception {
Long id = paramObj.getLong("id");
- Connection conn = databaseService.getConnectionByDatabaseId(id);
- if (conn != null) {
- ClassLoader classLoader = conn.getClass().getClassLoader();
- conn.close();
- if (classLoader instanceof URLClassLoader) {
- ((URLClassLoader) classLoader).close();
+ DatabaseVo databaseVo = databaseMapper.getDataBaseById(id);
+ if (databaseVo == null) {
+ throw new DatabaseNotFoundException(id);
+ }
+ List fileIdList = databaseVo.getFileIdList();
+ if (CollectionUtils.isNotEmpty(fileIdList)) {
+ List fileList = fileMapper.getFileListByIdList(fileIdList);
+ databaseVo.setFileList(fileList);
+ } else {
+ throw new DatabaseConnectionFailedException(DatabaseConnectionFailedException.Type.FILE_ID_LIST_IS_EMPTY, databaseVo.getName());
+ }
+ Driver driver = DriverHolder.borrowDriver(databaseVo);
+ JSONObject config = databaseVo.getConfig();
+ if (MapUtils.isNotEmpty(config)) {
+ String user = config.getString("user");
+ String password = config.getString("password");
+ String url = config.getString("url");
+ Properties props = new Properties();
+ if (StringUtils.isNoneBlank(user)) {
+ props.put("user", user);
+ }
+ if (StringUtils.isNotBlank(password)) {
+ props.put("password", password);
+ }
+ Connection conn = driver.connect(url, props);
+ if (conn != null) {
+ conn.close();
}
+ return null;
+ } else {
+ throw new DatabaseConnectionFailedException(DatabaseConnectionFailedException.Type.CONFIG_IS_EMPTY, databaseVo.getName());
}
- return null;
}
@Override