diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml
index ea9cbb7e..689d3413 100644
--- a/example/example-app/example-app-cmd-domain/pom.xml
+++ b/example/example-app/example-app-cmd-domain/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml
index fa5a85b3..7bc5ad75 100644
--- a/example/example-app/example-app-cmd-meta/pom.xml
+++ b/example/example-app/example-app-cmd-meta/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml
index d98b0870..cdc291a1 100644
--- a/example/example-app/example-app-query/pom.xml
+++ b/example/example-app/example-app-query/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml
index a06ce069..2810d70d 100644
--- a/example/example-app/pom.xml
+++ b/example/example-app/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.49
+ 3.4.50
../pom.xml
pom
diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml
index 34d74e5e..161e2505 100644
--- a/example/example-domain/example-domain-leave/pom.xml
+++ b/example/example-domain/example-domain-leave/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml
index 7e63cef4..f13f8ef1 100644
--- a/example/example-domain/example-domain-user/pom.xml
+++ b/example/example-domain/example-domain-user/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml
index e6aa033d..98c2dca0 100644
--- a/example/example-domain/pom.xml
+++ b/example/example-domain/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-example
- 3.4.49
+ 3.4.50
../pom.xml
4.0.0
diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml
index 8f0d701f..1ac1197c 100644
--- a/example/example-infra/example-infra-flow/pom.xml
+++ b/example/example-infra/example-infra-flow/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml
index 06c380f5..f8f80375 100644
--- a/example/example-infra/example-infra-jpa/pom.xml
+++ b/example/example-infra/example-infra-jpa/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml
index 40f3d079..2c9e8888 100644
--- a/example/example-infra/example-infra-security/pom.xml
+++ b/example/example-infra/example-infra-security/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-infra
- 3.4.49
+ 3.4.50
../pom.xml
diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml
index 4da00f43..a13b67a1 100644
--- a/example/example-infra/pom.xml
+++ b/example/example-infra/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.49
+ 3.4.50
../pom.xml
pom
diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml
index 1cc2348c..8524b770 100644
--- a/example/example-interface/pom.xml
+++ b/example/example-interface/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.49
+ 3.4.50
example-interface
diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml
index 390ce743..f5016a32 100644
--- a/example/example-server/pom.xml
+++ b/example/example-server/pom.xml
@@ -5,7 +5,7 @@
springboot-example
com.codingapi.springboot
- 3.4.49
+ 3.4.50
4.0.0
diff --git a/example/pom.xml b/example/pom.xml
index fc06945f..155e93a6 100644
--- a/example/pom.xml
+++ b/example/pom.xml
@@ -19,7 +19,7 @@
springboot-example
- 3.4.49
+ 3.4.50
springboot-example
springboot-example project for Spring Boot
diff --git a/pom.xml b/pom.xml
index 24edea63..4e1be78e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.49
+ 3.4.50
https://github.com/codingapi/springboot-framewrok
springboot-parent
@@ -165,6 +165,12 @@
${codingapi.framework.version}
+
+ com.codingapi.springboot
+ springboot-starter-script
+ ${codingapi.framework.version}
+
+
com.codingapi.springboot
springboot-starter-security
@@ -288,6 +294,7 @@
springboot-starter
+ springboot-starter-script
springboot-starter-security
springboot-starter-data-authorization
springboot-starter-data-fast
@@ -302,6 +309,7 @@
springboot-starter
+ springboot-starter-script
springboot-starter-security
springboot-starter-data-authorization
springboot-starter-data-fast
@@ -354,6 +362,7 @@
springboot-starter
+ springboot-starter-script
springboot-starter-security
springboot-starter-data-authorization
springboot-starter-data-fast
diff --git a/springboot-starter-data-authorization/pom.xml b/springboot-starter-data-authorization/pom.xml
index 25ade71a..49fc763e 100644
--- a/springboot-starter-data-authorization/pom.xml
+++ b/springboot-starter-data-authorization/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.49
+ 3.4.50
springboot-starter-data-authorization
diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml
index 67075ae9..60ce33e2 100644
--- a/springboot-starter-data-fast/pom.xml
+++ b/springboot-starter-data-fast/pom.xml
@@ -5,7 +5,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.49
+ 3.4.50
4.0.0
@@ -35,6 +35,11 @@
springboot-starter
+
+ com.codingapi.springboot
+ springboot-starter-script
+
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java
index 609a61a1..a0aac58e 100644
--- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java
+++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java
@@ -4,12 +4,14 @@
import com.codingapi.springboot.fast.jdbc.JdbcQueryContext;
import com.codingapi.springboot.fast.jpa.JpaQuery;
import com.codingapi.springboot.fast.jpa.JpaQueryContext;
-import com.codingapi.springboot.framework.script.GroovyScriptRunner;
-import com.codingapi.springboot.framework.script.request.GroovyBindObjectBuilder;
+import com.codingapi.springboot.script.GroovyScriptRuntime;
import lombok.Getter;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
+import java.util.HashMap;
+import java.util.Map;
+
public class ScriptRuntime {
@@ -17,10 +19,10 @@ public class ScriptRuntime {
@Getter
private final static ScriptRuntime instance = new ScriptRuntime();
- private final GroovyScriptRunner scriptRunner;
+ private final GroovyScriptRuntime scriptRunner;
private ScriptRuntime(){
- this.scriptRunner = new GroovyScriptRunner(1000);
+ this.scriptRunner = new GroovyScriptRuntime(1000);
}
Object running(String script) {
@@ -29,11 +31,12 @@ Object running(String script) {
JdbcQuery jdbcQuery = JdbcQueryContext.getInstance().getJdbcQuery();
JpaQuery jpaQuery = JpaQueryContext.getInstance().getJpaQuery();
- GroovyBindObjectBuilder bindBuilder = GroovyBindObjectBuilder.builder();
- bindBuilder.add("$request", request);
- bindBuilder.add("$jpa", jpaQuery);
- bindBuilder.add("$jdbc", jdbcQuery);
+ Map bindBuilder = new HashMap<>();
+ bindBuilder.put("$request", request);
+ bindBuilder.put("$jpa", jpaQuery);
+ bindBuilder.put("$jdbc", jdbcQuery);
+
+ return this.scriptRunner.run(script,Object.class,bindBuilder);
- return this.scriptRunner.run(script,Object.class,bindBuilder.build());
}
}
diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml
index 49ef4056..fb641563 100644
--- a/springboot-starter-flow/pom.xml
+++ b/springboot-starter-flow/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.49
+ 3.4.50
springboot-starter-flow
@@ -23,6 +23,11 @@
springboot-starter
+
+ com.codingapi.springboot
+ springboot-starter-script
+
+
com.esotericsoftware
kryo
@@ -46,30 +51,4 @@
-
-
-
- org.jacoco
- jacoco-maven-plugin
- 0.8.12
-
-
-
- prepare-agent
-
-
-
- report
- test
-
- report
-
-
-
-
-
-
-
-
-
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/script/GroovyShellContext.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/script/GroovyShellContext.java
index 28c076c0..da354620 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/script/GroovyShellContext.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/script/GroovyShellContext.java
@@ -1,6 +1,6 @@
package com.codingapi.springboot.flow.script;
-import com.codingapi.springboot.framework.script.GroovyScriptRunner;
+import com.codingapi.springboot.script.GroovyScriptRuntime;
import lombok.Getter;
public class GroovyShellContext {
@@ -11,11 +11,11 @@ public class GroovyShellContext {
@Getter
private final static GroovyShellContext instance = new GroovyShellContext();
- private final GroovyScriptRunner scriptRunner;
+ private final GroovyScriptRuntime scriptRunner;
private GroovyShellContext() {
- scriptRunner = new GroovyScriptRunner(MAX_CACHE_SIZE);
+ scriptRunner = new GroovyScriptRuntime(MAX_CACHE_SIZE);
}
diff --git a/springboot-starter-script/pom.xml b/springboot-starter-script/pom.xml
new file mode 100644
index 00000000..4255683d
--- /dev/null
+++ b/springboot-starter-script/pom.xml
@@ -0,0 +1,81 @@
+
+
+ 4.0.0
+
+ com.codingapi.springboot
+ springboot-parent
+ 3.4.50
+
+
+ springboot-starter-script
+ springboot-starter-script project for Spring Boot
+ springboot-starter-script
+
+
+ 17
+
+
+
+
+
+ com.codingapi.springboot
+ springboot-starter
+
+
+
+ org.apache.groovy
+ groovy
+
+
+
+ org.apache.groovy
+ groovy-json
+
+
+
+ org.apache.groovy
+ groovy-xml
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+ test
+
+
+
+ com.h2database
+ h2
+ test
+
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.12
+
+
+
+ prepare-agent
+
+
+
+ report
+ test
+
+ report
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScript.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScript.java
new file mode 100644
index 00000000..e8812097
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScript.java
@@ -0,0 +1,272 @@
+package com.codingapi.springboot.script;
+
+import com.codingapi.springboot.script.cache.GroovyScriptCacheContext;
+import com.codingapi.springboot.script.gateway.GroovyMetadataReloadGatewayContext;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.service.GroovyMetadataParserService;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Map;
+
+/**
+ * 脚本对象
+ */
+@Setter
+@Getter
+public class GroovyScript {
+
+ /**
+ * 脚本唯一编码
+ */
+ private final String key;
+ /**
+ * 脚本内容
+ */
+ private String script;
+ /**
+ * 脚本描述信息
+ */
+ private String description;
+ /**
+ * 脚本函数名称
+ */
+ private String method;
+ /**
+ * 返回数据类型
+ */
+ private Class> returnType;
+ /**
+ * 绑定数据类型
+ */
+ private Map> binds;
+ /**
+ * 请求参数对象
+ */
+ private Map> requests;
+ /**
+ * 备注信息
+ */
+ private String remark;
+
+
+ private GroovyScript(String key,
+ String script,
+ String remark,
+ String description,
+ String method,
+ Class> returnType,
+ Map> binds,
+ Map> requests) {
+ this.key = key;
+ this.script = script;
+ this.remark = remark;
+ this.description = description;
+ this.method = method;
+ this.returnType = returnType;
+ this.binds = binds;
+ this.requests = requests;
+
+ GroovyScriptCacheContext.getInstance().update(this);
+ }
+
+
+ public static GroovyScript create(String key,
+ String script,
+ String remark,
+ String description,
+ String method,
+ Class> returnType,
+ Map> binds,
+ Map> requests) {
+ return new GroovyScript(key, script, remark, description, method, returnType, binds, requests);
+ }
+
+
+
+ public static GroovyScript createRun(String key,
+ String script,
+ Class> returnType,
+ Map> binds) {
+ return new GroovyScript(key, script, null, null, null, returnType, binds, null);
+ }
+
+
+
+ public static GroovyScript createRun(String key,
+ String script,
+ String description,
+ Class> returnType,
+ Map> binds) {
+ return new GroovyScript(key, script, description, null, null, returnType, binds, null);
+ }
+
+ public static GroovyScript createInvoke(String key,
+ String script,
+ String remark,
+ String description,
+ String method,
+ Class> returnType,
+ Map> requests) {
+ return new GroovyScript(key, script, remark, description, method, returnType, null, requests);
+ }
+
+ public static GroovyScript createInvoke(String key,
+ String script,
+ String description,
+ String method,
+ Class> returnType,
+ Map> requests) {
+ return new GroovyScript(key, script, null, description, method, returnType, null, requests);
+ }
+
+ public static GroovyScript createInvoke(String key,
+ String script,
+ String method,
+ Class> returnType,
+ Map> requests) {
+ return new GroovyScript(key, script, null, null, method, returnType, null, requests);
+ }
+
+
+ public static GroovyScript createInvoke(String key,
+ String script,
+ String method,
+ Class> returnType,
+ Map> binds,
+ Map> requests) {
+ return new GroovyScript(key, script, null, null, method, returnType, binds, requests);
+ }
+
+
+
+ /**
+ * 编译脚本 并缓存
+ *
+ * @param cache 是否缓存
+ */
+ public void compile(boolean cache) {
+ GroovyScriptRuntimeContext.getInstance().compile(this.script, cache);
+ }
+
+ /**
+ * 编译脚本 非缓存
+ */
+ public void compile() {
+ GroovyScriptRuntimeContext.getInstance().compile(this.script);
+ }
+
+ /**
+ * 转化为直接运行时对象
+ *
+ * @param binds 绑定对象
+ * @return 运行时对象
+ */
+ public T run(TransactionMode transactionMode, Map binds) {
+ return (T) GroovyScriptRuntimeContext.getInstance().run(this.script, returnType, transactionMode, binds);
+ }
+
+ /**
+ * 转化为直接运行时对象
+ *
+ * @param binds 绑定对象
+ * @return 运行时对象
+ */
+ public T run(Map binds) {
+ return this.run(TransactionMode.DEFAULT, binds);
+ }
+
+ /**
+ * 转化为直接运行时对象
+ *
+ * @return 运行时对象
+ */
+ public T run(TransactionMode transactionMode) {
+ return this.run(transactionMode, null);
+ }
+
+ /**
+ * 转化为直接运行时对象
+ *
+ * @return 运行时对象
+ */
+ public T run() {
+ return this.run(TransactionMode.DEFAULT, null);
+ }
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @param transactionMode 事务模式
+ * @param binds 绑定对象
+ * @param requests 运行参数
+ * @return 运行时对象
+ */
+ public T invoke(TransactionMode transactionMode, Map binds, Object... requests) {
+ return (T) GroovyScriptRuntimeContext.getInstance().invoke(this.method, this.script, this.returnType, transactionMode, binds, requests);
+ }
+
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @param binds 绑定对象
+ * @param requests 运行参数
+ * @return 运行时对象
+ */
+ public T invoke(Map binds, Object... requests) {
+ return this.invoke(TransactionMode.DEFAULT, binds, requests);
+ }
+
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @param requests 运行参数
+ * @return 运行时对象
+ */
+ public T invoke(TransactionMode transactionMode,Object... requests) {
+ return this.invoke(transactionMode, null, requests);
+ }
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @param requests 运行参数
+ * @return 运行时对象
+ */
+ public T invoke(Object... requests) {
+ return this.invoke(TransactionMode.DEFAULT, null, requests);
+ }
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @return 运行时对象
+ */
+ public T invoke() {
+ return this.invoke(TransactionMode.DEFAULT, null, null);
+ }
+
+ /**
+ * 转化为函数运行时对象
+ *
+ * @return 运行时对象
+ */
+ public T invoke(TransactionMode transactionMode) {
+ return this.invoke(transactionMode, null, null);
+ }
+
+
+ /**
+ * 构建脚本元数据信息
+ */
+ public GroovyMetadata toMetadata() {
+ GroovyMetadataParserService groovyMetaDataParserService = new GroovyMetadataParserService(this);
+ GroovyMetadata metadata = groovyMetaDataParserService.parser();
+ GroovyMetadataReloadGatewayContext.getInstance().reload(metadata);
+ return metadata;
+ }
+
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunner.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntime.java
similarity index 70%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunner.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntime.java
index 110f9538..f75d8aba 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunner.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntime.java
@@ -1,8 +1,6 @@
-package com.codingapi.springboot.framework.script;
+package com.codingapi.springboot.script;
import com.codingapi.springboot.framework.crypto.SHA256;
-import com.codingapi.springboot.framework.script.request.GroovyBindObject;
-import com.codingapi.springboot.framework.script.request.GroovyRunningScript;
import com.codingapi.springboot.framework.transaction.TransactionManagerContext;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyShell;
@@ -10,13 +8,12 @@
import lombok.Getter;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
* groovy script 执行上下文对象
*/
-public class GroovyScriptRunner {
+public class GroovyScriptRuntime {
private final GroovyShell shell;
@@ -25,27 +22,9 @@ public class GroovyScriptRunner {
@Getter
private final int maxCacheSize;
- @Getter
- private final TransactionMode transactionMode;
-
-
- public enum TransactionMode {
- // 默认不处理
- DEFAULT,
- // 事务提交模式
- COMMIT,
- // 事务只读模式
- READONLY
- }
-
- public GroovyScriptRunner(int maxCacheSize) {
- this(maxCacheSize, TransactionMode.DEFAULT);
- }
-
- public GroovyScriptRunner(int maxCacheSize, TransactionMode transactionMode) {
+ public GroovyScriptRuntime(int maxCacheSize) {
this.maxCacheSize = maxCacheSize;
- this.transactionMode = transactionMode;
GroovyClassLoader groovyClassLoader = new GroovyClassLoader(getClass().getClassLoader());
this.shell = new GroovyShell(groovyClassLoader);
this.cache = new LinkedHashMap<>(16, 0.75F, true) {
@@ -110,7 +89,47 @@ public void compile(String script) {
* @param args 函数参数
* @return 返回数据
*/
- public T invoke(String method, String script, Class returnType, List binds, Object... args) {
+ public T invoke(String method,
+ String script,
+ Class returnType,
+ Map binds,
+ Object... args) {
+ return this.invoke(method, script, returnType, TransactionMode.DEFAULT, binds, args);
+ }
+
+ /**
+ * 执行函数脚本
+ *
+ * @param method 函数名称
+ * @param script 脚本内容
+ * @param returnType 返回类型
+ * @param args 函数参数
+ * @return 返回数据
+ */
+ public T invoke(String method,
+ String script,
+ Class returnType,
+ Object... args) {
+ return this.invoke(method, script, returnType, TransactionMode.DEFAULT, null, args);
+ }
+
+ /**
+ * 执行函数脚本
+ *
+ * @param method 函数名称
+ * @param script 脚本内容
+ * @param returnType 返回类型
+ * @param transactionMode 事务模式
+ * @param binds 绑定数据对象
+ * @param args 函数参数
+ * @return 返回数据
+ */
+ public T invoke(String method,
+ String script,
+ Class returnType,
+ TransactionMode transactionMode,
+ Map binds,
+ Object... args) {
String key = SHA256.sha256(script);
Script runtime = this.cache.get(key);
if (runtime == null) {
@@ -118,9 +137,10 @@ public T invoke(String method, String script, Class returnType, List T invoke(String method, String script, Class returnType, List T invoke(String method, String script, Class returnType, List T run(String script, Class returnType, List binds) {
+ public T run(String script, Class returnType, Map binds) {
+ return this.run(script, returnType, TransactionMode.DEFAULT, binds);
+ }
+
+ /**
+ * 执行脚本
+ *
+ * @param script 脚本
+ * @param returnType 返回数据类型
+ * @param transactionMode 事务模式
+ * @param binds 绑定对象
+ * @return 返回数据
+ */
+ public T run(String script, Class returnType, TransactionMode transactionMode, Map binds) {
String key = SHA256.sha256(script);
Script runtime = this.cache.get(key);
if (runtime == null) {
@@ -162,11 +194,12 @@ public T run(String script, Class returnType, List bind
}
if (binds != null && !binds.isEmpty()) {
- for (GroovyBindObject groovyBindObject : binds) {
- runtime.setProperty(groovyBindObject.getName(), groovyBindObject.getObject());
+ for (String bindKey : binds.keySet()) {
+ runtime.setProperty(bindKey, binds.get(bindKey));
}
}
+
// 事务制只读模式
if (transactionMode == TransactionMode.READONLY) {
Script finalRuntime = runtime;
@@ -188,39 +221,4 @@ public T run(String script, Class returnType, List bind
}
- /**
- * 执行脚本
- *
- * @param script 脚本
- * @param returnType 返回类型
- * @return 返回数据
- */
- public T run(String script, Class returnType) {
- return this.run(script, returnType, null);
- }
-
- /**
- * 执行函数脚本
- *
- * @param method 函数名称
- * @param script 脚本内容
- * @param returnType 返回类型
- * @param args 函数参数
- * @return 返回数据
- */
- public T invoke(String method, String script, Class returnType, Object... args) {
- return this.invoke(method, script, returnType, null, args);
- }
-
-
- /**
- * 执行函数脚本
- *
- * @param request 脚本参数
- * @return 返回数据
- */
- public T invoke(GroovyRunningScript request) {
- return this.invoke(request.getMethod(), request.getScript(), request.getReturnType(), request.getBinds(), request.getParams());
- }
-
}
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntimeContext.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntimeContext.java
new file mode 100644
index 00000000..d488bbc8
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/GroovyScriptRuntimeContext.java
@@ -0,0 +1,50 @@
+package com.codingapi.springboot.script;
+
+import lombok.Getter;
+
+import java.util.Map;
+
+public class GroovyScriptRuntimeContext {
+
+ @Getter
+ private final static GroovyScriptRuntimeContext instance = new GroovyScriptRuntimeContext();
+
+ public static final int DEFAULT_MAX_CACHE_SIZE = 10 * 1024;
+
+ private final GroovyScriptRuntime scriptRuntime;
+
+ private GroovyScriptRuntimeContext() {
+ int maxCacheSize = Integer.parseInt(System.getProperty("DEFAULT_MAX_CACHE_SIZE", String.valueOf(DEFAULT_MAX_CACHE_SIZE)));
+ System.out.println("GroovyScriptRuntimeContext max cache size:" + maxCacheSize);
+ this.scriptRuntime = new GroovyScriptRuntime(maxCacheSize);
+ }
+
+ public int getMaxCacheSize() {
+ return scriptRuntime.getMaxCacheSize();
+ }
+
+ public void clearCache() {
+ scriptRuntime.clearCache();
+ }
+
+ public int cacheSize() {
+ return scriptRuntime.cacheSize();
+ }
+
+ public void compile(String script, boolean cache) {
+ scriptRuntime.compile(script, cache);
+ }
+
+ public void compile(String script) {
+ scriptRuntime.compile(script);
+ }
+
+ public T invoke(String method, String script, Class returnType, TransactionMode transactionMode, Map binds, Object... requests) {
+ return scriptRuntime.invoke(method, script, returnType, transactionMode, binds, requests);
+ }
+
+
+ public T run(String script, Class returnType, TransactionMode transactionMode, Map binds) {
+ return scriptRuntime.run(script, returnType, transactionMode, binds);
+ }
+}
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/TransactionMode.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/TransactionMode.java
new file mode 100644
index 00000000..b3664bfe
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/TransactionMode.java
@@ -0,0 +1,10 @@
+package com.codingapi.springboot.script;
+
+public enum TransactionMode {
+ // 默认不处理
+ DEFAULT,
+ // 事务提交模式
+ COMMIT,
+ // 事务只读模式
+ READONLY
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptField.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptField.java
similarity index 83%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptField.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptField.java
index fc3b1455..f9396ca5 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptField.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptField.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.annotation;
+package com.codingapi.springboot.script.annotation;
import java.lang.annotation.*;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptFunction.java
similarity index 85%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptFunction.java
index f027bc36..2b2a466d 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptFunction.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.annotation;
+package com.codingapi.springboot.script.annotation;
import java.lang.annotation.*;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptType.java
similarity index 79%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptType.java
index bb2fb52b..cbcaa179 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/annotation/ScriptType.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.annotation;
+package com.codingapi.springboot.script.annotation;
import java.lang.annotation.*;
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/cache/GroovyScriptCacheContext.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/cache/GroovyScriptCacheContext.java
new file mode 100644
index 00000000..bc619398
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/cache/GroovyScriptCacheContext.java
@@ -0,0 +1,149 @@
+package com.codingapi.springboot.script.cache;
+
+import com.codingapi.springboot.script.GroovyScript;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.repository.GroovyScriptRepositoryContext;
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 脚本数据上下文管理对象
+ */
+public class GroovyScriptCacheContext {
+
+ @Getter
+ private final static GroovyScriptCacheContext instance = new GroovyScriptCacheContext();
+
+ private final Map cache;
+
+ private GroovyScriptCacheContext() {
+ this.cache = new LinkedHashMap<>(16, 0.75f);
+ }
+
+ /**
+ * 更新脚本缓存
+ *
+ * @param script 脚本对象
+ */
+ public void update(GroovyScript script) {
+ if (script != null) {
+ this.cache.put(script.getKey(), script);
+ GroovyScriptRepositoryContext.getInstance().save(script);
+ }
+ }
+
+ /**
+ * 删除脚本
+ *
+ * @param key 脚本key
+ */
+ public void remove(String key) {
+ GroovyScript groovyScript = this.getGroovyScript(key);
+ if (groovyScript != null) {
+ this.cache.remove(key);
+ GroovyScriptRepositoryContext.getInstance().delete(groovyScript);
+ }
+ }
+
+ /**
+ * 获取脚本keys
+ */
+ public List keys() {
+ return this.cache.keySet().stream().toList();
+ }
+
+ /**
+ * 脚本总数量
+ *
+ * @return 总数量
+ */
+ public int count() {
+ return this.cache.size();
+ }
+
+ /**
+ * 获取脚本对象
+ *
+ * @param key 脚本key
+ * @return 脚本对象
+ */
+ public GroovyScript getGroovyScript(String key) {
+ return this.cache.get(key);
+ }
+
+ /**
+ * 获取脚本元数据信息
+ *
+ * @param key 脚本keu
+ * @return 元数据信息
+ */
+ public GroovyMetadata getGroovyMetadata(String key) {
+ GroovyScript script = this.getGroovyScript(key);
+ if (script != null) {
+ return script.toMetadata();
+ }
+ return null;
+ }
+
+ /**
+ * 获取脚本内容
+ *
+ * @param key 脚本key
+ * @return 脚本数据
+ */
+ public String getScript(String key) {
+ GroovyScript script = this.getGroovyScript(key);
+ if (script != null) {
+ return script.getScript();
+ }
+ return "";
+ }
+
+
+ /**
+ * 获取脚本编辑信息
+ *
+ * @param key 脚本可以
+ */
+ public Map getEditorScript(String key) {
+ Map map = new HashMap<>();
+ GroovyScript script = this.getGroovyScript(key);
+ if (script != null) {
+ map.put("script", script.getScript());
+ map.put("metadata", script.toMetadata());
+ }
+ return map;
+ }
+
+
+ /**
+ * 批量加载脚本
+ *
+ * @param scriptList 脚本数据
+ */
+ public void loadAll(List scriptList) {
+ if (scriptList != null) {
+ for (GroovyScript script : scriptList) {
+ if (script != null) {
+ this.cache.put(script.getKey(), script);
+ }
+ }
+ }
+ }
+
+ /**
+ * 编译脚本
+ *
+ * @param cache 是否缓存
+ */
+ public void compileAll(boolean cache) {
+ for (GroovyScript script : this.cache.values()) {
+ script.compile(cache);
+ }
+ }
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/gateway/GroovyMetadataReloadGateway.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGateway.java
similarity index 52%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/gateway/GroovyMetadataReloadGateway.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGateway.java
index ba35a0b2..eaa94ec4 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/gateway/GroovyMetadataReloadGateway.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGateway.java
@@ -1,6 +1,6 @@
-package com.codingapi.springboot.framework.script.gateway;
+package com.codingapi.springboot.script.gateway;
-import com.codingapi.springboot.framework.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
/**
* 脚本元数据刷新加载对象
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyMetadataReloadGatewayContext.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGatewayContext.java
similarity index 76%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyMetadataReloadGatewayContext.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGatewayContext.java
index 3db69b87..309b6ce0 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyMetadataReloadGatewayContext.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/gateway/GroovyMetadataReloadGatewayContext.java
@@ -1,7 +1,6 @@
-package com.codingapi.springboot.framework.script;
+package com.codingapi.springboot.script.gateway;
-import com.codingapi.springboot.framework.script.gateway.GroovyMetadataReloadGateway;
-import com.codingapi.springboot.framework.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
import lombok.Getter;
import java.util.ArrayList;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyField.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyField.java
similarity index 85%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyField.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyField.java
index 23de1518..fe5cb2ae 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyField.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyField.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.meta;
+package com.codingapi.springboot.script.meta;
import lombok.Getter;
import lombok.Setter;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyFunction.java
similarity index 92%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyFunction.java
index d872331f..888da580 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyFunction.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.meta;
+package com.codingapi.springboot.script.meta;
import lombok.Getter;
import lombok.Setter;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyMetadata.java
similarity index 92%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyMetadata.java
index de3dcde1..36910df6 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyMetadata.java
@@ -1,7 +1,7 @@
-package com.codingapi.springboot.framework.script.meta;
+package com.codingapi.springboot.script.meta;
-import com.codingapi.springboot.framework.script.annotation.ScriptType;
-import com.codingapi.springboot.framework.script.service.GroovyTypeParser;
+import com.codingapi.springboot.script.annotation.ScriptType;
+import com.codingapi.springboot.script.service.GroovyTypeParser;
import lombok.Getter;
import lombok.Setter;
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyType.java
similarity index 84%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyType.java
index 0ad3f73e..61980e3f 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/meta/GroovyType.java
@@ -1,4 +1,4 @@
-package com.codingapi.springboot.framework.script.meta;
+package com.codingapi.springboot.script.meta;
import lombok.Getter;
import lombok.Setter;
@@ -39,6 +39,9 @@ public GroovyType() {
this.functions = new ArrayList<>();
}
+ public boolean isEmpty() {
+ return this.fields.isEmpty() && this.functions.isEmpty();
+ }
public void addFunction(GroovyFunction function) {
this.functions.add(function);
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepository.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepository.java
new file mode 100644
index 00000000..ed5d9aa3
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepository.java
@@ -0,0 +1,21 @@
+package com.codingapi.springboot.script.repository;
+
+import com.codingapi.springboot.script.GroovyScript;
+
+/**
+ * GroovyScript 仓储对象
+ */
+public interface GroovyScriptRepository {
+
+ /**
+ * 保存脚本
+ * @param groovyScript 脚本对象
+ */
+ void save(GroovyScript groovyScript);
+
+ /**
+ * 删除脚本
+ * @param groovyScript 脚本对象
+ */
+ void delete(GroovyScript groovyScript);
+}
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepositoryContext.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepositoryContext.java
new file mode 100644
index 00000000..29dc826d
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/repository/GroovyScriptRepositoryContext.java
@@ -0,0 +1,42 @@
+package com.codingapi.springboot.script.repository;
+
+import com.codingapi.springboot.script.GroovyScript;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * GroovyScriptRepository 上下文对象
+ */
+public class GroovyScriptRepositoryContext {
+
+ @Getter
+ private final static GroovyScriptRepositoryContext instance = new GroovyScriptRepositoryContext();
+
+ private GroovyScriptRepositoryContext() {
+
+ }
+
+ @Setter
+ private GroovyScriptRepository groovyScriptRepository = new GroovyScriptRepository() {
+ @Override
+ public void save(GroovyScript groovyScript) {
+
+ }
+
+ @Override
+ public void delete(GroovyScript groovyScript) {
+
+ }
+ };
+
+ public void save(GroovyScript groovyScript) {
+ this.groovyScriptRepository.save(groovyScript);
+ }
+
+
+ public void delete(GroovyScript groovyScript) {
+ this.groovyScriptRepository.delete(groovyScript);
+ }
+
+
+}
diff --git a/springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyMetadataParserService.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyMetadataParserService.java
new file mode 100644
index 00000000..c88b997f
--- /dev/null
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyMetadataParserService.java
@@ -0,0 +1,99 @@
+package com.codingapi.springboot.script.service;
+
+import com.codingapi.springboot.script.GroovyScript;
+import com.codingapi.springboot.script.meta.GroovyField;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.meta.GroovyType;
+
+import java.util.Map;
+
+/**
+ * 脚本元数据解析对象
+ */
+public class GroovyMetadataParserService {
+
+ private final GroovyScript script;
+
+ private final GroovyMetadata groovyMetadata;
+
+ public GroovyMetadataParserService(GroovyScript script) {
+ this.script = script;
+ this.groovyMetadata = new GroovyMetadata();
+ this.groovyMetadata.setMainMethod(script.getMethod());
+ this.groovyMetadata.setDescription(script.getDescription());
+ }
+
+
+ private void loadRequestTypes() {
+ Map> requests = script.getRequests();
+ if (requests != null && !requests.isEmpty()) {
+ for (Class> objClass : requests.values()) {
+ this.groovyMetadata.buildType(objClass);
+ }
+ }
+ }
+
+ private void loadBindTypes() {
+ Map> binds = script.getBinds();
+ if (binds != null && !binds.isEmpty()) {
+ for (Class> objClass : binds.values()) {
+ this.groovyMetadata.buildType(objClass);
+ }
+ }
+ }
+
+ private void loadReturnType() {
+ Class> returnTypeClass = this.script.getReturnType();
+ this.groovyMetadata.buildType(returnTypeClass);
+ this.groovyMetadata.setReturnType(returnTypeClass.getSimpleName());
+ }
+
+
+ private void loadRequests() {
+ Map> requests = script.getRequests();
+ if (requests != null && !requests.isEmpty()) {
+ for (String key : requests.keySet()) {
+ Class> objClass = requests.get(key);
+ String dataType = objClass.getSimpleName();
+ GroovyField groovyField = new GroovyField();
+ groovyField.setDataType(dataType);
+ groovyField.setName(key);
+ GroovyType groovyType = this.groovyMetadata.getType(dataType);
+ if (groovyType != null) {
+ groovyField.setDescription(groovyType.getDescription());
+ }
+ this.groovyMetadata.addRequest(groovyField);
+ }
+ }
+ }
+
+ private void loadBinds() {
+ Map> binds = script.getBinds();
+ if (binds != null && !binds.isEmpty()) {
+ for (String key : binds.keySet()) {
+ Class> objClass = binds.get(key);
+ GroovyField groovyField = new GroovyField();
+ String dataType = objClass.getSimpleName();
+ groovyField.setDataType(dataType);
+ groovyField.setName(key);
+ GroovyType groovyType = this.groovyMetadata.getType(dataType);
+ if (groovyType != null) {
+ groovyField.setDescription(groovyType.getDescription());
+ }
+ this.groovyMetadata.addBind(groovyField);
+ }
+ }
+ }
+
+
+ public GroovyMetadata parser() {
+ this.loadRequestTypes();
+ this.loadBindTypes();
+ this.loadReturnType();
+
+ this.loadRequests();
+ this.loadBinds();
+ return groovyMetadata;
+ }
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/GroovyTypeParser.java b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyTypeParser.java
similarity index 89%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/GroovyTypeParser.java
rename to springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyTypeParser.java
index c29cf655..c31a064e 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/GroovyTypeParser.java
+++ b/springboot-starter-script/src/main/java/com/codingapi/springboot/script/service/GroovyTypeParser.java
@@ -1,11 +1,11 @@
-package com.codingapi.springboot.framework.script.service;
-
-import com.codingapi.springboot.framework.script.annotation.ScriptField;
-import com.codingapi.springboot.framework.script.annotation.ScriptFunction;
-import com.codingapi.springboot.framework.script.meta.GroovyField;
-import com.codingapi.springboot.framework.script.meta.GroovyFunction;
-import com.codingapi.springboot.framework.script.meta.GroovyMetadata;
-import com.codingapi.springboot.framework.script.meta.GroovyType;
+package com.codingapi.springboot.script.service;
+
+import com.codingapi.springboot.script.annotation.ScriptField;
+import com.codingapi.springboot.script.annotation.ScriptFunction;
+import com.codingapi.springboot.script.meta.GroovyField;
+import com.codingapi.springboot.script.meta.GroovyFunction;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.meta.GroovyType;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
diff --git a/springboot-starter-script/src/test/java/com/codingapi/springboot/script/GroovyScriptRuntimeContextTest.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/GroovyScriptRuntimeContextTest.java
new file mode 100644
index 00000000..ea735153
--- /dev/null
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/GroovyScriptRuntimeContextTest.java
@@ -0,0 +1,106 @@
+package com.codingapi.springboot.script;
+
+import com.alibaba.fastjson.JSON;
+import com.codingapi.springboot.script.meta.GroovyMetadata;
+import com.codingapi.springboot.script.request.MyScriptRequest;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class GroovyScriptRuntimeContextTest {
+
+ @Test
+ void voidInvoke() {
+
+ String script = """
+ def run(request){
+ println(request)
+ }
+ """;
+
+ GroovyScript groovyScript = GroovyScript.createInvoke("voidInvoke", script, "run", Void.class, Map.of("request", Integer.class));
+ long t1 = System.currentTimeMillis();
+ groovyScript.invoke(Map.of("request",100));
+ long t2 = System.currentTimeMillis();
+ System.out.println("groovy time:" + (t2 - t1));
+
+ }
+
+
+ @Test
+ void metaTest() {
+ String script = """
+
+ def run(request){
+ return request.count;
+ }
+ """;
+
+ MyScriptRequest request = new MyScriptRequest(100);
+
+ GroovyScript groovyScript = GroovyScript.createInvoke("metaTest",
+ script, "这是一个run函数,返回的格式为int类型。","run", Integer.class, Map.of("request", MyScriptRequest.class));
+
+ GroovyMetadata metadata = groovyScript.toMetadata();
+ System.out.println(JSON.toJSONString(metadata));
+ assertEquals(1, metadata.getRequests().size());
+
+ long t1 = System.currentTimeMillis();
+ int result = groovyScript.invoke(request);
+ long t2 = System.currentTimeMillis();
+ System.out.println("groovy time:" + (t2 - t1));
+ assertEquals(100, result);
+ }
+
+ @Test
+ void run() {
+
+ String script = " return $request; ";
+
+
+ GroovyScript groovyScript = GroovyScript.createRun("run",
+ script, Integer.class, Map.of("$request", Integer.class));
+
+
+ long t1 = System.currentTimeMillis();
+ int result = groovyScript.run(Map.of("$request",100));
+ long t2 = System.currentTimeMillis();
+ System.out.println("groovy time:" + (t2 - t1));
+
+ assertEquals(100, result);
+ }
+
+ @Test
+ void invoke() {
+
+ String script = """
+ def run(request){
+ return request;
+ }
+ """;
+
+ GroovyScript groovyScript = GroovyScript.createInvoke("invoke",
+ script, "run", Integer.class, Map.of("request", Integer.class));
+
+ long t1 = System.currentTimeMillis();
+ int result = groovyScript.invoke(100);
+ long t2 = System.currentTimeMillis();
+ System.out.println("groovy time:" + (t2 - t1));
+
+ assertEquals(100, result);
+ }
+
+ @Test
+ void batchInvoke() {
+ int count = 100;
+ invoke();
+ long t1 = System.currentTimeMillis();
+ for (int i = 0; i < count; i++) {
+ invoke();
+ }
+ long t2 = System.currentTimeMillis();
+ System.out.println("total time:" + (t2 - t1));
+ }
+}
\ No newline at end of file
diff --git a/springboot-starter-script/src/test/java/com/codingapi/springboot/script/TestApplication.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/TestApplication.java
new file mode 100644
index 00000000..99600f42
--- /dev/null
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/TestApplication.java
@@ -0,0 +1,13 @@
+package com.codingapi.springboot.script;
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class TestApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(TestApplication.class,args);
+ }
+}
diff --git a/springboot-starter/src/test/java/com/codingapi/springboot/framework/script/TransactionGroovyScriptRunningContextTest.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/TransactionGroovyScriptRuntimeContextTest.java
similarity index 57%
rename from springboot-starter/src/test/java/com/codingapi/springboot/framework/script/TransactionGroovyScriptRunningContextTest.java
rename to springboot-starter-script/src/test/java/com/codingapi/springboot/script/TransactionGroovyScriptRuntimeContextTest.java
index 43564fd5..73338f5c 100644
--- a/springboot-starter/src/test/java/com/codingapi/springboot/framework/script/TransactionGroovyScriptRunningContextTest.java
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/TransactionGroovyScriptRuntimeContextTest.java
@@ -1,23 +1,22 @@
-package com.codingapi.springboot.framework.script;
+package com.codingapi.springboot.script;
-import com.codingapi.springboot.framework.entity.MyTest;
-import com.codingapi.springboot.framework.repository.MyTestRepository;
-import com.codingapi.springboot.framework.script.request.GroovyBindObjectBuilder;
-import com.codingapi.springboot.framework.script.request.GroovyRunningScript;
-import com.codingapi.springboot.framework.script.request.MyScriptRequest;
+import com.codingapi.springboot.script.entity.MyTest;
+import com.codingapi.springboot.script.repository.MyTestRepository;
+import com.codingapi.springboot.script.request.MyScriptRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@Transactional
-class TransactionGroovyScriptRunningContextTest {
+class TransactionGroovyScriptRuntimeContextTest {
@Autowired
private MyTestRepository myTestRepository;
@@ -37,16 +36,16 @@ def run(request){
myTestRepository.deleteAll();
List list = myTestRepository.findAll();
assertTrue(list.isEmpty());
- GroovyScriptRunner scriptRunner = new GroovyScriptRunner(100,GroovyScriptRunner.TransactionMode.COMMIT);
- scriptRunner.compile(script);
- GroovyRunningScript runningScript = new GroovyRunningScript<>(script,
+
+ GroovyScript groovyScript = GroovyScript.createInvoke("transactionCommitRun",
+ script,
+ "run",
Void.class,
- GroovyBindObjectBuilder.builder().add("$repository",myTestRepository),
- GroovyBindObjectBuilder.builder().add("request",request)
- );
+ Map.of("$repository", myTestRepository.getClass()),
+ Map.of("request", request.getClass()));
long t1 = System.currentTimeMillis();
- scriptRunner.invoke(runningScript);
+ groovyScript.invoke(TransactionMode.COMMIT, Map.of("$repository", myTestRepository), request);
long t2 = System.currentTimeMillis();
System.out.println("groovy time:" + (t2 - t1));
@@ -72,17 +71,10 @@ def run(request){
List list = myTestRepository.findAll();
assertTrue(list.isEmpty());
- GroovyScriptRunner scriptRunner = new GroovyScriptRunner(100, GroovyScriptRunner.TransactionMode.READONLY);
- scriptRunner.compile(script);
-
- GroovyRunningScript runningScript = new GroovyRunningScript<>(script,
- Void.class,
- GroovyBindObjectBuilder.builder().add("$repository",myTestRepository),
- GroovyBindObjectBuilder.builder().add("request",request)
- );
+ GroovyScript groovyScript = GroovyScript.createInvoke("transactionOnlyReadRun", script, "run", Void.class, Map.of("$repository", myTestRepository.getClass()), Map.of("request", request.getClass()));
long t1 = System.currentTimeMillis();
- scriptRunner.invoke(runningScript);
+ groovyScript.invoke(TransactionMode.READONLY, Map.of("$repository", myTestRepository), request);
long t2 = System.currentTimeMillis();
System.out.println("groovy time:" + (t2 - t1));
diff --git a/springboot-starter-script/src/test/java/com/codingapi/springboot/script/entity/MyTest.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/entity/MyTest.java
new file mode 100644
index 00000000..f489cba4
--- /dev/null
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/entity/MyTest.java
@@ -0,0 +1,23 @@
+package com.codingapi.springboot.script.entity;
+
+import com.codingapi.springboot.script.annotation.ScriptField;
+import com.codingapi.springboot.script.annotation.ScriptType;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import lombok.Data;
+
+@Data
+@Entity
+@ScriptType(description = "test")
+public class MyTest {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @ScriptField(name = "id", description = "id")
+ private Long id;
+
+ @ScriptField(name = "name", description = "name")
+ private String name;
+}
diff --git a/springboot-starter-script/src/test/java/com/codingapi/springboot/script/repository/MyTestRepository.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/repository/MyTestRepository.java
new file mode 100644
index 00000000..642ca4cc
--- /dev/null
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/repository/MyTestRepository.java
@@ -0,0 +1,10 @@
+package com.codingapi.springboot.script.repository;
+
+import com.codingapi.springboot.script.entity.MyTest;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MyTestRepository extends JpaRepository {
+
+}
diff --git a/springboot-starter/src/test/java/com/codingapi/springboot/framework/script/request/MyScriptRequest.java b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/request/MyScriptRequest.java
similarity index 64%
rename from springboot-starter/src/test/java/com/codingapi/springboot/framework/script/request/MyScriptRequest.java
rename to springboot-starter-script/src/test/java/com/codingapi/springboot/script/request/MyScriptRequest.java
index a6404981..c68630a5 100644
--- a/springboot-starter/src/test/java/com/codingapi/springboot/framework/script/request/MyScriptRequest.java
+++ b/springboot-starter-script/src/test/java/com/codingapi/springboot/script/request/MyScriptRequest.java
@@ -1,16 +1,14 @@
-package com.codingapi.springboot.framework.script.request;
+package com.codingapi.springboot.script.request;
-import com.codingapi.springboot.framework.entity.MyTest;
-import com.codingapi.springboot.framework.repository.MyTestRepository;
-import com.codingapi.springboot.framework.script.annotation.ScriptField;
-import com.codingapi.springboot.framework.script.annotation.ScriptFunction;
-import com.codingapi.springboot.framework.script.annotation.ScriptType;
+import com.codingapi.springboot.script.entity.MyTest;
+import com.codingapi.springboot.script.repository.MyTestRepository;
+import com.codingapi.springboot.script.annotation.ScriptField;
+import com.codingapi.springboot.script.annotation.ScriptFunction;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
-@ScriptType(description = "我的测试对象")
public class MyScriptRequest {
@ScriptField(name = "count", description = "总数量")
diff --git a/springboot-starter-script/src/test/resources/application.properties b/springboot-starter-script/src/test/resources/application.properties
new file mode 100644
index 00000000..967207fa
--- /dev/null
+++ b/springboot-starter-script/src/test/resources/application.properties
@@ -0,0 +1,7 @@
+spring.datasource.driver-class-name=org.h2.Driver
+spring.datasource.url=jdbc:h2:file:./test.db
+spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
+spring.jpa.hibernate.ddl-auto=create-drop
+spring.jpa.show-sql=true
+
+codingapi.framework.event.transaction.enable=true
\ No newline at end of file
diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml
index 2ab67bfa..867467c2 100644
--- a/springboot-starter-security/pom.xml
+++ b/springboot-starter-security/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.49
+ 3.4.50
springboot-starter-security
diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml
index 51b842f7..256ddf6a 100644
--- a/springboot-starter/pom.xml
+++ b/springboot-starter/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.49
+ 3.4.50
springboot-starter
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java
deleted file mode 100644
index aefdf8c2..00000000
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.codingapi.springboot.framework.script;
-
-import com.codingapi.springboot.framework.script.request.GroovyBindObject;
-import com.codingapi.springboot.framework.script.request.GroovyRunningScript;
-import lombok.Getter;
-
-import java.util.List;
-
-/**
- * groovy script 执行上下文对象,事务模式为可写入
- */
-public class GroovyScriptRunningContext {
-
- private final GroovyScriptRunner scriptRunner;
-
- public static final int MAX_CACHE_SIZE = 1000;
-
- @Getter
- private static GroovyScriptRunningContext instance = new GroovyScriptRunningContext(MAX_CACHE_SIZE);
-
- private GroovyScriptRunningContext(int maxCacheSize) {
- this.scriptRunner = new GroovyScriptRunner(maxCacheSize);
- }
-
- /**
- * 更新最大的缓存大小
- */
- public void setMaxCacheSize(int maxCacheSize) {
- instance = new GroovyScriptRunningContext(maxCacheSize);
- }
-
- /**
- * 清空缓存对象
- */
- public void clearCache() {
- this.scriptRunner.clearCache();
- }
-
- /**
- * 缓存大小
- */
- public int cacheSize() {
- return this.scriptRunner.cacheSize();
- }
-
- /**
- * 编译脚本
- *
- * @param script 脚本内容
- * @param cache 是否缓存
- */
- public void compile(String script, boolean cache) {
- this.scriptRunner.compile(script, cache);
- }
-
-
- /**
- * 编译脚本,非缓存模式
- *
- * @param script 脚本内容
- */
- public void compile(String script) {
- this.compile(script, false);
- }
-
- /**
- * 执行函数脚本
- *
- * @param script 脚本内容
- * @param returnType 返回类型
- * @return 返回数据
- */
- public T run(String script, Class returnType) {
- return this.scriptRunner.run(script, returnType, null);
- }
-
- /**
- * 执行函数脚本
- *
- * @param script 脚本内容
- * @param returnType 返回类型
- * @param binds 绑定数据对象
- * @return 返回数据
- */
- public T run(String script, Class returnType, List binds) {
- return this.scriptRunner.run(script, returnType, binds);
- }
-
- /**
- * 执行函数脚本
- *
- * @param method 函数名称
- * @param script 脚本内容
- * @param returnType 返回类型
- * @param binds 绑定数据对象
- * @param args 函数参数
- * @return 返回数据
- */
- public T invoke(String method, String script, Class returnType, List binds, Object... args) {
- return this.scriptRunner.invoke(method, script, returnType, binds, args);
- }
-
- /**
- * 运行脚本
- *
- * @param method 函数名称
- * @param script 脚本内容
- * @param returnType 返回类型
- * @param args 函数参数
- * @return 返回数据
- */
- public T invoke(String method, String script, Class returnType, Object... args) {
- return this.invoke(method, script, returnType, null, args);
- }
-
-
- /**
- * 执行脚本
- *
- * @param request 脚本参数
- * @return 返回数据
- */
- public T invoke(GroovyRunningScript request) {
- return this.invoke(request.getMethod(), request.getScript(), request.getReturnType(), request.getBinds(), request.getParams());
- }
-
-}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java
deleted file mode 100644
index 4acf4f32..00000000
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package com.codingapi.springboot.framework.script.request;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 运行时绑定对象
- */
-@Getter
-@AllArgsConstructor
-public class GroovyBindObject {
-
- /**
- * 绑定的访问对象
- */
- private String name;
- /**
- * 绑定的对象实例
- */
- private Object object;
-
-
- public static List of(String key, Object value) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key, value));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- return list;
- }
-
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5, String key6, Object value6) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- list.add(new GroovyBindObject(key6, value6));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5, String key6, Object value6, String key7, Object value7) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- list.add(new GroovyBindObject(key6, value6));
- list.add(new GroovyBindObject(key7, value7));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5, String key6, Object value6, String key7, Object value7, String key8, Object value8) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- list.add(new GroovyBindObject(key6, value6));
- list.add(new GroovyBindObject(key7, value7));
- list.add(new GroovyBindObject(key8, value8));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5, String key6, Object value6, String key7, Object value7, String key8, Object value8, String key9, Object value9) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- list.add(new GroovyBindObject(key6, value6));
- list.add(new GroovyBindObject(key7, value7));
- list.add(new GroovyBindObject(key8, value8));
- list.add(new GroovyBindObject(key9, value9));
- return list;
- }
-
- public static List of(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4, String key5, Object value5, String key6, Object value6, String key7, Object value7, String key8, Object value8, String key9, Object value9, String key10, Object value10) {
- List list = new ArrayList<>();
- list.add(new GroovyBindObject(key1, value1));
- list.add(new GroovyBindObject(key2, value2));
- list.add(new GroovyBindObject(key3, value3));
- list.add(new GroovyBindObject(key4, value4));
- list.add(new GroovyBindObject(key5, value5));
- list.add(new GroovyBindObject(key6, value6));
- list.add(new GroovyBindObject(key7, value7));
- list.add(new GroovyBindObject(key8, value8));
- list.add(new GroovyBindObject(key9, value9));
- list.add(new GroovyBindObject(key10, value10));
- return list;
- }
-
-}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObjectBuilder.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObjectBuilder.java
deleted file mode 100644
index 07b69ce5..00000000
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObjectBuilder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.codingapi.springboot.framework.script.request;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GroovyBindObjectBuilder {
-
- private final List list;
-
- private GroovyBindObjectBuilder() {
- this.list = new ArrayList<>();
- }
-
- public static GroovyBindObjectBuilder builder(){
- return new GroovyBindObjectBuilder();
- }
-
- public GroovyBindObjectBuilder add(String name, Object value) {
- this.list.add(new GroovyBindObject(name, value));
- return this;
- }
-
-
- public List build() {
- return this.list;
- }
-}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyRunningScript.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyRunningScript.java
deleted file mode 100644
index a9209f9c..00000000
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyRunningScript.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.codingapi.springboot.framework.script.request;
-
-import com.codingapi.springboot.framework.script.GroovyMetadataReloadGatewayContext;
-import com.codingapi.springboot.framework.script.meta.GroovyMetadata;
-import com.codingapi.springboot.framework.script.service.GroovyMetadataParserService;
-import lombok.Getter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 脚本执行对象
- *
- * @param 返回格式
- */
-@Getter
-public class GroovyRunningScript {
-
- /**
- * 脚本函数名称
- */
- private final String method;
-
- /**
- * 脚本代码
- */
- private final String script;
-
- /**
- * 脚本说明
- */
- private final String description;
-
- /**
- * 返回数据类型
- */
- private final Class returnType;
-
- /**
- * 请求参数对象
- */
- private final List requests;
-
- /**
- * 绑定数据对象
- */
- private final List binds;
-
- /**
- * 脚本元数据信息
- */
- private GroovyMetadata metadata;
-
-
- public GroovyRunningScript(String method, String script, String description, Class returnType, List binds, List requests) {
- this.method = method;
- this.script = script;
- this.description = description;
- this.returnType = returnType;
- this.requests = requests;
- this.binds = binds;
- }
-
- public GroovyRunningScript(String method, String script, String description, Class returnType, GroovyBindObjectBuilder bindBuilder, GroovyBindObjectBuilder requestBuilder) {
- this(method, script, description, returnType, bindBuilder != null ? bindBuilder.build() : null, requestBuilder != null ? requestBuilder.build() : null);
- }
-
-
- public GroovyRunningScript(String method, String script, String description, Class returnType, GroovyBindObjectBuilder requestBuilder) {
- this(method, script, description, returnType, null, requestBuilder);
- }
-
- public GroovyRunningScript(String script, Class returnType, GroovyBindObjectBuilder bindBuilder, GroovyBindObjectBuilder requestBuilder) {
- this("run", script, null, returnType, bindBuilder, requestBuilder);
- }
-
- public GroovyRunningScript(String script, String description, Class returnType, GroovyBindObjectBuilder bindBuilder, GroovyBindObjectBuilder requestBuilder) {
- this("run", script, description, returnType, bindBuilder, requestBuilder);
- }
-
- public GroovyRunningScript(String script,String description, Class returnType, GroovyBindObjectBuilder requestBuilder) {
- this("run", script, returnType, null, requestBuilder);
- }
-
- public GroovyRunningScript(String script,Class returnType, GroovyBindObjectBuilder requestBuilder) {
- this("run", script,null, returnType, null, requestBuilder);
- }
-
- /**
- * 获取参数
- */
- public Object[] getParams() {
- List