update 优化 适配 anyline 新改动

2.X
疯狂的狮子Li 6 months ago
parent a87c14b40d
commit 8d874ba759

@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.anyline.data.datasource.DataSourceMonitor;
import org.anyline.data.runtime.DataRuntime;
import org.anyline.util.ConfigTable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
@ -41,7 +42,7 @@ public class MyBatisDataSourceMonitor implements DataSourceMonitor {
* @return String null
*/
@Override
public String feature(Object datasource) {
public String feature(DataRuntime runtime, Object datasource) {
String feature = null;
if (datasource instanceof JdbcTemplate jdbc) {
DataSource ds = jdbc.getDataSource();
@ -69,6 +70,22 @@ public class MyBatisDataSourceMonitor implements DataSourceMonitor {
return feature;
}
/**
* feature
* @param datasource
* @return String null
*/
@Override
public String key(DataRuntime runtime, Object datasource) {
if(datasource instanceof JdbcTemplate jdbc){
DataSource ds = jdbc.getDataSource();
if(ds instanceof DynamicRoutingDataSource){
return DynamicDataSourceContextHolder.peek();
}
}
return runtime.getKey();
}
/**
* ConfigTable.KEEP_ADAPTER=2 : adapter<br/>
* DynamicRoutingDataSourcefalse,DynamicRoutingDataSource, true
@ -77,7 +94,7 @@ public class MyBatisDataSourceMonitor implements DataSourceMonitor {
* @return boolean
*/
@Override
public boolean keepAdapter(Object datasource) {
public boolean keepAdapter(DataRuntime runtime, Object datasource) {
if (datasource instanceof JdbcTemplate jdbc) {
DataSource ds = jdbc.getDataSource();
return !(ds instanceof DynamicRoutingDataSource);

Loading…
Cancel
Save