From 689ef2e6d53651f23549b39de6586294a3fe318d Mon Sep 17 00:00:00 2001 From: jay li <221531386@qq.com> Date: Sat, 24 Aug 2024 13:52:08 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I9H6GY=20SQL=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=9C=A8=E9=85=8D=E7=BD=AE=E4=B8=8A=E6=94=AF=E6=8C=81=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/constant/SqlReadConstant.java | 2 + .../parser/sql/read/AbstractSqlRead.java | 6 ++- .../parser/sql/read/impl/ChainRead.java | 22 +++++++---- .../liteflow/parser/sql/vo/SQLParserVO.java | 26 +++++++++++++ ...SQLWithXmlELWithSuffix2SpringbootTest.java | 38 +++++++++++++++++++ .../SQLWithXmlELWithSuffixSpringbootTest.java | 37 ++++++++++++++++++ ...ion-data-source-with-suffix-xml.properties | 23 +++++++++++ ...on-data-source-with-suffix2-xml.properties | 23 +++++++++++ .../src/test/resources/sql/data.sql | 2 + .../src/test/resources/sql/schema.sql | 1 + 10 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffix2SpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffixSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix-xml.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix2-xml.properties diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java index 6cc4015db..5f07cdd2a 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java @@ -12,6 +12,8 @@ public class SqlReadConstant { public static final String SQL_PATTERN = "SELECT * FROM {} WHERE {}=?"; + public static final String SQL_PATTERN_WITH_SUFFIX = "SELECT * FROM {} WHERE {}=? AND {}=?"; + public static final String SCRIPT_SQL_CHECK_PATTERN = "SELECT 1 FROM {} "; public static final String SCRIPT_SQL_PATTERN = "SELECT * FROM {} WHERE {}=?"; diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java index 599815897..7acd9f76c 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java @@ -10,9 +10,7 @@ import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; import java.sql.*; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * sql 读取抽象类,维护公共方法 @@ -53,6 +51,10 @@ public abstract class AbstractSqlRead implements SqlRead { stmt.setFetchSize(SqlReadConstant.FETCH_SIZE_MAX); stmt.setString(1, config.getApplicationName()); + if (sqlCmd.contains(config.getChainSuffixTypeField()) && StrUtil.isNotBlank(config.getChainSuffixType())) { + stmt.setString(2, config.getChainSuffixType()); + } + rs = stmt.executeQuery(); while (rs.next()) { diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java index b7ce9ef97..dffe02ee7 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java @@ -29,10 +29,10 @@ public class ChainRead extends AbstractSqlRead { ChainVO chainVO = new ChainVO(); chainVO.setChainId(getStringFromRsWithCheck(rs, super.config.getChainNameField())); chainVO.setBody(getStringFromRsWithCheck(rs, super.config.getElDataField())); - if (StrUtil.isNotBlank(super.config.getNamespaceField())){ + if (StrUtil.isNotBlank(super.config.getNamespaceField())) { chainVO.setNamespace(getStringFromRs(rs, super.config.getNamespaceField())); } - if (StrUtil.isNotBlank(super.config.getRouteField())){ + if (StrUtil.isNotBlank(super.config.getRouteField())) { chainVO.setRoute(getStringFromRs(rs, super.config.getRouteField())); } return chainVO; @@ -56,8 +56,14 @@ public class ChainRead extends AbstractSqlRead { public String buildQuerySql() { String chainTableName = super.config.getChainTableName(); String chainApplicationNameField = super.config.getChainApplicationNameField(); + String chainSuffixTypeField = super.config.getChainSuffixTypeField(); - return StrUtil.format(SqlReadConstant.SQL_PATTERN, chainTableName, chainApplicationNameField); + if (StrUtil.isNotBlank(chainSuffixTypeField)) { + return StrUtil.format(SqlReadConstant.SQL_PATTERN_WITH_SUFFIX, chainTableName, + chainApplicationNameField, chainSuffixTypeField); + } else { + return StrUtil.format(SqlReadConstant.SQL_PATTERN, chainTableName, chainApplicationNameField); + } } @Override @@ -68,19 +74,19 @@ public class ChainRead extends AbstractSqlRead { String chainApplicationNameField = super.config.getChainApplicationNameField(); String applicationName = super.config.getApplicationName(); - if (StrUtil.isBlank(chainTableName)){ + if (StrUtil.isBlank(chainTableName)) { throw new ELSQLException("You did not define the chainTableName property"); } - if (StrUtil.isBlank(elDataField)){ + if (StrUtil.isBlank(elDataField)) { throw new ELSQLException("You did not define the elDataField property"); } - if (StrUtil.isBlank(chainNameField)){ + if (StrUtil.isBlank(chainNameField)) { throw new ELSQLException("You did not define the chainNameField property"); } - if (StrUtil.isBlank(chainApplicationNameField)){ + if (StrUtil.isBlank(chainApplicationNameField)) { throw new ELSQLException("You did not define the chainApplicationNameField property"); } - if (StrUtil.isBlank(applicationName)){ + if (StrUtil.isBlank(applicationName)) { throw new ELSQLException("You did not define the applicationName property"); } } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java index c654df2a1..0c2a0f430 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java @@ -71,6 +71,16 @@ public class SQLParserVO { */ private String chainEnableField; + /** + * chain 后缀 + */ + private String chainSuffixType; + + /** + * chain 后缀字段名 + */ + private String chainSuffixTypeField = "chain_suffix_type"; + /** * 脚本 node 表名 */ @@ -336,4 +346,20 @@ public class SQLParserVO { public void setNamespaceField(String namespaceField) { this.namespaceField = namespaceField; } + + public String getChainSuffixType() { + return chainSuffixType; + } + + public void setChainSuffixType(String chainSuffixType) { + this.chainSuffixType = chainSuffixType; + } + + public String getChainSuffixTypeField() { + return chainSuffixTypeField; + } + + public void setChainSuffixTypeField(String chainSuffixTypeField) { + this.chainSuffixTypeField = chainSuffixTypeField; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffix2SpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffix2SpringbootTest.java new file mode 100644 index 000000000..310d78951 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffix2SpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.withSuffix; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +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; +import javax.sql.DataSource; + +/** + * @author jay li + * @since 2.12.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-data-source-with-suffix2-xml.properties") +@SpringBootTest(classes = SQLWithXmlELWithSuffix2SpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELWithSuffix2SpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testSQLWithXmlChain1() { + LiteflowResponse response = flowExecutor.execute2Resp("r_chain1", "arg"); + Assertions.assertEquals("c==>b==>a", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffixSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffixSpringbootTest.java new file mode 100644 index 000000000..d05791dc2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/withSuffix/SQLWithXmlELWithSuffixSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.withSuffix; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +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; +import javax.sql.DataSource; + +/** + * @author jay li + * @since 2.12.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-data-source-with-suffix-xml.properties") +@SpringBootTest(classes = SQLWithXmlELWithSuffixSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELWithSuffixSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testSQLWithXmlChain1() { + LiteflowResponse response = flowExecutor.execute2Resp("r_chain1", "arg"); + Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix-xml.properties new file mode 100644 index 000000000..c1cfe009f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix-xml.properties @@ -0,0 +1,23 @@ +liteflow.rule-source-ext-data={\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "chainSuffixTypeField":"chain_suffix_type",\ + "chainSuffixType":"biz1",\ + "elDataField":"EL_DATA",\ + "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.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:test_db;MODE=MySQL +spring.datasource.username=root +spring.datasource.password=123456 +spring.datasource.schema=classpath:/sql/schema.sql +spring.datasource.data=classpath:/sql/data.sql +spring.datasource.platform=h2 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix2-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix2-xml.properties new file mode 100644 index 000000000..93ef74aa5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-with-suffix2-xml.properties @@ -0,0 +1,23 @@ +liteflow.rule-source-ext-data={\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "chainSuffixTypeField":"chain_suffix_type",\ + "chainSuffixType":"biz2",\ + "elDataField":"EL_DATA",\ + "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.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:test_db;MODE=MySQL +spring.datasource.username=root +spring.datasource.password=123456 +spring.datasource.schema=classpath:/sql/schema.sql +spring.datasource.data=classpath:/sql/data.sql +spring.datasource.platform=h2 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql index e885458bf..c4df6d8be 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql @@ -7,6 +7,8 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','