mirror of https://gitee.com/dromara/liteFlow
适配 shardingjdbc
This commit is contained in:
parent
b6fe455d95
commit
bf1a10a867
|
@ -0,0 +1,39 @@
|
|||
package com.yomahub.liteflow.exception;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 缺少 maven 依赖异常
|
||||
*
|
||||
* @author tkc
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public class MissMavenDependencyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String TEMPLATE = "miss maven dependency " + "\n" +
|
||||
"<dependency>\n" +
|
||||
" <groupId>{groupId}</groupId>\n" +
|
||||
" <artifactId>{artifactId}</artifactId>\n" +
|
||||
" <version>${version}</version>\n" +
|
||||
"</dependency>";
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
public MissMavenDependencyException(String groupId, String artifactId) {
|
||||
this.message = StrUtil.format(TEMPLATE, groupId, artifactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
<artifactId>liteflow-rule-sql</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
|
@ -25,5 +26,23 @@
|
|||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 苞米豆动态数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring</artifactId>
|
||||
<version>${dynamic-datasource.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Sharding JDBC -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${sharding-jdbc.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,16 +0,0 @@
|
|||
package com.yomahub.liteflow.parser.sql;
|
||||
|
||||
import com.yomahub.liteflow.spi.SpiPriority;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface DataBaseConnect extends SpiPriority {
|
||||
|
||||
/**
|
||||
* 获取连接
|
||||
*/
|
||||
Connection getConn();
|
||||
}
|
|
@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.yomahub.liteflow.core.FlowInitHook;
|
||||
import com.yomahub.liteflow.parser.constant.ReadType;
|
||||
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.LiteflowDataSourceConnectFactory;
|
||||
import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
||||
import com.yomahub.liteflow.parser.sql.read.SqlReadFactory;
|
||||
import com.yomahub.liteflow.parser.sql.util.JDBCHelper;
|
||||
|
@ -57,6 +58,8 @@ public class SQLXmlELParser extends ClassXmlFlowELParser {
|
|||
|
||||
// 初始化 SqlReadFactory
|
||||
SqlReadFactory.registerRead(sqlParserVO);
|
||||
// 初始化连接器
|
||||
LiteflowDataSourceConnectFactory.register();
|
||||
|
||||
// 注册轮询任务
|
||||
SqlReadFactory.registerSqlReadPollTask(ReadType.CHAIN);
|
||||
|
@ -92,7 +95,7 @@ public class SQLXmlELParser extends ClassXmlFlowELParser {
|
|||
* @param sqlParserVO sqlParserVO
|
||||
*/
|
||||
private void checkParserVO(SQLParserVO sqlParserVO) {
|
||||
if (sqlParserVO.isProjectExistedDataSource()) {
|
||||
if (sqlParserVO.isAutoFoundDataSource()) {
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isEmpty(sqlParserVO.getUrl())) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.yomahub.liteflow.parser.sql.datasource;
|
||||
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* 数据源获取接口
|
||||
*
|
||||
* @author tkc
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public interface LiteflowDataSourceConnect {
|
||||
|
||||
/**
|
||||
* 检查是否支持该数据源
|
||||
*/
|
||||
boolean filter(SQLParserVO config);
|
||||
|
||||
/**
|
||||
* 获取连接
|
||||
*/
|
||||
Connection getConn(SQLParserVO config) throws Exception;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.yomahub.liteflow.parser.sql.datasource;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.impl.BaoMiDouDynamicDs;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.impl.ShardingJdbcDs;
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 数据源获取接口工厂
|
||||
*
|
||||
* @author tkc
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public class LiteflowDataSourceConnectFactory {
|
||||
private static List<LiteflowDataSourceConnect> CONNECT_LIST = CollUtil.newArrayList(
|
||||
new BaoMiDouDynamicDs(),
|
||||
new ShardingJdbcDs()
|
||||
);
|
||||
|
||||
public static void register() {
|
||||
ContextAware contextAware = ContextAwareHolder.loadContextAware();
|
||||
Map<String, LiteflowDataSourceConnect> beanMap = contextAware.getBeansOfType(LiteflowDataSourceConnect.class);
|
||||
Collection<LiteflowDataSourceConnect> values = beanMap.values();
|
||||
CONNECT_LIST.addAll(values);
|
||||
|
||||
// 根据类名去重
|
||||
CONNECT_LIST = CollUtil.distinct(CONNECT_LIST, t -> t.getClass().getName(), true);
|
||||
}
|
||||
|
||||
public static Optional<LiteflowDataSourceConnect> getConnect(SQLParserVO sqlParserVO) {
|
||||
return CONNECT_LIST.stream().filter(connect -> connect.filter(sqlParserVO)).findFirst();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.yomahub.liteflow.parser.sql.datasource.impl;
|
||||
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.yomahub.liteflow.exception.MissMavenDependencyException;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.LiteflowDataSourceConnect;
|
||||
import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 苞米豆动态数据源
|
||||
*
|
||||
* @author tkc
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public class BaoMiDouDynamicDs implements LiteflowDataSourceConnect {
|
||||
|
||||
@Override
|
||||
public boolean filter(SQLParserVO config) {
|
||||
// 是否配置苞米豆动态数据源配置
|
||||
boolean configFlag = Optional.ofNullable(config.getBaomidou())
|
||||
.map(SQLParserVO.DataSourceConfig::getDataSourceName)
|
||||
.isPresent();
|
||||
if (!configFlag) {
|
||||
return false;
|
||||
}
|
||||
boolean classLoadFlag = ClassLoaderUtil.isPresent("com.baomidou.dynamic.datasource.DynamicRoutingDataSource");
|
||||
if (!classLoadFlag) {
|
||||
throw new MissMavenDependencyException("com.baomidou","dynamic-datasource-spring-boot-starter");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConn(SQLParserVO config) throws Exception {
|
||||
String dataSourceName = config.getShardingjdbc().getDataSourceName();
|
||||
ContextAware contextAware = ContextAwareHolder.loadContextAware();
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = contextAware.getBean(DynamicRoutingDataSource.class);
|
||||
Map<String, DataSource> dataSources = dynamicRoutingDataSource.getDataSources();
|
||||
if (!dataSources.containsKey(dataSourceName)){
|
||||
throw new ELSQLException(StrUtil.format("can not found {} datasource", dataSourceName));
|
||||
}
|
||||
|
||||
DataSource dataSource = dynamicRoutingDataSource.getDataSource(dataSourceName);
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.yomahub.liteflow.parser.sql.datasource.impl;
|
||||
|
||||
import com.yomahub.liteflow.parser.sql.datasource.LiteflowDataSourceConnect;
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* ShardingJdbc 动态数据源
|
||||
*
|
||||
* @author tkc
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public class ShardingJdbcDs implements LiteflowDataSourceConnect {
|
||||
@Override
|
||||
public boolean filter(SQLParserVO config) {
|
||||
// 是否配置 sharding jdbc 动态数据源配置
|
||||
boolean configFlag = Optional.ofNullable(config.getShardingjdbc())
|
||||
.map(SQLParserVO.DataSourceConfig::getDataSourceName)
|
||||
.isPresent();
|
||||
|
||||
if (!configFlag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConn(SQLParserVO config) throws Exception {
|
||||
ContextAware contextAware = ContextAwareHolder.loadContextAware();
|
||||
|
||||
return contextAware.getBean(DataSource.class).getConnection();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.yomahub.liteflow.parser.sql.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.parser.sql.DataBaseConnect;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.LiteflowDataSourceConnect;
|
||||
import com.yomahub.liteflow.parser.sql.datasource.LiteflowDataSourceConnectFactory;
|
||||
import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -36,12 +36,12 @@ public class LiteFlowJdbcUtil {
|
|||
|
||||
try {
|
||||
// 如果指定连接查找器,就使用连接查找器获取连接
|
||||
ContextAware contextAware = ContextAwareHolder.loadContextAware();
|
||||
if (contextAware.hasBean(DataBaseConnect.class)) {
|
||||
connection = contextAware.getBean(DataBaseConnect.class).getConn();
|
||||
Optional<LiteflowDataSourceConnect> connectOpt = LiteflowDataSourceConnectFactory.getConnect(sqlParserVO);
|
||||
if (connectOpt.isPresent()) {
|
||||
connection =connectOpt.get().getConn(sqlParserVO);
|
||||
}
|
||||
// 如果不配置 jdbc 连接相关配置,代表使用项目数据源
|
||||
else if (sqlParserVO.isProjectExistedDataSource()) {
|
||||
else if (sqlParserVO.isAutoFoundDataSource()) {
|
||||
Map<String, DataSource> dataSourceMap = ContextAwareHolder.loadContextAware().getBeansOfType(DataSource.class);
|
||||
if (DataSourceBeanNameHolder.isNotInit()) {
|
||||
synchronized (DataSourceBeanNameHolder.class) {
|
||||
|
|
|
@ -142,6 +142,16 @@ public class SQLParserVO {
|
|||
*/
|
||||
private Boolean sqlLogEnabled = true;
|
||||
|
||||
/**
|
||||
* 苞米豆动态数据源配置
|
||||
*/
|
||||
private DataSourceConfig baomidou;
|
||||
|
||||
/**
|
||||
* sharding jdbc 动态数据源配置
|
||||
*/
|
||||
private DataSourceConfig shardingjdbc;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
@ -271,10 +281,13 @@ public class SQLParserVO {
|
|||
}
|
||||
|
||||
/**
|
||||
* 判断配资是否使用 IOC 已有数据源
|
||||
* 判断是否自动查找数据源
|
||||
*/
|
||||
public boolean isProjectExistedDataSource() {
|
||||
return StrUtil.isBlank(url) && StrUtil.isBlank(username) && StrUtil.isBlank(password) && StrUtil.isBlank(driverClassName);
|
||||
public boolean isAutoFoundDataSource() {
|
||||
return StrUtil.isBlank(url) &&
|
||||
StrUtil.isBlank(username) &&
|
||||
StrUtil.isBlank(password) &&
|
||||
StrUtil.isBlank(driverClassName);
|
||||
}
|
||||
|
||||
public Boolean getPollingEnabled() {
|
||||
|
@ -363,4 +376,32 @@ public class SQLParserVO {
|
|||
public void setScriptCustomSql(String scriptCustomSql) {
|
||||
this.scriptCustomSql = scriptCustomSql;
|
||||
}
|
||||
|
||||
public DataSourceConfig getBaomidou() {
|
||||
return baomidou;
|
||||
}
|
||||
|
||||
public void setBaomidou(DataSourceConfig baomidou) {
|
||||
this.baomidou = baomidou;
|
||||
}
|
||||
|
||||
public DataSourceConfig getShardingjdbc() {
|
||||
return shardingjdbc;
|
||||
}
|
||||
|
||||
public void setShardingjdbc(DataSourceConfig shardingjdbc) {
|
||||
this.shardingjdbc = shardingjdbc;
|
||||
}
|
||||
|
||||
public static class DataSourceConfig {
|
||||
private String dataSourceName;
|
||||
|
||||
public String getDataSourceName() {
|
||||
return dataSourceName;
|
||||
}
|
||||
|
||||
public void setDataSourceName(String dataSourceName) {
|
||||
this.dataSourceName = dataSourceName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package com.yomahub.liteflow.test.sql;
|
||||
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.ds.ItemDataSource;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import com.zaxxer.hikari.HikariPoolMXBean;
|
||||
import com.zaxxer.hikari.pool.HikariPool;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
@ -18,11 +13,6 @@ import org.springframework.test.context.TestPropertySource;
|
|||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author tangkc
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package com.yomahub.liteflow.test.sql.finder;
|
||||
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.yomahub.liteflow.parser.sql.DataBaseConnect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 自定义数据库连接
|
||||
*/
|
||||
@Component
|
||||
public class CustomerDataBaseConnFinder implements DataBaseConnect {
|
||||
@Resource
|
||||
private DynamicRoutingDataSource dynamicRoutingDataSource;
|
||||
@Override
|
||||
public Connection getConn() {
|
||||
DataSource dataSource = dynamicRoutingDataSource.getDataSource("h2-first");
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
liteflow.rule-source-ext-data={\
|
||||
"applicationName":"demo",\
|
||||
"baomidou":{"dataSourceName":"h2-first"},\
|
||||
"chainTableName":"EL_TABLE",\
|
||||
"chainApplicationNameField":"application_name",\
|
||||
"chainNameField":"chain_name",\
|
||||
"elDataField":"EL_DATA",\
|
||||
"pollingEnabled": true,\
|
||||
"pollingIntervalSeconds": 10,\
|
||||
"pollingStartSeconds": 5,\
|
||||
"scriptTableName":"script_node_table",\
|
||||
"scriptApplicationNameField":"application_name",\
|
||||
"scriptIdField":"script_node_id",\
|
||||
"scriptNameField":"script_node_name",\
|
||||
"scriptDataField":"script_node_data",\
|
||||
"scriptLanguageField":"script_language",\
|
||||
"scriptTypeField":"script_node_type"\
|
||||
}
|
||||
spring.profiles.active=test
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.datasource.dynamic.primary=h2-first
|
||||
spring.datasource.dynamic.strict=false
|
||||
spring.datasource.dynamic.datasource.h2-first.url=jdbc:h2:mem:test_db1
|
||||
spring.datasource.dynamic.datasource.h2-first.username=root1
|
||||
spring.datasource.dynamic.datasource.h2-first.password=123456
|
||||
spring.datasource.dynamic.datasource.h2-first.init.schema=classpath:/sql/schema.sql
|
||||
spring.datasource.dynamic.datasource.h2-first.init.data=classpath:/sql/data.sql
|
||||
spring.datasource.dynamic.datasource.h2-first.hikari.min-idle=1
|
||||
spring.datasource.dynamic.datasource.h2-first.hikari.max-pool-size=5
|
||||
spring.datasource.dynamic.datasource.h2-second.url=jdbc:h2:mem:test_db2
|
||||
spring.datasource.dynamic.datasource.h2-second.username=root2
|
||||
spring.datasource.dynamic.datasource.h2-second.password=123456
|
||||
spring.datasource.dynamic.datasource.h2-second.init.schema=classpath:/sql/second/schema.sql
|
||||
spring.datasource.dynamic.datasource.h2-second.init.data=classpath:/sql/second/data.sql
|
||||
spring.datasource.dynamic.datasource.h2-second.hikari.min-idle=1
|
||||
spring.datasource.dynamic.datasource.h2-second.hikari.max-pool-size=5
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>liteflow-testcase-el</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-testcase-el-sql-springboot-sharding-jdbc</artifactId>
|
||||
|
||||
<properties>
|
||||
<h2.version>2.1.214</h2.version>
|
||||
<jpa.version>2.6.8</jpa.version>
|
||||
<shardingsphere.version>5.5.0</shardingsphere.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-rule-sql</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<version>${jpa.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-groovy</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-graaljs</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc</artifactId>
|
||||
<version>${shardingsphere.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package com.yomahub.liteflow.test.sql.shardingjdbc;
|
||||
|
||||
|
||||
import com.yomahub.liteflow.core.FlowInitHook;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.spi.holder.SpiFactoryInitializing;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
/**
|
||||
* @author tangkc
|
||||
* @since 2.8.6
|
||||
*/
|
||||
public class BaseTest {
|
||||
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
SpiFactoryInitializing.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.yomahub.liteflow.test.sql.shardingjdbc;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/application-sharding-jdbc-data-source-xml.properties")
|
||||
@SpringBootTest(classes = SQLWithXmlELShardingJdbcDsSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.sql.shardingjdbc.cmp"})
|
||||
public class SQLWithXmlELShardingJdbcDsSpringbootTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testMultiLanguage1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("x2[python脚本]==>x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.sql.shardingjdbc.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.sql.shardingjdbc.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.sql.shardingjdbc.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
liteflow.rule-source-ext-data={\
|
||||
"applicationName":"demo",\
|
||||
"shardingjdbc":{"dataSourceName":"ds_1"},\
|
||||
"chainTableName":"EL_TABLE",\
|
||||
"chainApplicationNameField":"application_name",\
|
||||
"chainNameField":"chain_name",\
|
||||
"elDataField":"EL_DATA",\
|
||||
"pollingEnabled": true,\
|
||||
"pollingIntervalSeconds": 10,\
|
||||
"pollingStartSeconds": 5,\
|
||||
"scriptTableName":"script_node_table",\
|
||||
"scriptApplicationNameField":"application_name",\
|
||||
"scriptIdField":"script_node_id",\
|
||||
"scriptNameField":"script_node_name",\
|
||||
"scriptDataField":"script_node_data",\
|
||||
"scriptLanguageField":"script_language",\
|
||||
"scriptTypeField":"script_node_type"\
|
||||
}
|
||||
spring.profiles.active=test
|
||||
spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||
|
||||
spring.datasource.url=jdbc:shardingsphere:classpath:shardingsphere.yaml
|
|
@ -0,0 +1,26 @@
|
|||
rules:
|
||||
- !READWRITE_SPLITTING
|
||||
dataSources:
|
||||
readwrite_ds:
|
||||
writeDataSourceName: ds_2
|
||||
readDataSourceNames:
|
||||
- ds_1
|
||||
transactionalReadQueryStrategy: PRIMARY
|
||||
loadBalancerName: random
|
||||
loadBalancers:
|
||||
random:
|
||||
type: RANDOM
|
||||
|
||||
dataSources:
|
||||
ds_1:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: org.h2.Driver
|
||||
jdbcUrl: jdbc:h2:mem:test_db1;INIT=RUNSCRIPT FROM 'classpath:sql/schema.sql'\;RUNSCRIPT FROM 'classpath:sql/data.sql'
|
||||
username: root1
|
||||
password: 123456
|
||||
ds_2:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: org.h2.Driver
|
||||
jdbcUrl: jdbc:h2:mem:test_db2;INIT=RUNSCRIPT FROM 'classpath:sql/second/schema.sql'\;RUNSCRIPT FROM 'classpath:sql/second/data.sql'
|
||||
username: root2
|
||||
password: 123456
|
|
@ -0,0 +1,14 @@
|
|||
DELETE FROM EL_TABLE;
|
||||
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain1','THEN(a, b, c);');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain2','THEN(a, b, c);');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain3','IF(x0, THEN(a, b));');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','<chain3>','IF(x0, THEN(a, b));');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain4','IF(x2, IF(x0, THEN(a, b)));');
|
||||
|
||||
DELETE FROM SCRIPT_NODE_TABLE;
|
||||
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','boolean_script','return true','groovy');
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','boolean_script','return false','groovy');
|
||||
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','boolean_script','return true','js');
|
|
@ -0,0 +1,20 @@
|
|||
create table IF NOT EXISTS `EL_TABLE`
|
||||
(
|
||||
`id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`application_name` varchar(32) NOT NULL,
|
||||
`chain_name` varchar(32) NOT NULL,
|
||||
`el_data` varchar(1024) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
create table IF NOT EXISTS `script_node_table`
|
||||
(
|
||||
`id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`application_name` varchar(32) NOT NULL,
|
||||
`script_node_id` varchar(32) NOT NULL,
|
||||
`script_node_name` varchar(32) NOT NULL,
|
||||
`script_node_type` varchar(32) NOT NULL,
|
||||
`script_node_data` varchar(1024) NOT NULL,
|
||||
`script_language` varchar(1024) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
|
@ -0,0 +1,27 @@
|
|||
DELETE
|
||||
FROM EL_TABLE;
|
||||
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA)
|
||||
values ('demo', 'chain11', 'THEN(a, b, c);');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA)
|
||||
values ('demo', 'chain21', 'THEN(a, b, c);');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA)
|
||||
values ('demo', 'chain31', 'IF(x0, THEN(a, b));');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA)
|
||||
values ('demo', '<chain31>', 'IF(x0, THEN(a, b));');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA)
|
||||
values ('demo', 'chain41', 'IF(x2, IF(x0, THEN(a, b)));');
|
||||
|
||||
DELETE
|
||||
FROM SCRIPT_NODE_TABLE;
|
||||
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA,
|
||||
SCRIPT_LANGUAGE)
|
||||
values ('demo', 'x01', 'if 脚本', 'boolean_script', 'return true', 'groovy');
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA,
|
||||
SCRIPT_LANGUAGE)
|
||||
values ('demo', 'x11', 'if 脚本', 'boolean_script', 'return false', 'groovy');
|
||||
|
||||
INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA,
|
||||
SCRIPT_LANGUAGE)
|
||||
values ('demo', 'x21', 'python脚本', 'boolean_script', 'return true', 'js');
|
|
@ -0,0 +1,20 @@
|
|||
create table IF NOT EXISTS `EL_TABLE`
|
||||
(
|
||||
`id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`application_name` varchar(32) NOT NULL,
|
||||
`chain_name` varchar(32) NOT NULL,
|
||||
`el_data` varchar(1024) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
create table IF NOT EXISTS `script_node_table`
|
||||
(
|
||||
`id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`application_name` varchar(32) NOT NULL,
|
||||
`script_node_id` varchar(32) NOT NULL,
|
||||
`script_node_name` varchar(32) NOT NULL,
|
||||
`script_node_type` varchar(32) NOT NULL,
|
||||
`script_node_data` varchar(1024) NOT NULL,
|
||||
`script_language` varchar(1024) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
|
@ -43,6 +43,7 @@
|
|||
<module>liteflow-testcase-el-script-kotlin-springboot</module>
|
||||
<module>liteflow-testcase-el-sql-solon</module>
|
||||
<module>liteflow-testcase-el-script-javax-springboot</module>
|
||||
<module>liteflow-testcase-el-sql-springboot-sharding-jdbc</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -78,6 +78,9 @@
|
|||
<janino.version>3.1.12</janino.version>
|
||||
<kotlin.version>1.9.23</kotlin.version>
|
||||
<liquor.version>1.3.6</liquor.version>
|
||||
<!--sql plugin-->
|
||||
<dynamic-datasource.version>4.3.1</dynamic-datasource.version>
|
||||
<sharding-jdbc.version>4.1.1</sharding-jdbc.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
Loading…
Reference in New Issue