From afa44b0c23165a67b331ded958775f33bdca4225 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 4 Aug 2025 11:48:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=88=A9=E7=94=A8js?= =?UTF-8?q?qlparser=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E6=8B=BC=E8=A3=85sql=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1469817729548288]利用jsqlparser新增一个方便拼装sql的工具类 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1469817729548288 --- src/main/java/neatlogic/framework/sqlgenerator/$sql.java | 4 ++++ .../java/neatlogic/framework/sqlgenerator/$sqlTest.java | 7 ++++++- .../neatlogic/framework/sqlgenerator/ExpressionVo.java | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/framework/sqlgenerator/$sql.java b/src/main/java/neatlogic/framework/sqlgenerator/$sql.java index 5c003c150..a7a84c961 100644 --- a/src/main/java/neatlogic/framework/sqlgenerator/$sql.java +++ b/src/main/java/neatlogic/framework/sqlgenerator/$sql.java @@ -79,6 +79,10 @@ public class $sql { return exp(null, leftExpressionVo, operationType, rightExpressionVo, null); } + public static ExpressionVo exp(String leftParenthesis, ExpressionVo leftExpressionVo, String rightParenthesis) { + return exp(leftParenthesis, leftExpressionVo, "and", null, rightParenthesis); + } + public static ExpressionVo exp(String leftColumn, String operationSymbol, String rightColumn) { return new ExpressionVo(leftColumn, operationSymbol, rightColumn); } diff --git a/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java b/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java index 678083a43..1358e4754 100644 --- a/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java +++ b/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java @@ -617,7 +617,12 @@ public class $sqlTest { $sql.addWhereExpression(plainSelect, $sql.exp("(", $sql.exp("uuid", "=", "name"), "and", $sql.exp("name", "=", "uuid"), ")")); Assert.isTrue(Objects.equals(plainSelect.toString(), "SELECT FROM tenant WHERE (uuid = name AND name = uuid)"), "测试失败"); methodNameList.remove("public static ExpressionVo exp(String, ExpressionVo, String, ExpressionVo, String)"); - +// public static ExpressionVo exp(String, ExpressionVo, String) + plainSelect = $sql.from("tenant"); + ExpressionVo orExp = $sql.exp($sql.exp("uuid", "=", "name"), "or", $sql.exp("name", "=", "uuid")); + $sql.addWhereExpression(plainSelect, $sql.exp("(", orExp, ")")); + Assert.isTrue(Objects.equals(plainSelect.toString(), "SELECT FROM tenant WHERE (uuid = name OR name = uuid)"), "测试失败"); + methodNameList.remove("public static ExpressionVo exp(String, ExpressionVo, String)"); } private static void testFun(List methodNameList) { diff --git a/src/main/java/neatlogic/framework/sqlgenerator/ExpressionVo.java b/src/main/java/neatlogic/framework/sqlgenerator/ExpressionVo.java index d7edfa2d2..65b063131 100644 --- a/src/main/java/neatlogic/framework/sqlgenerator/ExpressionVo.java +++ b/src/main/java/neatlogic/framework/sqlgenerator/ExpressionVo.java @@ -34,6 +34,10 @@ public class ExpressionVo { private final String operationSymbol; private final String type; + ExpressionVo(String leftParenthesis, ExpressionVo leftExpressionVo, String rightParenthesis) { + this(leftParenthesis, leftExpressionVo, "and", null, rightParenthesis); + } + ExpressionVo(ExpressionVo leftExpressionVo, String operationType, ExpressionVo rightExpressionVo) { this(null, leftExpressionVo, operationType, rightExpressionVo, null); } -- Gitee From ab0eae861394e3268ba353f72eedde6c2917f7a2 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 4 Aug 2025 17:21:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=88=A9=E7=94=A8js?= =?UTF-8?q?qlparser=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E6=8B=BC=E8=A3=85sql=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1469817729548288]利用jsqlparser新增一个方便拼装sql的工具类 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1469817729548288 --- .../neatlogic/framework/sqlgenerator/$sql.java | 11 +++++++++++ .../neatlogic/framework/sqlgenerator/$sqlTest.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/neatlogic/framework/sqlgenerator/$sql.java b/src/main/java/neatlogic/framework/sqlgenerator/$sql.java index a7a84c961..e96aecf7a 100644 --- a/src/main/java/neatlogic/framework/sqlgenerator/$sql.java +++ b/src/main/java/neatlogic/framework/sqlgenerator/$sql.java @@ -335,6 +335,17 @@ public class $sql { return plainSelect; } + public static void setDistinct(PlainSelect plainSelect, boolean distinct) { + if (plainSelect == null) { + return; + } + if (distinct) { + plainSelect.setDistinct(new Distinct()); + } else { + plainSelect.setDistinct(null); + } + } + public static void addSelectColumn(PlainSelect plainSelect, String columnName) { addSelectColumn(plainSelect, columnName, null); } diff --git a/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java b/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java index 1358e4754..f2abd2fa4 100644 --- a/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java +++ b/src/main/java/neatlogic/framework/sqlgenerator/$sqlTest.java @@ -32,6 +32,7 @@ public class $sqlTest { List methodNameList = getMethodNameList($sql.class); testSql(methodNameList); testForm(methodNameList); + testSetDistinct(methodNameList); testSetSelectColumn(methodNameList); testAddSelectColumn(methodNameList); testAddJoin(methodNameList); @@ -168,6 +169,19 @@ public class $sqlTest { methodNameList.remove("public static void from(PlainSelect, String, String, String)"); } + private static void testSetDistinct(List methodNameList) { +// public static void setDistinct(PlainSelect, boolean) + PlainSelect plainSelect = $sql.from("tenant"); + $sql.setDistinct(plainSelect, true); + $sql.setSelectColumn(plainSelect, "name"); + System.out.println("plainSelect = " + plainSelect); + Assert.isTrue(Objects.equals(plainSelect.toString(), "SELECT DISTINCT name FROM tenant"), "测试失败"); + + $sql.setDistinct(plainSelect, false); + $sql.setSelectColumn(plainSelect, "uuid"); + Assert.isTrue(Objects.equals(plainSelect.toString(), "SELECT uuid FROM tenant"), "测试失败"); + methodNameList.remove("public static void setDistinct(PlainSelect, boolean)"); + } private static void testSetSelectColumn(List methodNameList) { PlainSelect plainSelect = $sql.from("tenant"); // public static void setSelectColumn(PlainSelect, String) -- Gitee