mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 10:36:31 +08:00
@@ -1,39 +1,23 @@
|
|||||||
package com.orangeforms.common.flow.config;
|
package com.orangeforms.common.flow.config;
|
||||||
|
|
||||||
import com.orangeforms.common.core.config.DynamicDataSource;
|
import com.orangeforms.common.core.config.DataSourceContextHolder;
|
||||||
import com.orangeforms.common.core.constant.ApplicationConstant;
|
import com.orangeforms.common.core.constant.ApplicationConstant;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
|
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
|
||||||
import org.flowable.common.engine.impl.EngineConfigurator;
|
import org.flowable.common.engine.impl.EngineConfigurator;
|
||||||
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务启动过程中动态切换flowable引擎内置表所在的数据源。
|
* 服务启动过程中动态切换flowable引擎内置表所在的数据源。
|
||||||
*
|
*
|
||||||
* @author Jerry
|
* @author Jerry
|
||||||
* @date 2024-07-02
|
* @date 2024-04-15
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CustomEngineConfigurator implements EngineConfigurator {
|
public class CustomEngineConfigurator implements EngineConfigurator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeInit(AbstractEngineConfiguration engineConfiguration) {
|
public void beforeInit(AbstractEngineConfiguration engineConfiguration) {
|
||||||
DataSource dataSource = engineConfiguration.getDataSource();
|
DataSourceContextHolder.setDataSourceType(ApplicationConstant.COMMON_FLOW_AND_ONLINE_DATASOURCE_TYPE);
|
||||||
if (dataSource instanceof TransactionAwareDataSourceProxy) {
|
|
||||||
TransactionAwareDataSourceProxy proxy = (TransactionAwareDataSourceProxy) dataSource;
|
|
||||||
DataSource targetDataSource = proxy.getTargetDataSource();
|
|
||||||
if (targetDataSource instanceof DynamicDataSource) {
|
|
||||||
DynamicDataSource dynamicDataSource = (DynamicDataSource) targetDataSource;
|
|
||||||
Map<Object, DataSource> dynamicDataSourceMap = dynamicDataSource.getResolvedDataSources();
|
|
||||||
DataSource flowDataSource = dynamicDataSourceMap.get(ApplicationConstant.COMMON_FLOW_AND_ONLINE_DATASOURCE_TYPE);
|
|
||||||
if (flowDataSource != null) {
|
|
||||||
engineConfiguration.setDataSource(flowDataSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user