Support for custom drivers

This commit is contained in:
jipengfei-jpf
2023-06-23 15:54:53 +08:00
parent 63d002df55
commit 150d1399a6

View File

@ -46,7 +46,7 @@ public class Chat2DBContext {
} }
} }
public static DriverConfig getDefaultDriverConfig(String dbType){ public static DriverConfig getDefaultDriverConfig(String dbType) {
return PLUGIN_MAP.get(dbType).getDBConfig().getDefaultDriverConfig(); return PLUGIN_MAP.get(dbType).getDBConfig().getDefaultDriverConfig();
} }
@ -63,7 +63,7 @@ public class Chat2DBContext {
return PLUGIN_MAP.get(getConnectInfo().getDbType()).getMetaData(); return PLUGIN_MAP.get(getConnectInfo().getDbType()).getMetaData();
} }
public static DBConfig getDBConfig(){ public static DBConfig getDBConfig() {
return PLUGIN_MAP.get(getConnectInfo().getDbType()).getDBConfig(); return PLUGIN_MAP.get(getConnectInfo().getDbType()).getDBConfig();
} }
@ -103,9 +103,15 @@ public class Chat2DBContext {
if (session != null) { if (session != null) {
url = url.replace(host, "127.0.0.1").replace(port, ssh.getLocalPort()); url = url.replace(host, "127.0.0.1").replace(port, ssh.getLocalPort());
} }
DriverConfig config = connectInfo.getDriverConfig();
if (config == null) {
config = getDefaultDriverConfig(connectInfo.getDbType());
connectInfo.setDriverConfig(config);
}
connection = getConnect(url, host, port, connectInfo.getUser(), connection = getConnect(url, host, port, connectInfo.getUser(),
connectInfo.getPassword(), connectInfo.getDbType(), connectInfo.getPassword(), connectInfo.getDbType(),
connectInfo.getDriverConfig(), ssh, connectInfo.getExtendMap()); connectInfo.getDriverConfig(), ssh, connectInfo.getExtendMap());
} catch (Exception e1) { } catch (Exception e1) {
log.error("getConnect error", e1); log.error("getConnect error", e1);
if (connection != null) { if (connection != null) {
@ -139,8 +145,8 @@ public class Chat2DBContext {
* @return * @return
*/ */
private static Connection getConnect(String url, String host, String port, private static Connection getConnect(String url, String host, String port,
String userName, String password, String dbType, String userName, String password, String dbType,
DriverConfig jdbc, SSHInfo ssh, Map<String, Object> properties) throws SQLException { DriverConfig jdbc, SSHInfo ssh, Map<String, Object> properties) throws SQLException {
// 创建连接 // 创建连接
return IDriverManager.getConnection(url, userName, password, jdbc, properties); return IDriverManager.getConnection(url, userName, password, jdbc, properties);