提交 4d9fd87f authored 作者: Matrix's avatar Matrix

fix(SQL执行器): 修复了数据源切换的问题

上级 6cb493c9
......@@ -124,7 +124,7 @@ public class CheckPointActuator implements Actuator {
);
}
} catch (ScriptException e) {
throw new CheckPointException("初始化js引擎失败");
throw new CheckPointException("初始化js引擎失败" + e);
}
}
......
......@@ -12,6 +12,12 @@ import java.util.Set;
public interface IDataSourceService {
/**
* 切换回主数据源
* @return 是否切换成功
*/
boolean switchMainDataSource();
/**
* 将当前使用的数据替换为参数提供的数据源,如果还没有,则会添加,如果已经有了,则不会添加
*
......
......@@ -30,6 +30,17 @@ public class IDataSourceServiceImpl implements IDataSourceService {
this.dataSourceCreator = dataSourceCreator;
}
/**
* 切换回主数据源
*
* @return 是否切换成功
*/
@Override
public boolean switchMainDataSource() {
DynamicDataSourceContextHolder.push("master");
return true;
}
/**
* 将当前使用的数据替换为参数提供的数据源,如果还没有,则会添加,如果已经有了,则不会添加
*
......
......@@ -229,7 +229,10 @@ public class SqlExpActuator implements Actuator {
// 切换数据源,执行SQL,获取数值
Set<String> dataSources = dataSourceService.switchDataSource(dataSourceDTO);
log.info("当前存在的数据源 {}", dataSources);
return jdbcTemplate.queryForList(sqlExp);
List<Map<String, Object>> resultMap = jdbcTemplate.queryForList(sqlExp);
dataSourceService.switchMainDataSource();
return resultMap;
} else {
throw new GlobalException(String.format("动态变量的类型必须要是SQL类型且DETAIL内的SQL语句必须为元SQL语句,当前type : %s , 当前detail : %s",
......
......@@ -25,7 +25,7 @@ class CaseActuatorTest {
1l
);
String json = "{\n" +
" \"url\":\"http://127.0.0.1:13245/test/sayHelloJson\",\n" +
" \"url\":\"http://192.168.102.223:13245/test/sayHelloJson\",\n" +
" \"method\":\"POST\",\n" +
" \"requestType\":\"JSON\",\n" +
" \"stringValue\":\"{\\\"name\\\":\\\"${componentName}[0]\\\"}\",\n" +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论