From 1a179780e3be7286268af9002303fede749bb036 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Thu, 22 Jun 2023 14:28:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20With=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=94=AF=E6=8C=81=E6=B7=B1=E5=BA=A6=E5=85=8B=E9=9A=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/query/BaseQueryWrapper.java | 1 + .../java/com/mybatisflex/core/query/With.java | 18 ++++++++++++++-- .../mybatisflex/core/query/WithDetail.java | 2 +- .../com/mybatisflex/core/query/WithItem.java | 21 ++++++++++++++++--- .../core/query/WithSelectDetail.java | 16 +++++++++++++- .../core/query/WithStringDetail.java | 13 +++++++++++- .../core/query/WithValuesDetail.java | 20 ++++++++++++++++-- 7 files changed, 81 insertions(+), 10 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java index 4683a378..96621c54 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java @@ -267,6 +267,7 @@ public class BaseQueryWrapper> implements CloneSup try { T clone = (T) super.clone(); // deep clone ... + clone.with = ObjectUtil.clone(this.with); clone.queryTables = CollectionUtil.cloneArrayList(this.queryTables); clone.selectColumns = CollectionUtil.cloneArrayList(this.selectColumns); clone.joins = CollectionUtil.cloneArrayList(this.joins); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/With.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/With.java index 3ae2fe11..87bf7f83 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/With.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/With.java @@ -17,13 +17,14 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.util.ArrayUtil; +import com.mybatisflex.core.util.CollectionUtil; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class With implements Serializable { +public class With implements CloneSupport { private boolean recursive; private List withItems; @@ -79,4 +80,17 @@ public class With implements Serializable { } return paramValues; } + + @Override + public With clone() { + try { + With clone = (With) super.clone(); + // deep clone ... + clone.withItems = CollectionUtil.cloneArrayList(this.withItems); + return clone; + } catch (CloneNotSupportedException e) { + throw FlexExceptions.wrap(e); + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java index 03a67c21..9b649557 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java @@ -17,7 +17,7 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; -public interface WithDetail { +public interface WithDetail extends CloneSupport { String toSql(IDialect dialect); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java index ddb29a68..db19a4de 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java @@ -16,13 +16,14 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.util.CollectionUtil; +import com.mybatisflex.core.util.ObjectUtil; import com.mybatisflex.core.util.StringUtil; -import java.io.Serializable; import java.util.List; -public class WithItem implements Serializable { +public class WithItem implements CloneSupport { private String name; private List params; @@ -64,7 +65,7 @@ public class WithItem implements Serializable { public String toSql(IDialect dialect) { StringBuilder sql = new StringBuilder(name); if (CollectionUtil.isNotEmpty(params)){ - sql.append("(").append(StringUtil.join(", ",params)).append(")"); + sql.append("(").append(StringUtil.join(", ", params)).append(")"); } sql.append(" AS ("); sql.append(withDetail.toSql(dialect)); @@ -74,4 +75,18 @@ public class WithItem implements Serializable { public Object[] getParamValues() { return withDetail.getParamValues(); } + + @Override + public WithItem clone() { + try { + WithItem clone = (WithItem) super.clone(); + // deep clone ... + clone.withDetail = ObjectUtil.clone(this.withDetail); + clone.params = CollectionUtil.newArrayList(this.params); + return clone; + } catch (CloneNotSupportedException e) { + throw FlexExceptions.wrap(e); + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithSelectDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithSelectDetail.java index 6128c7a8..bf0c52c6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithSelectDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithSelectDetail.java @@ -16,8 +16,9 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexExceptions; -public class WithSelectDetail implements WithDetail{ +public class WithSelectDetail implements WithDetail { private QueryWrapper queryWrapper; @@ -45,4 +46,17 @@ public class WithSelectDetail implements WithDetail{ public Object[] getParamValues() { return queryWrapper.getValueArray(); } + + @Override + public WithSelectDetail clone() { + try { + WithSelectDetail clone = (WithSelectDetail) super.clone(); + // deep clone ... + clone.queryWrapper = this.queryWrapper.clone(); + return clone; + } catch (CloneNotSupportedException e) { + throw FlexExceptions.wrap(e); + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithStringDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithStringDetail.java index c46dbcb3..8b3c7e48 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithStringDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithStringDetail.java @@ -16,8 +16,9 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexExceptions; -public class WithStringDetail implements WithDetail{ +public class WithStringDetail implements WithDetail { private String rawSQL; private Object[] params; @@ -52,4 +53,14 @@ public class WithStringDetail implements WithDetail{ public Object[] getParamValues() { return params; } + + @Override + public WithStringDetail clone() { + try { + return (WithStringDetail) super.clone(); + } catch (CloneNotSupportedException e) { + throw FlexExceptions.wrap(e); + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java index a52ba13a..033ad642 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java @@ -16,12 +16,14 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexExceptions; +import com.mybatisflex.core.util.CollectionUtil; import com.mybatisflex.core.util.StringUtil; import java.util.ArrayList; import java.util.List; -public class WithValuesDetail implements WithDetail{ +public class WithValuesDetail implements WithDetail { private List values; private QueryWrapper queryWrapper; @@ -49,7 +51,7 @@ public class WithValuesDetail implements WithDetail{ stringValues.add(String.valueOf(value)); } StringBuilder sql = new StringBuilder("VALUES (") - .append(StringUtil.join(", ",stringValues)).append(") "); + .append(StringUtil.join(", ", stringValues)).append(") "); return sql.append(dialect.buildNoSelectSql(queryWrapper)).toString(); } @@ -57,4 +59,18 @@ public class WithValuesDetail implements WithDetail{ public Object[] getParamValues() { return queryWrapper.getValueArray(); } + + @Override + public WithValuesDetail clone() { + try { + WithValuesDetail clone = (WithValuesDetail) super.clone(); + // deep clone ... + clone.values = CollectionUtil.newArrayList(this.values); + clone.queryWrapper = this.queryWrapper.clone(); + return clone; + } catch (CloneNotSupportedException e) { + throw FlexExceptions.wrap(e); + } + } + }