mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update anyline 8.7.2-20240726
This commit is contained in:
		
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -51,7 +51,7 @@
 | 
				
			|||||||
        <!-- 限制框架中的fastjson版本 -->
 | 
					        <!-- 限制框架中的fastjson版本 -->
 | 
				
			||||||
        <fastjson.version>1.2.83</fastjson.version>
 | 
					        <fastjson.version>1.2.83</fastjson.version>
 | 
				
			||||||
        <!-- 面向运行时的D-ORM依赖 -->
 | 
					        <!-- 面向运行时的D-ORM依赖 -->
 | 
				
			||||||
        <anyline.version>8.7.2-20240722</anyline.version>
 | 
					        <anyline.version>8.7.2-20240726</anyline.version>
 | 
				
			||||||
        <!--工作流配置-->
 | 
					        <!--工作流配置-->
 | 
				
			||||||
        <flowable.version>7.0.1</flowable.version>
 | 
					        <flowable.version>7.0.1</flowable.version>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					package org.dromara.generator.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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.util.ConfigTable;
 | 
				
			||||||
 | 
					import org.springframework.jdbc.core.JdbcTemplate;
 | 
				
			||||||
 | 
					import org.springframework.jdbc.datasource.DataSourceUtils;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.sql.DataSource;
 | 
				
			||||||
 | 
					import java.sql.Connection;
 | 
				
			||||||
 | 
					import java.sql.DatabaseMetaData;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Slf4j
 | 
				
			||||||
 | 
					@Component
 | 
				
			||||||
 | 
					public class MyBatisDataSourceMonitor implements DataSourceMonitor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public MyBatisDataSourceMonitor() {
 | 
				
			||||||
 | 
					        // 调整执行模式为自定义
 | 
				
			||||||
 | 
					        ConfigTable.KEEP_ADAPTER = 2;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final Map<String, String> features = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 数据源特征 用来定准 adapter 包含数据库或JDBC协议关键字<br/>
 | 
				
			||||||
 | 
					     * 一般会通过 产品名_url 合成 如果返回null 上层方法会通过driver_产品名_url合成
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param datasource 数据源
 | 
				
			||||||
 | 
					     * @return String 返回null由上层自动提取
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String feature(Object datasource) {
 | 
				
			||||||
 | 
					        String feature = null;
 | 
				
			||||||
 | 
					        if (datasource instanceof JdbcTemplate jdbc) {
 | 
				
			||||||
 | 
					            DataSource ds = jdbc.getDataSource();
 | 
				
			||||||
 | 
					            if (ds instanceof DynamicRoutingDataSource) {
 | 
				
			||||||
 | 
					                String key = DynamicDataSourceContextHolder.peek();
 | 
				
			||||||
 | 
					                feature = features.get(key);
 | 
				
			||||||
 | 
					                if (null == feature) {
 | 
				
			||||||
 | 
					                    Connection con = null;
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        con = DataSourceUtils.getConnection(ds);
 | 
				
			||||||
 | 
					                        DatabaseMetaData meta = con.getMetaData();
 | 
				
			||||||
 | 
					                        String url = meta.getURL();
 | 
				
			||||||
 | 
					                        feature = meta.getDatabaseProductName().toLowerCase().replace(" ", "") + "_" + url;
 | 
				
			||||||
 | 
					                        features.put(key, feature);
 | 
				
			||||||
 | 
					                    } catch (Exception e) {
 | 
				
			||||||
 | 
					                        log.error(e.getMessage(), e);
 | 
				
			||||||
 | 
					                    } finally {
 | 
				
			||||||
 | 
					                        if (null != con && !DataSourceUtils.isConnectionTransactional(con, ds)) {
 | 
				
			||||||
 | 
					                            DataSourceUtils.releaseConnection(con, ds);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return feature;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * ConfigTable.KEEP_ADAPTER=2 : 根据当前接口判断是否保持同一个数据源绑定同一个adapter<br/>
 | 
				
			||||||
 | 
					     * DynamicRoutingDataSource类型的返回false,因为同一个DynamicRoutingDataSource可能对应多类数据库, 如果项目中只有一种数据库 应该直接返回true
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param datasource 数据源
 | 
				
			||||||
 | 
					     * @return boolean
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean keepAdapter(Object datasource) {
 | 
				
			||||||
 | 
					        if (datasource instanceof JdbcTemplate jdbc) {
 | 
				
			||||||
 | 
					            DataSource ds = jdbc.getDataSource();
 | 
				
			||||||
 | 
					            return !(ds instanceof DynamicRoutingDataSource);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -186,7 +186,7 @@ public class GenTableServiceImpl implements IGenTableService {
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public List<GenTable> selectDbTableListByNames(String[] tableNames, String dataName) {
 | 
					    public List<GenTable> selectDbTableListByNames(String[] tableNames, String dataName) {
 | 
				
			||||||
        Set<String> tableNameSet = new HashSet<>(List.of(tableNames));
 | 
					        Set<String> tableNameSet = new HashSet<>(List.of(tableNames));
 | 
				
			||||||
        LinkedHashMap<String, Table<?>> tablesMap = ServiceProxy.service(dataName).metadata().tables();
 | 
					        LinkedHashMap<String, Table<?>> tablesMap = ServiceProxy.metadata().tables();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (CollUtil.isEmpty(tablesMap)) {
 | 
					        if (CollUtil.isEmpty(tablesMap)) {
 | 
				
			||||||
            return new ArrayList<>();
 | 
					            return new ArrayList<>();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user