mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
feat: QueryWrapper 支持 clone() 方法。
This commit is contained in:
parent
d5dbd80b20
commit
c33a9c89d2
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -96,6 +97,14 @@ public class ArithmeticQueryColumn extends QueryColumn {
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArithmeticQueryColumn clone() {
|
||||
ArithmeticQueryColumn clone = (ArithmeticQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.arithmeticInfos = CollectionUtil.cloneValue(this.arithmeticInfos, ArrayList::new);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
@ -107,12 +116,13 @@ public class ArithmeticQueryColumn extends QueryColumn {
|
||||
}
|
||||
|
||||
|
||||
static class ArithmeticInfo {
|
||||
static class ArithmeticInfo implements CloneSupport<ArithmeticInfo> {
|
||||
|
||||
private String symbol;
|
||||
private Object value;
|
||||
|
||||
public ArithmeticInfo(Object value) {
|
||||
this.value = value;
|
||||
this(null, value);
|
||||
}
|
||||
|
||||
public ArithmeticInfo(String symbol, Object value) {
|
||||
@ -129,5 +139,14 @@ public class ArithmeticQueryColumn extends QueryColumn {
|
||||
}
|
||||
return index == 0 ? valueSql : symbol + valueSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArithmeticInfo clone() {
|
||||
try {
|
||||
return (ArithmeticInfo) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BaseQueryWrapper<T> implements Serializable {
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public class BaseQueryWrapper<T extends BaseQueryWrapper<T>> implements CloneSupport<T> {
|
||||
|
||||
|
||||
protected List<QueryTable> queryTables;
|
||||
@ -256,4 +259,26 @@ public class BaseQueryWrapper<T> implements Serializable {
|
||||
protected <R> R getContext(String key){
|
||||
return context == null ? null : (R) context.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T clone() {
|
||||
try {
|
||||
T clone = (T) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryTables = CollectionUtil.cloneValue(this.queryTables, ArrayList::new);
|
||||
clone.selectColumns = CollectionUtil.cloneValue(this.selectColumns, LinkedList::new);
|
||||
clone.joins = CollectionUtil.cloneValue(this.joins, LinkedList::new);
|
||||
clone.joinTables = CollectionUtil.cloneValue(this.joinTables, ArrayList::new);
|
||||
clone.whereQueryCondition = ObjectUtil.clone(this.whereQueryCondition);
|
||||
clone.groupByColumns = CollectionUtil.cloneValue(this.groupByColumns, LinkedList::new);
|
||||
clone.havingQueryCondition = ObjectUtil.clone(this.havingQueryCondition);
|
||||
clone.orderBys = CollectionUtil.cloneValue(this.orderBys, LinkedList::new);
|
||||
clone.unions = CollectionUtil.cloneValue(this.unions, ArrayList::new);
|
||||
clone.endFragments = CollectionUtil.newArrayList(this.endFragments);
|
||||
clone.context = CollectionUtil.newHashMap(this.context);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
public class Brackets extends QueryCondition {
|
||||
|
||||
private final QueryCondition childCondition;
|
||||
private QueryCondition childCondition;
|
||||
|
||||
public Brackets(QueryCondition childCondition) {
|
||||
this.childCondition = childCondition;
|
||||
@ -111,4 +112,12 @@ public class Brackets extends QueryCondition {
|
||||
"childCondition=" + childCondition +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public Brackets clone() {
|
||||
Brackets clone = (Brackets) super.clone();
|
||||
// deep clone ...
|
||||
clone.childCondition = ObjectUtil.clone(this.childCondition);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.FlexConsts;
|
||||
import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ArrayUtil;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import com.mybatisflex.core.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -56,6 +53,14 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaseQueryColumn clone() {
|
||||
CaseQueryColumn clone = (CaseQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.whens = CollectionUtil.cloneValue(this.whens, ArrayList::new);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
@ -100,14 +105,14 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
for (When when : whens) {
|
||||
values = ArrayUtil.concat(values, WrapperUtil.getValues(when.whenCondition));
|
||||
}
|
||||
if (elseValue instanceof HasParamsColumn){
|
||||
values = ArrayUtil.concat(values,((HasParamsColumn) elseValue).getParamValues());
|
||||
if (elseValue instanceof HasParamsColumn) {
|
||||
values = ArrayUtil.concat(values, ((HasParamsColumn) elseValue).getParamValues());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
public static class When {
|
||||
public static class When implements CloneSupport<When> {
|
||||
private Builder builder;
|
||||
private QueryCondition whenCondition;
|
||||
private Object thenValue;
|
||||
@ -122,9 +127,22 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
this.builder.caseQueryColumn.addWhen(this);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public When clone() {
|
||||
try {
|
||||
When clone = (When) super.clone();
|
||||
// deep clone ...
|
||||
clone.whenCondition = ObjectUtil.clone(this.whenCondition);
|
||||
clone.thenValue = ObjectUtil.cloneObject(this.thenValue);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static class Builder implements CloneSupport<Builder> {
|
||||
|
||||
private CaseQueryColumn caseQueryColumn = new CaseQueryColumn();
|
||||
|
||||
@ -140,5 +158,17 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
public CaseQueryColumn end() {
|
||||
return caseQueryColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder clone() {
|
||||
try {
|
||||
Builder clone = (Builder) super.clone();
|
||||
// deep clone ...
|
||||
clone.caseQueryColumn = this.caseQueryColumn.clone();
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.FlexConsts;
|
||||
import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ArrayUtil;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import com.mybatisflex.core.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -49,6 +46,15 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaseSearchQueryColumn clone() {
|
||||
CaseSearchQueryColumn clone = (CaseSearchQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryColumn = ObjectUtil.clone(this.queryColumn);
|
||||
clone.whens = CollectionUtil.cloneValue(this.whens, ArrayList::new);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
@ -107,7 +113,7 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum
|
||||
}
|
||||
|
||||
|
||||
public static class When {
|
||||
public static class When implements CloneSupport<When> {
|
||||
private Builder builder;
|
||||
private Object searchValue;
|
||||
private Object thenValue;
|
||||
@ -122,12 +128,28 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum
|
||||
this.builder.caseQueryColumn.addWhen(this);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public When clone() {
|
||||
try {
|
||||
When clone = (When) super.clone();
|
||||
// deep clone ...
|
||||
clone.searchValue = ObjectUtil.cloneObject(this.searchValue);
|
||||
clone.thenValue = ObjectUtil.cloneObject(this.thenValue);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static class Builder implements CloneSupport<Builder> {
|
||||
|
||||
private CaseSearchQueryColumn caseQueryColumn = new CaseSearchQueryColumn();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder(QueryColumn queryColumn) {
|
||||
this.caseQueryColumn.queryColumn = queryColumn;
|
||||
}
|
||||
@ -144,5 +166,17 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum
|
||||
public CaseSearchQueryColumn end() {
|
||||
return caseQueryColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder clone() {
|
||||
try {
|
||||
Builder clone = (Builder) super.clone();
|
||||
// deep clone ...
|
||||
clone.caseQueryColumn = this.caseQueryColumn.clone();
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>克隆支持接口。
|
||||
*
|
||||
* <p>支持序列化克隆与 {@link Object#clone()} 方法。
|
||||
*
|
||||
* @param <T> 克隆对象类型
|
||||
* @author 王帅
|
||||
* @since 2023-06-10
|
||||
*/
|
||||
public interface CloneSupport<T> extends Serializable, Cloneable {
|
||||
|
||||
/**
|
||||
* 改写 {@link Object#clone()} 方法。
|
||||
*
|
||||
* @return 克隆对象
|
||||
*/
|
||||
T clone();
|
||||
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -19,11 +19,12 @@ import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DistinctQueryColumn extends QueryColumn {
|
||||
|
||||
private final List<QueryColumn> queryColumns;
|
||||
private List<QueryColumn> queryColumns;
|
||||
|
||||
public DistinctQueryColumn(QueryColumn... queryColumns) {
|
||||
this.queryColumns = CollectionUtil.newArrayList(queryColumns);
|
||||
@ -37,4 +38,12 @@ public class DistinctQueryColumn extends QueryColumn {
|
||||
return " DISTINCT " + StringUtil.join(", ", queryColumns, queryColumn ->
|
||||
queryColumn.toSelectSql(queryTables, dialect));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistinctQueryColumn clone() {
|
||||
DistinctQueryColumn clone = (DistinctQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryColumns = CollectionUtil.cloneValue(this.queryColumns, ArrayList::new);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.FlexConsts;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
@ -88,5 +89,13 @@ public class FunctionQueryColumn extends QueryColumn implements HasParamsColumn
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionQueryColumn clone() {
|
||||
FunctionQueryColumn clone = (FunctionQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.column = ObjectUtil.clone(this.column);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
@ -26,7 +26,7 @@ import java.util.function.Supplier;
|
||||
* @author michael yang (fuhai999@gmail.com)
|
||||
* @Date: 2020/1/14
|
||||
*/
|
||||
public class Join implements Serializable {
|
||||
public class Join implements CloneSupport<Join> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -39,7 +39,7 @@ public class Join implements Serializable {
|
||||
|
||||
|
||||
protected final String type;
|
||||
protected final QueryTable queryTable;
|
||||
protected QueryTable queryTable;
|
||||
protected QueryCondition on;
|
||||
protected boolean effective;
|
||||
|
||||
@ -92,4 +92,17 @@ public class Join implements Serializable {
|
||||
sql.append(" ON ").append(on.toSql(newQueryTables, dialect));
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Join clone() {
|
||||
try {
|
||||
Join clone = (Join) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryTable = ObjectUtil.clone(this.queryTable);
|
||||
clone.on = ObjectUtil.clone(this.on);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
@ -27,7 +28,7 @@ import java.util.List;
|
||||
public class OperatorQueryCondition extends QueryCondition {
|
||||
|
||||
private final String operator;
|
||||
private final QueryCondition child;
|
||||
private QueryCondition child;
|
||||
|
||||
public OperatorQueryCondition(String operator, QueryCondition child) {
|
||||
this.operator = operator;
|
||||
@ -66,4 +67,12 @@ public class OperatorQueryCondition extends QueryCondition {
|
||||
boolean containsTable(String... tables) {
|
||||
return child != null && child.containsTable(tables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperatorQueryCondition clone() {
|
||||
OperatorQueryCondition clone = (OperatorQueryCondition) super.clone();
|
||||
// deep clone ...
|
||||
clone.child = ObjectUtil.clone(this.child);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
@ -28,7 +29,7 @@ import java.util.List;
|
||||
public class OperatorSelectCondition extends QueryCondition {
|
||||
//操作符,例如 exist, not exist
|
||||
private final String operator;
|
||||
private final QueryWrapper queryWrapper;
|
||||
private QueryWrapper queryWrapper;
|
||||
|
||||
public OperatorSelectCondition(String operator, QueryWrapper queryWrapper) {
|
||||
this.operator = operator;
|
||||
@ -69,4 +70,12 @@ public class OperatorSelectCondition extends QueryCondition {
|
||||
QueryCondition condition = queryWrapper.getWhereQueryCondition();
|
||||
return condition != null && condition.containsTable(tables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperatorSelectCondition clone() {
|
||||
OperatorSelectCondition clone = (OperatorSelectCondition) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryWrapper = ObjectUtil.clone(this.queryWrapper);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -20,7 +20,6 @@ import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
import com.mybatisflex.core.util.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
@ -28,7 +27,7 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* 查询列,描述的是一张表的字段
|
||||
*/
|
||||
public class QueryColumn implements Serializable {
|
||||
public class QueryColumn implements CloneSupport<QueryColumn> {
|
||||
|
||||
protected QueryTable table;
|
||||
protected String name;
|
||||
@ -546,4 +545,15 @@ public class QueryColumn implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public QueryColumn clone() {
|
||||
try {
|
||||
QueryColumn clone = (QueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.table = ObjectUtil.clone(this.table);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,31 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ClassUtil;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class QueryCondition implements Serializable {
|
||||
public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
|
||||
public static final String LOGIC_LIKE = "LIKE";
|
||||
public static final String LOGIC_GT = ">";
|
||||
@ -297,4 +297,22 @@ public class QueryCondition implements Serializable {
|
||||
", effective=" + effective +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryCondition clone() {
|
||||
try {
|
||||
QueryCondition clone = (QueryCondition) super.clone();
|
||||
// deep clone ...
|
||||
clone.column = ObjectUtil.clone(this.column);
|
||||
clone.value = ObjectUtil.cloneObject(this.value);
|
||||
clone.before = clone.next = null;
|
||||
for (QueryCondition x = next; x != null; x = x.next) {
|
||||
clone.next = x.clone();
|
||||
clone.next.before = this;
|
||||
}
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,30 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
public class QueryOrderBy implements Serializable {
|
||||
public class QueryOrderBy implements CloneSupport<QueryOrderBy> {
|
||||
|
||||
private QueryColumn queryColumn;
|
||||
|
||||
@ -70,4 +70,16 @@ public class QueryOrderBy implements Serializable {
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryOrderBy clone() {
|
||||
try {
|
||||
QueryOrderBy clone = (QueryOrderBy) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryColumn = ObjectUtil.clone(this.queryColumn);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -20,13 +20,12 @@ import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 查询列,描述的是一张表的字段
|
||||
*/
|
||||
public class QueryTable implements Serializable {
|
||||
public class QueryTable implements CloneSupport<QueryTable> {
|
||||
|
||||
protected String schema;
|
||||
protected String name;
|
||||
@ -81,10 +80,11 @@ public class QueryTable implements Serializable {
|
||||
if (table == null) {
|
||||
return false;
|
||||
}
|
||||
if (StringUtil.isNotBlank(alias) && StringUtil.isNotBlank(table.alias)) {
|
||||
if (Objects.equals(alias, table.alias)) {
|
||||
if (StringUtil.isNotBlank(alias)
|
||||
&& StringUtil.isNotBlank(table.alias)
|
||||
&& (Objects.equals(alias, table.alias))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return Objects.equals(name, table.name);
|
||||
}
|
||||
@ -113,4 +113,13 @@ public class QueryTable implements Serializable {
|
||||
", alias='" + alias + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTable clone() {
|
||||
try {
|
||||
return (QueryTable) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -657,4 +657,8 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public QueryWrapper clone() {
|
||||
return (QueryWrapper) super.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -58,6 +58,11 @@ public class RawFragment extends QueryCondition {
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawFragment clone() {
|
||||
return (RawFragment) super.clone();
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
@ -49,6 +50,14 @@ public class SelectQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
return selectSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectQueryColumn clone() {
|
||||
SelectQueryColumn clone = (SelectQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryWrapper = ObjectUtil.clone(this.queryWrapper);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
return super.toConditionSql(queryTables, dialect);
|
||||
|
||||
@ -54,4 +54,12 @@ public class SelectQueryTable extends QueryTable {
|
||||
return "(" + sql + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectQueryTable clone() {
|
||||
SelectQueryTable clone = (SelectQueryTable) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryWrapper = this.queryWrapper.clone();
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
@ -80,4 +81,12 @@ public class StringFunctionQueryColumn extends QueryColumn {
|
||||
", params=" + params +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringFunctionQueryColumn clone() {
|
||||
StringFunctionQueryColumn clone = (StringFunctionQueryColumn) super.clone();
|
||||
// deep clone ...
|
||||
clone.params = CollectionUtil.newArrayList(this.params);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -48,4 +48,9 @@ public class StringQueryColumn extends QueryColumn {
|
||||
"content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringQueryColumn clone() {
|
||||
return (StringQueryColumn) super.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
@ -37,4 +37,9 @@ public class StringQueryOrderBy extends QueryOrderBy {
|
||||
public String toSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringQueryOrderBy clone() {
|
||||
return (StringQueryOrderBy) super.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.ObjectUtil;
|
||||
|
||||
public class UnionWrapper {
|
||||
public class UnionWrapper implements CloneSupport<UnionWrapper> {
|
||||
|
||||
private String key;
|
||||
private QueryWrapper queryWrapper;
|
||||
@ -59,4 +60,16 @@ public class UnionWrapper {
|
||||
public void buildSql(StringBuilder sqlBuilder, IDialect dialect) {
|
||||
sqlBuilder.append(key).append("(").append(dialect.buildSelectSql(queryWrapper)).append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnionWrapper clone() {
|
||||
try {
|
||||
UnionWrapper clone = (UnionWrapper) super.clone();
|
||||
// deep clone ...
|
||||
clone.queryWrapper = ObjectUtil.clone(this.queryWrapper);
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,12 @@
|
||||
*/
|
||||
package com.mybatisflex.core.util;
|
||||
|
||||
import com.mybatisflex.core.query.CloneSupport;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class CollectionUtil {
|
||||
@ -105,4 +109,30 @@ public class CollectionUtil {
|
||||
return results;
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static <E extends CloneSupport<E>> List<E> cloneValue(Collection<E> collection, Supplier<List<E>> collectionSupplier) {
|
||||
if (isEmpty(collection)) {
|
||||
return collectionSupplier.get();
|
||||
}
|
||||
return collection.stream()
|
||||
// 这里不能使用 CloneSupport::clone
|
||||
// java.lang.BootstrapMethodError: call site initialization exception
|
||||
.map(cloneable -> cloneable.clone())
|
||||
.collect(Collectors.toCollection(collectionSupplier));
|
||||
}
|
||||
|
||||
public static <E> ArrayList<E> newArrayList(Collection<E> collection) {
|
||||
if (isEmpty(collection)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
public static <K, V> HashMap<K, V> newHashMap(Map<K, V> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return new HashMap<>(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,12 +15,28 @@
|
||||
*/
|
||||
package com.mybatisflex.core.util;
|
||||
|
||||
import com.mybatisflex.core.query.CloneSupport;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ObjectUtil {
|
||||
|
||||
private ObjectUtil() {}
|
||||
|
||||
public static Object cloneObject(Object value) {
|
||||
if (value instanceof CloneSupport) {
|
||||
return ((CloneSupport<?>) value).clone();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static <T extends CloneSupport<T>> T clone(T value) {
|
||||
if (value != null) {
|
||||
return value.clone();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T requireNonNullElse(T t1, T t2) {
|
||||
return t1 == null ? t2 : t1;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user