From ead5896d046f5695b20111ada2421ae4a3a2fabc Mon Sep 17 00:00:00 2001 From: tangkc <1016771049@qq.com> Date: Tue, 20 Sep 2022 17:52:35 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I5ROOR=20SQL=20plugin=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/parser/sql/util/JDBCHelper.java | 3 +- .../pom.xml | 3 +- .../test/sql/SQLWithXmlELSpringbootTest.java | 46 ++++++++++++++++--- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java index 3f6c5a5c1..896c23244 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java @@ -149,9 +149,8 @@ public class JDBCHelper { return sqlParserVO; } - private JDBCHelper setSqlParserVO(SQLParserVO sqlParserVO) { + private void setSqlParserVO(SQLParserVO sqlParserVO) { this.sqlParserVO = sqlParserVO; - return this; } //#endregion } diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml index b1bfc69df..023a8340a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml @@ -14,6 +14,7 @@ 2.1.214 + 2.0.5.RELEASE @@ -38,7 +39,7 @@ org.springframework.boot spring-boot-starter-data-jpa - 2.0.5.RELEASE + ${jpa.version} test diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java index 34ceb68ac..9a6a418e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -2,7 +2,12 @@ package com.yomahub.liteflow.test.sql; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.util.JsonUtil; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,6 +18,10 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; /** * @author tangkc @@ -24,12 +33,35 @@ import javax.annotation.Resource; @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) public class SQLWithXmlELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testSQLWithXml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } + @Test + public void testSQLWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + + // 修改数据库 + changeData(); + + // 重新加载规则 + flowExecutor.reloadRule(); + Assert.assertEquals("a==>c==>b", flowExecutor.execute2Resp("chain1", "arg").getExecuteStepStr()); + } + + /** + * 修改数据库数据 + */ + private void changeData() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); + Connection connection = null; + try { + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), sqlParserVO.getPassword()); + Statement statement = connection.createStatement(); + statement.executeUpdate("UPDATE EL_TABLE SET EL_DATA='THEN(a, c, b);' WHERE chain_name='chain1'"); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } }