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

Loading…
Cancel
Save