mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
fix: 修复使用多数据源 + seata 分布式事务时,数据源解密错误的问题
This commit is contained in:
parent
02b7997d16
commit
9354f200c6
@ -21,6 +21,9 @@ import org.apache.ibatis.logging.LogFactory;
|
||||
import javax.sql.DataSource;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author michael
|
||||
*/
|
||||
public class DataSourceManager {
|
||||
|
||||
private static DataSourceDecipher decipher;
|
||||
|
||||
@ -49,8 +49,13 @@ public class FlexDataSource extends AbstractDataSource {
|
||||
private final DataSource defaultDataSource;
|
||||
|
||||
public FlexDataSource(String dataSourceKey, DataSource dataSource) {
|
||||
this(dataSourceKey, dataSource, true);
|
||||
}
|
||||
|
||||
DataSourceManager.decryptDataSource(dataSource);
|
||||
public FlexDataSource(String dataSourceKey, DataSource dataSource, boolean needDecryptDataSource) {
|
||||
if (needDecryptDataSource) {
|
||||
DataSourceManager.decryptDataSource(dataSource);
|
||||
}
|
||||
|
||||
this.defaultDataSourceKey = dataSourceKey;
|
||||
this.defaultDataSource = dataSource;
|
||||
@ -61,11 +66,19 @@ public class FlexDataSource extends AbstractDataSource {
|
||||
}
|
||||
|
||||
public void addDataSource(String dataSourceKey, DataSource dataSource) {
|
||||
DataSourceManager.decryptDataSource(dataSource);
|
||||
addDataSource(dataSourceKey, dataSource, true);
|
||||
}
|
||||
|
||||
|
||||
public void addDataSource(String dataSourceKey, DataSource dataSource, boolean needDecryptDataSource) {
|
||||
if (needDecryptDataSource) {
|
||||
DataSourceManager.decryptDataSource(dataSource);
|
||||
}
|
||||
dataSourceMap.put(dataSourceKey, dataSource);
|
||||
dbTypeHashMap.put(dataSourceKey, DbTypeUtil.getDbType(dataSource));
|
||||
}
|
||||
|
||||
|
||||
public void removeDatasource(String dataSourceKey) {
|
||||
dataSourceMap.remove(dataSourceKey);
|
||||
dbTypeHashMap.remove(dataSourceKey);
|
||||
|
||||
@ -81,18 +81,22 @@ public class MultiDataSourceAutoConfiguration {
|
||||
DataSourceManager.setDecipher(dataSourceDecipher);
|
||||
|
||||
for (Map.Entry<String, Map<String, String>> entry : dataSourceProperties.entrySet()) {
|
||||
|
||||
DataSource dataSource = new DataSourceBuilder(entry.getValue()).build();
|
||||
if (seataConfig !=null &&seataConfig.isEnable()){
|
||||
if (seataConfig.getSeataMode() ==SeataMode.XA){
|
||||
DataSourceManager.decryptDataSource(dataSource);
|
||||
|
||||
if (seataConfig != null && seataConfig.isEnable()) {
|
||||
if (seataConfig.getSeataMode() == SeataMode.XA) {
|
||||
dataSource = new DataSourceProxyXA(dataSource);
|
||||
}else {
|
||||
} else {
|
||||
dataSource = new DataSourceProxy(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (flexDataSource == null) {
|
||||
flexDataSource = new FlexDataSource(entry.getKey(), dataSource);
|
||||
flexDataSource = new FlexDataSource(entry.getKey(), dataSource, false);
|
||||
} else {
|
||||
flexDataSource.addDataSource(entry.getKey(), dataSource);
|
||||
flexDataSource.addDataSource(entry.getKey(), dataSource, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user