mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
This commit is contained in:
parent
de3504ed5e
commit
326bd68ade
@ -12,6 +12,7 @@ import com.github.yulichang.injector.MPJSqlInjector;
|
||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.MBiPredicate;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.slf4j.Logger;
|
||||
@ -42,7 +43,6 @@ import org.springframework.core.annotation.Order;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* springboot 自动配置类
|
||||
@ -73,9 +73,10 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
ConfigProperties.subQueryAlias = this.properties.getSubQueryAlias();
|
||||
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
|
||||
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
||||
ConfigProperties.Convert.IfExists = this.properties.getIfExists();
|
||||
ConfigProperties.ifExists = Optional.ofNullable(IfExistsConsumers.getIfAvailable())
|
||||
.map(m -> (BiPredicate<Object, IfExistsSqlKeyWordEnum>) m)
|
||||
.orElse((val, key) -> this.properties.getIfExists().test(val));
|
||||
.map(m -> (MBiPredicate<Object, IfExistsSqlKeyWordEnum>) m)
|
||||
.orElse((val, key) -> ConfigProperties.Convert.IfExists.test(val));
|
||||
info("mybatis plus join properties config complete");
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.github.yulichang.autoconfigure.consumer;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import com.github.yulichang.wrapper.interfaces.MBiPredicate;
|
||||
|
||||
/**
|
||||
* 自定义IfExists策略
|
||||
@ -10,5 +9,5 @@ import java.util.function.BiPredicate;
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public interface MybatisPlusJoinIfExistsConsumer extends BiPredicate<Object, IfExistsSqlKeyWordEnum> {
|
||||
public interface MybatisPlusJoinIfExistsConsumer extends MBiPredicate<Object, IfExistsSqlKeyWordEnum> {
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ package com.github.yulichang.config;
|
||||
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import com.github.yulichang.wrapper.interfaces.MBiPredicate;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
@ -53,5 +52,13 @@ public class ConfigProperties {
|
||||
* <p>
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
public static BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = (val, key) -> IfExistsEnum.NOT_EMPTY.test(val);
|
||||
public static MBiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = (val, key) -> IfExistsEnum.NOT_EMPTY.test(val);
|
||||
|
||||
|
||||
/**
|
||||
* 暂存 不可使用 用于规避starter包中需要序列化
|
||||
*/
|
||||
public static class Convert {
|
||||
public static IfExistsEnum IfExists = IfExistsEnum.NOT_EMPTY;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package com.github.yulichang.config.enums;
|
||||
|
||||
import com.github.yulichang.toolkit.MPJStringUtils;
|
||||
import com.github.yulichang.wrapper.interfaces.MPredicate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 条件判断策略
|
||||
@ -11,7 +12,7 @@ import java.util.function.Predicate;
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfExistsEnum implements Predicate<Object> {
|
||||
public enum IfExistsEnum implements MPredicate<Object>, Serializable {
|
||||
|
||||
/**
|
||||
* 非null
|
||||
@ -26,9 +27,9 @@ public enum IfExistsEnum implements Predicate<Object> {
|
||||
*/
|
||||
NOT_BLANK(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || MPJStringUtils.isNotBlank((CharSequence) v)).test(val));
|
||||
|
||||
private final Predicate<Object> predicate;
|
||||
private final MPredicate<Object> predicate;
|
||||
|
||||
IfExistsEnum(Predicate<Object> predicate) {
|
||||
IfExistsEnum(MPredicate<Object> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.github.yulichang.config.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 逻辑删除位置
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.4
|
||||
*/
|
||||
public enum LogicDelTypeEnum {
|
||||
public enum LogicDelTypeEnum implements Serializable {
|
||||
WHERE, ON
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
|
||||
private ResultMapping selectToResult(Class<?> entity, Select select, Class<?> type, ResultMapping.Builder builder) {
|
||||
if (select.hasTypeHandle() && select.getTableFieldInfo().getPropertyType().isAssignableFrom(type)) {
|
||||
if (select.hasTypeHandle() && select.getPropertyType().isAssignableFrom(type)) {
|
||||
builder.typeHandler(select.getTypeHandle());
|
||||
}
|
||||
if (select.isPk() && entity == select.getClazz()) {
|
||||
|
@ -264,7 +264,7 @@ public class MybatisLabel<E, T> implements Label<T> {
|
||||
result.setIndex(mybatisLabel.index);
|
||||
result.setProperty(i.getColumProperty());
|
||||
result.setJavaType(i.getColumnType());
|
||||
result.setJdbcType(Objects.isNull(i.getTableFieldInfo()) ? null : i.getTableFieldInfo().getJdbcType());
|
||||
result.setJdbcType(i.getJdbcType());
|
||||
result.setSelectNormal(i);
|
||||
return result;
|
||||
}).collect(Collectors.toList()));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.kt.resultmap;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
@ -14,7 +13,6 @@ import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* result 标签
|
||||
@ -60,7 +58,7 @@ public class Result implements IResult {
|
||||
result.selectNormal = selectCache;
|
||||
result.property = selectCache.getColumProperty();
|
||||
result.javaType = selectCache.getColumnType();
|
||||
result.jdbcType = Optional.ofNullable(selectCache.getTableFieldInfo()).map(TableFieldInfo::getJdbcType).orElse(null);
|
||||
result.jdbcType = selectCache.getJdbcType();
|
||||
}
|
||||
|
||||
public Builder<T> property(KProperty<?> property) {
|
||||
@ -80,7 +78,7 @@ public class Result implements IResult {
|
||||
result.javaType = normal.getColumnType();
|
||||
}
|
||||
if (Objects.isNull(result.jdbcType)) {
|
||||
result.jdbcType = Objects.isNull(normal.getTableFieldInfo()) ? null : normal.getTableFieldInfo().getJdbcType();
|
||||
result.jdbcType = normal.getJdbcType();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY;
|
||||
@ -66,7 +65,7 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
/**
|
||||
* 主表 表名处理方法
|
||||
*/
|
||||
protected Function<String, String> tableFunc;
|
||||
protected SFunction<String, String> tableFunc;
|
||||
|
||||
/**
|
||||
* 逻辑删除位置
|
||||
@ -170,7 +169,7 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
*
|
||||
* @return 自定义表别名
|
||||
*/
|
||||
public Children setTableName(Function<String, String> tableFunc) {
|
||||
public Children setTableName(SFunction<String, String> tableFunc) {
|
||||
if (isMain) {
|
||||
if (tableFunc != null) {
|
||||
this.dynamicTableName = true;
|
||||
|
@ -122,7 +122,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
* IfExists 策略
|
||||
*/
|
||||
@Getter
|
||||
protected BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||
protected MBiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
@ -175,7 +175,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfExists(BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||
public Children setIfExists(MBiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||
this.ifExists = IfExists;
|
||||
return typedThis;
|
||||
}
|
||||
@ -329,7 +329,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
() -> formatSqlMaybeWithParam(applySql, null, values)));
|
||||
}
|
||||
|
||||
public Children applyFunc(String applySql, Function<FuncConsumer, SFunction<?, ?>[]> consumerFunction, Object... values) {
|
||||
public Children applyFunc(String applySql, SFunction<FuncConsumer, SFunction<?, ?>[]> consumerFunction, Object... values) {
|
||||
return applyFunc(true, applySql, consumerFunction, values);
|
||||
}
|
||||
|
||||
|
@ -10,17 +10,13 @@ import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import com.github.yulichang.wrapper.interfaces.Query;
|
||||
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
||||
import com.github.yulichang.wrapper.interfaces.*;
|
||||
import com.github.yulichang.wrapper.resultmap.Label;
|
||||
import com.github.yulichang.wrapper.segments.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -126,7 +122,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
|
||||
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||
MBiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||
super.setEntity(entity);
|
||||
super.setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.github.yulichang.wrapper.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* if absent 枚举
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfExistsSqlKeyWordEnum {
|
||||
public enum IfExistsSqlKeyWordEnum implements Serializable {
|
||||
EQ,
|
||||
NE,
|
||||
GT,
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* on function
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.14
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MBiPredicate<T, U> extends BiPredicate<T, U>, Serializable {
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* on function
|
||||
*
|
||||
@ -7,7 +9,7 @@ package com.github.yulichang.wrapper.interfaces;
|
||||
* @since 1.1.8
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MFunction<T> {
|
||||
public interface MFunction<T> extends Serializable {
|
||||
|
||||
T apply(T wrapper);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* on function
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.14
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MPredicate<T> extends Predicate<T>, Serializable {
|
||||
|
||||
}
|
@ -362,7 +362,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
||||
* @param right 扩展 用于关联表的 select 和 where
|
||||
*/
|
||||
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||
return join(keyWord, clazz, on -> on.eq(left, rightAlias,right));
|
||||
return join(keyWord, clazz, on -> on.eq(left, rightAlias, right));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,9 @@ package com.github.yulichang.wrapper.resultmap;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
public interface IResult {
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface IResult extends Serializable {
|
||||
|
||||
boolean isId();
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.yulichang.wrapper.resultmap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -8,7 +9,7 @@ import java.util.List;
|
||||
* @author yulichang
|
||||
* @since 2023/3/17 11:35
|
||||
*/
|
||||
public interface Label<T> {
|
||||
public interface Label<T> extends Serializable {
|
||||
|
||||
String getProperty();
|
||||
|
||||
|
@ -268,7 +268,7 @@ public class MybatisLabel<E, T> implements Label<T> {
|
||||
result.setIndex(mybatisLabel.index);
|
||||
result.setProperty(i.getColumProperty());
|
||||
result.setJavaType(i.getColumnType());
|
||||
result.setJdbcType(Objects.isNull(i.getTableFieldInfo()) ? null : i.getTableFieldInfo().getJdbcType());
|
||||
result.setJdbcType(i.getJdbcType());
|
||||
result.setSelectNormal(i);
|
||||
return result;
|
||||
}).collect(Collectors.toList()));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.wrapper.resultmap;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
@ -13,7 +12,6 @@ import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* result 标签
|
||||
@ -59,7 +57,7 @@ public class Result implements IResult {
|
||||
result.selectNormal = selectCache;
|
||||
result.property = selectCache.getColumProperty();
|
||||
result.javaType = selectCache.getColumnType();
|
||||
result.jdbcType = Optional.ofNullable(selectCache.getTableFieldInfo()).map(TableFieldInfo::getJdbcType).orElse(null);
|
||||
result.jdbcType = selectCache.getJdbcType();
|
||||
}
|
||||
|
||||
public Builder<T> property(SFunction<T, ?> property) {
|
||||
@ -80,7 +78,7 @@ public class Result implements IResult {
|
||||
result.javaType = normal.getColumnType();
|
||||
}
|
||||
if (Objects.isNull(result.jdbcType)) {
|
||||
result.jdbcType = Objects.isNull(normal.getTableFieldInfo()) ? null : normal.getTableFieldInfo().getJdbcType();
|
||||
result.jdbcType = normal.getJdbcType();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -40,7 +40,9 @@ public interface Select extends Serializable {
|
||||
|
||||
String getAlias();
|
||||
|
||||
TableFieldInfo getTableFieldInfo();
|
||||
Class<?> getPropertyType();
|
||||
|
||||
JdbcType getJdbcType();
|
||||
|
||||
boolean isFunc();
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
/**
|
||||
@ -79,8 +79,13 @@ public class SelectAlias implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
return cache.getTableFieldInfo();
|
||||
public Class<?> getPropertyType() {
|
||||
return cache.getPropertyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return cache.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,11 +8,15 @@ import com.github.yulichang.toolkit.MPJStringUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import org.apache.ibatis.type.UnknownTypeHandler;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
@ -21,7 +25,7 @@ import java.util.Objects;
|
||||
* @since 1.3.10
|
||||
*/
|
||||
@Getter
|
||||
public class SelectCache {
|
||||
public class SelectCache implements Serializable {
|
||||
|
||||
/**
|
||||
* 实体类
|
||||
@ -55,20 +59,17 @@ public class SelectCache {
|
||||
*/
|
||||
private final String columProperty;
|
||||
|
||||
/**
|
||||
* mp 字段信息
|
||||
*/
|
||||
private final TableFieldInfo tableFieldInfo;
|
||||
|
||||
/**
|
||||
* 使用使用 hasTypeHandle
|
||||
*/
|
||||
private final boolean hasTypeHandle;
|
||||
|
||||
/**
|
||||
* hasTypeHandle 类型
|
||||
* tableFieldInfo中信息
|
||||
*/
|
||||
private final TypeHandler<?> typeHandler;
|
||||
private final Class<?> propertyType;
|
||||
private final JdbcType jdbcType;
|
||||
private final Class<? extends TypeHandler<?>> typeHandlerClass;
|
||||
|
||||
/**
|
||||
* 是否查询
|
||||
@ -82,29 +83,48 @@ public class SelectCache {
|
||||
this.columnType = columnType;
|
||||
this.columProperty = columProperty;
|
||||
this.tagColumn = MPJStringUtils.getTargetColumn(column);
|
||||
this.tableFieldInfo = tableFieldInfo;
|
||||
this.isSelect = isSelect;
|
||||
if (Objects.isNull(tableFieldInfo)) {
|
||||
this.hasTypeHandle = false;
|
||||
this.typeHandler = null;
|
||||
this.propertyType = null;
|
||||
this.jdbcType = null;
|
||||
this.typeHandlerClass = null;
|
||||
} else {
|
||||
this.hasTypeHandle = this.tableFieldInfo.getTypeHandler() != null && tableFieldInfo.getTypeHandler() != UnknownTypeHandler.class;
|
||||
if (this.hasTypeHandle) {
|
||||
TableInfo info = TableHelper.getAssert(clazz);
|
||||
this.typeHandler = getTypeHandler(AdapterHelper.getAdapter().mpjGetConfiguration(info), tableFieldInfo);
|
||||
} else {
|
||||
this.typeHandler = null;
|
||||
}
|
||||
this.propertyType = tableFieldInfo.getPropertyType();
|
||||
this.jdbcType = tableFieldInfo.getJdbcType();
|
||||
this.typeHandlerClass = tableFieldInfo.getTypeHandler();
|
||||
this.hasTypeHandle = tableFieldInfo.getTypeHandler() != null && tableFieldInfo.getTypeHandler() != UnknownTypeHandler.class;
|
||||
}
|
||||
}
|
||||
|
||||
public TypeHandler<?> getTypeHandler() {
|
||||
if (this.hasTypeHandle) {
|
||||
return Cache.getTypeHandlerCache(this.clazz, this.typeHandlerClass, this.propertyType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private TypeHandler<?> getTypeHandler(Configuration configuration, TableFieldInfo info) {
|
||||
private static TypeHandler<?> getTypeHandler(Configuration configuration, Class<?> propertyType, Class<? extends TypeHandler<?>> typeHandlerClass) {
|
||||
TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
|
||||
TypeHandler<?> typeHandler = registry.getMappingTypeHandler(info.getTypeHandler());
|
||||
TypeHandler<?> typeHandler = registry.getMappingTypeHandler(typeHandlerClass);
|
||||
if (typeHandler == null) {
|
||||
typeHandler = registry.getInstance(info.getPropertyType(), info.getTypeHandler());
|
||||
typeHandler = registry.getInstance(propertyType, typeHandlerClass);
|
||||
}
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
public static class Cache {
|
||||
private static final Map<Class<?>, Map<Class<?>, TypeHandler<?>>> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
public static TypeHandler<?> getTypeHandlerCache(Class<?> table, Class<? extends TypeHandler<?>> typeHandler, Class<?> propertyType) {
|
||||
if (table == null || typeHandler == null) {
|
||||
return null;
|
||||
}
|
||||
Map<Class<?>, TypeHandler<?>> map = CACHE.computeIfAbsent(table, k -> new ConcurrentHashMap<>());
|
||||
return map.computeIfAbsent(typeHandler, k -> {
|
||||
TableInfo info = TableHelper.getAssert(table);
|
||||
return getTypeHandler(AdapterHelper.getAdapter().mpjGetConfiguration(info), propertyType, typeHandler);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -143,8 +143,13 @@ public class SelectFunc implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
return Objects.isNull(cache) ? null : cache.getTableFieldInfo();
|
||||
public Class<?> getPropertyType() {
|
||||
return Objects.isNull(cache) ? null : cache.getPropertyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return Objects.isNull(cache) ? null : cache.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
/**
|
||||
@ -100,8 +100,13 @@ public class SelectLabel implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
return cache.getTableFieldInfo();
|
||||
public Class<?> getPropertyType() {
|
||||
return cache.getPropertyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return cache.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
/**
|
||||
@ -81,8 +81,13 @@ public class SelectNormal implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
return cache.getTableFieldInfo();
|
||||
public Class<?> getPropertyType() {
|
||||
return cache.getPropertyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return cache.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
/**
|
||||
@ -86,7 +86,12 @@ public class SelectString implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
public Class<?> getPropertyType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -24,7 +24,7 @@ public class SelectSub implements Select {
|
||||
|
||||
private final String tagProperty;
|
||||
|
||||
public SelectSub(Supplier<String> column, boolean hasTableAlias, String tableAlias,String tagProperty) {
|
||||
public SelectSub(Supplier<String> column, boolean hasTableAlias, String tableAlias, String tagProperty) {
|
||||
this.column = column;
|
||||
this.hasTableAlias = hasTableAlias;
|
||||
this.tableAlias = tableAlias;
|
||||
@ -97,7 +97,12 @@ public class SelectSub implements Select {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo getTableFieldInfo() {
|
||||
public Class<?> getPropertyType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcType getJdbcType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import com.github.yulichang.injector.MPJSqlInjector;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.MBiPredicate;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.solon.MybatisAdapter;
|
||||
import org.apache.ibatis.solon.integration.MybatisAdapterManager;
|
||||
@ -22,7 +23,6 @@ import org.noear.solon.core.util.GenericUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -62,7 +62,7 @@ public class XPluginImpl implements Plugin {
|
||||
ConfigProperties.mappingMaxCount = prop.get("mappingMaxCount", Integer::parseInt);
|
||||
ConfigProperties.ifExists = prop.get("ifExists", val ->
|
||||
Arrays.stream(IfExistsEnum.values()).filter(e -> e.name().equalsIgnoreCase(val)).findFirst()
|
||||
.map(m -> (BiPredicate<Object, IfExistsSqlKeyWordEnum>) (o, enums) -> m.test(o))
|
||||
.map(m -> (MBiPredicate<Object, IfExistsSqlKeyWordEnum>) (o, enums) -> m.test(o))
|
||||
.orElseThrow(() -> ExceptionUtils.mpe("mybatis-plus-join.ifExists 配置错误")));
|
||||
// 后续操作
|
||||
context.onEvent(AppLoadEndEvent.class, e -> {
|
||||
|
@ -64,14 +64,14 @@ class LambdaWrapperTest {
|
||||
ThreadLocalUtils.set("SELECT t.id, t.user_id, t.tenant_id FROM user_tenant t WHERE t.tenant_id = 1");
|
||||
MPJLambdaWrapper<UserTenantDO> lambda = JoinWrappers.lambda(UserTenantDO.class)
|
||||
.selectAsClass(UserTenantDO.class, UserTenantDTO.class);
|
||||
List<UserTenantDO> list = userTenantMapper.selectJoinList(UserTenantDO.class, lambda);
|
||||
List<UserTenantDO> list = userTenantMapper.selectJoinList(UserTenantDO.class, lambda.clone());
|
||||
assert list.size() == 5 && list.get(0).getIdea() != null;
|
||||
|
||||
|
||||
ThreadLocalUtils.set("SELECT t.tenant_id, t.user_id, t.id FROM user_tenant t WHERE t.tenant_id = 1");
|
||||
MPJLambdaWrapper<UserTenantDO> lambda1 = JoinWrappers.lambda(UserTenantDO.class)
|
||||
.selectAsClass(UserTenantDO.class, UserTenantDescDTO.class);
|
||||
List<UserTenantDO> list1 = userTenantMapper.selectJoinList(UserTenantDO.class, lambda1);
|
||||
List<UserTenantDO> list1 = userTenantMapper.selectJoinList(UserTenantDO.class, lambda1.clone());
|
||||
assert list1.size() == 5 && list1.get(0).getIdea() != null;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ class LambdaWrapperTest {
|
||||
void testSimple() {
|
||||
MPJLambdaWrapper<UserTenantDO> lambda = JoinWrappers.lambda(UserTenantDO.class);
|
||||
lambda.selectAs(UserTenantDO::getIdea, UserTenantDO::getIdea);
|
||||
List<UserTenantDO> list = userTenantMapper.selectList(lambda);
|
||||
List<UserTenantDO> list = userTenantMapper.selectList(lambda.clone());
|
||||
|
||||
assert list.size() == 5 && list.get(0).getIdea() != null;
|
||||
}
|
||||
@ -126,7 +126,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
||||
.le(UserDO::getId, 10000)
|
||||
.orderByDesc(UserDO::getId);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper.clone());
|
||||
|
||||
assert wrapper.checkJoinTable(AddressDO.class);
|
||||
assert wrapper.checkJoinTable(AreaDO.class);
|
||||
@ -167,7 +167,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.le(UserDO::getId, 10000)
|
||||
.orderByDesc(UserDO::getId);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper.clone());
|
||||
|
||||
assert list.get(0).getAddressIds() != null;
|
||||
list.forEach(System.out::println);
|
||||
@ -214,7 +214,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
||||
.orderByDesc(UserDO::getId);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper.clone());
|
||||
|
||||
assert list.get(0).getAddressList().get(0).getId() != null;
|
||||
list.forEach(System.out::println);
|
||||
@ -237,7 +237,7 @@ class LambdaWrapperTest {
|
||||
.select(UserDO::getId)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId);
|
||||
List<Integer> list = userMapper.selectJoinList(Integer.class, wrapper);
|
||||
List<Integer> list = userMapper.selectJoinList(Integer.class, wrapper.clone());
|
||||
|
||||
assert list.get(0) != null;
|
||||
System.out.println(list);
|
||||
@ -255,7 +255,7 @@ class LambdaWrapperTest {
|
||||
.select(UserDO::getCreateTime)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId);
|
||||
List<Timestamp> list1 = userMapper.selectJoinList(Timestamp.class, wrapper1);
|
||||
List<Timestamp> list1 = userMapper.selectJoinList(Timestamp.class, wrapper1.clone());
|
||||
|
||||
assert list1.get(0) != null;
|
||||
System.out.println(list);
|
||||
@ -281,9 +281,9 @@ class LambdaWrapperTest {
|
||||
" AND t.del = false\n" +
|
||||
" AND (t.id <= ?)\n" +
|
||||
"ORDER BY t.id ASC, t.`name` ASC");
|
||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>(new UserDO() {{
|
||||
setId(1);
|
||||
}})
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setId(1);
|
||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<>(userDO)
|
||||
.selectAll(UserDO.class)
|
||||
// .setEntity(new UserDO() {{
|
||||
// setId(1);
|
||||
@ -291,7 +291,7 @@ class LambdaWrapperTest {
|
||||
.le(UserDO::getId, 100)
|
||||
.orderByAsc(UserDO::getId, UserDO::getName);
|
||||
|
||||
List<UserDO> list = userMapper.selectList(wrapper);
|
||||
List<UserDO> list = userMapper.selectList(wrapper.clone());
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@ -322,7 +322,7 @@ class LambdaWrapperTest {
|
||||
.ge(UserDO::getId, 0))
|
||||
.leftJoin(UserDO.class, "uc", UserDO::getId, UserDto::getUpdateBy, ext -> ext
|
||||
.selectAs(UserDO::getName, UserDto::getUpdateName));
|
||||
List<UserDto> userDtos = userDTOMapper.selectJoinList(UserDto.class, wrapper);
|
||||
List<UserDto> userDtos = userDTOMapper.selectJoinList(UserDto.class, wrapper.clone());
|
||||
assert StringUtils.isNotBlank(userDtos.get(0).getUserName());
|
||||
assert StringUtils.isNotBlank(userDtos.get(0).getCreateName());
|
||||
assert StringUtils.isNotBlank(userDtos.get(0).getUpdateName());
|
||||
@ -360,7 +360,7 @@ class LambdaWrapperTest {
|
||||
.select(UserDO::getImg))
|
||||
.leftJoin(UserDO.class, "uc", UserDO::getId, UserDO::getUpdateBy)
|
||||
.eq(UserDO::getId, UserDO::getId);
|
||||
userMapper.selectJoinList(UserDO.class, w);
|
||||
userMapper.selectJoinList(UserDO.class, w.clone());
|
||||
System.out.println(1);
|
||||
}
|
||||
|
||||
@ -404,7 +404,7 @@ class LambdaWrapperTest {
|
||||
.selectCollection(UserDO.class, UserDO::getChildren)
|
||||
.leftJoin(UserDO.class, UserDO::getPid, UserDO::getId)
|
||||
.gt(UserDO::getId, 0);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper.clone());
|
||||
System.out.println(list);
|
||||
|
||||
ThreadLocalUtils.set("SELECT t.id,\n" +
|
||||
@ -438,7 +438,7 @@ class LambdaWrapperTest {
|
||||
.eq(UserDO::getId, UserDO::getUpdateBy);
|
||||
})
|
||||
.eq(UserDO::getId, UserDO::getId);
|
||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, w);
|
||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, w.clone());
|
||||
assert dos.get(0).getCreateName() != null && dos.get(0).getUpdateName() != null;
|
||||
|
||||
|
||||
@ -494,7 +494,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(UserDO.class, UserDO::getPid, UserDO::getId)
|
||||
.le(UserDO::getId, 5))
|
||||
.le(UserDO::getId, 4);
|
||||
List<UserDO> list1 = userMapper.selectJoinList(UserDO.class, wrapper1);
|
||||
List<UserDO> list1 = userMapper.selectJoinList(UserDO.class, wrapper1.clone());
|
||||
System.out.println(list1);
|
||||
}
|
||||
|
||||
@ -503,20 +503,20 @@ class LambdaWrapperTest {
|
||||
*/
|
||||
@Test
|
||||
void testLogicDel() {
|
||||
List<UserDTO> l1 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<>());
|
||||
List<UserDTO> l1 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>().clone());
|
||||
assert l1.size() == 14;
|
||||
|
||||
List<UserDTO> l2 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>()
|
||||
.selectAll(UserDO.class)
|
||||
.select(AddressDO::getAddress)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).clone());
|
||||
assert l2.size() == 10;
|
||||
|
||||
List<UserDTO> l3 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>()
|
||||
.disableSubLogicDel()
|
||||
.selectAll(UserDO.class)
|
||||
.selectCollection(AddressDO.class, UserDTO::getAddressList)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).clone());
|
||||
assert l3.size() == 14 && l3.get(0).getAddressList().size() == 9;
|
||||
|
||||
List<UserDTO> l4 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>()
|
||||
@ -525,7 +525,7 @@ class LambdaWrapperTest {
|
||||
.selectCollection(AddressDO.class, UserDTO::getAddressList)
|
||||
.leftJoin(AddressDO.class, on -> on
|
||||
.eq(AddressDO::getUserId, UserDO::getId)
|
||||
.eq(AddressDO::getDel, false)));
|
||||
.eq(AddressDO::getDel, false)).clone());
|
||||
assert l4.size() == 14 && l4.get(0).getAddressList().size() == 5;
|
||||
}
|
||||
|
||||
@ -540,7 +540,7 @@ class LambdaWrapperTest {
|
||||
.selectAll(UserDO.class)
|
||||
.selectCollection(UserDO.class, UserDO::getChildren)
|
||||
.leftJoin(UserDO.class, UserDO::getPid, UserDO::getId);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper.clone());
|
||||
assert list.get(0).getName() != null && list.get(0).getChildren().get(0).getName() != null;
|
||||
assert list.get(0).getImg() != null && list.get(0).getChildren().get(0).getImg() != null;
|
||||
System.out.println(list);
|
||||
@ -557,7 +557,7 @@ class LambdaWrapperTest {
|
||||
.select(UserDO::getId)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.orderByDesc(UserDO::getId);
|
||||
List<Object> list = userMapper.selectObjs(wrapper);
|
||||
List<Object> list = userMapper.selectObjs(wrapper.clone());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -590,7 +590,7 @@ class LambdaWrapperTest {
|
||||
.selectAll(AddressDO.class, "aa")
|
||||
// .selectCollection(UserDO.class, UserDO::getChildren)
|
||||
.leftJoin(AddressDO.class, "aa", AddressDO::getUserId, UserDO::getId);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper.clone());
|
||||
|
||||
System.out.println(list);
|
||||
}
|
||||
@ -604,7 +604,7 @@ class LambdaWrapperTest {
|
||||
.selectCollection("t2", AddressDO.class, UserDO::getAddressList2)
|
||||
.leftJoin(AddressDO.class, AddressDO::getId, UserDO::getAddressId)
|
||||
.leftJoin(AddressDO.class, AddressDO::getId, UserDO::getAddressId2);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
List<UserDO> list = userMapper.selectJoinList(UserDO.class, wrapper.clone());
|
||||
|
||||
assert list.get(0).getAddressList().get(0).getAddress() != null;
|
||||
assert list.get(0).getAddressList2().get(0).getAddress() != null;
|
||||
@ -625,7 +625,7 @@ class LambdaWrapperTest {
|
||||
.select(AddressDO::getAddress)
|
||||
.select(AreaDO::getProvince)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId));
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId).clone());
|
||||
iPage.getRecords().forEach(System.out::println);
|
||||
}
|
||||
|
||||
@ -636,24 +636,24 @@ class LambdaWrapperTest {
|
||||
@Test
|
||||
void test3() {
|
||||
ThreadLocalUtils.set("SELECT t.id,\n" +
|
||||
" t.pid,\n" +
|
||||
" t.`name`,\n" +
|
||||
" t.`json`,\n" +
|
||||
" t.sex,\n" +
|
||||
" t.head_img,\n" +
|
||||
" t.create_time,\n" +
|
||||
" t.address_id,\n" +
|
||||
" t.address_id2,\n" +
|
||||
" t.del,\n" +
|
||||
" t.create_by,\n" +
|
||||
" t.update_by,\n" +
|
||||
" t1.address\n" +
|
||||
"FROM `user` t\n" +
|
||||
" LEFT JOIN address t1 ON (t.id = t1.user_id AND t.id = t1.user_id)\n" +
|
||||
"WHERE t.del = false\n" +
|
||||
" AND t1.del = false\n" +
|
||||
" AND (t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?)\n" +
|
||||
"LIMIT ?",
|
||||
" t.pid,\n" +
|
||||
" t.`name`,\n" +
|
||||
" t.`json`,\n" +
|
||||
" t.sex,\n" +
|
||||
" t.head_img,\n" +
|
||||
" t.create_time,\n" +
|
||||
" t.address_id,\n" +
|
||||
" t.address_id2,\n" +
|
||||
" t.del,\n" +
|
||||
" t.create_by,\n" +
|
||||
" t.update_by,\n" +
|
||||
" t1.address\n" +
|
||||
"FROM `user` t\n" +
|
||||
" LEFT JOIN address t1 ON (t.id = t1.user_id AND t.id = t1.user_id)\n" +
|
||||
"WHERE t.del = false\n" +
|
||||
" AND t1.del = false\n" +
|
||||
" AND (t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?)\n" +
|
||||
"LIMIT ?",
|
||||
"SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, " +
|
||||
"t.create_time, t.address_id, t.address_id2, t.del, t.create_by, t.update_by, t1.address FROM `user` t " +
|
||||
"LEFT JOIN address t1 ON (t.id = t1.user_id AND t.id = t1.user_id) WHERE t.del = false AND t1.del = false AND " +
|
||||
@ -669,7 +669,7 @@ class LambdaWrapperTest {
|
||||
.and(i -> i.eq(UserDO::getImg, "er")
|
||||
.or()
|
||||
.eq(AddressDO::getUserId, 1))
|
||||
.eq(UserDO::getId, 1));
|
||||
.eq(UserDO::getId, 1).clone());
|
||||
page.getRecords().forEach(System.out::println);
|
||||
}
|
||||
|
||||
@ -681,7 +681,7 @@ class LambdaWrapperTest {
|
||||
UserDTO one = userMapper.selectJoinOne(UserDTO.class, JoinWrappers.<UserDO>lambda()
|
||||
.selectSum(UserDO::getId)
|
||||
.selectMax(UserDO::getId, UserDTO::getHeadImg)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).clone());
|
||||
System.out.println(one);
|
||||
}
|
||||
|
||||
@ -707,7 +707,7 @@ class LambdaWrapperTest {
|
||||
List<Map<String, Object>> list = userMapper.selectJoinMaps(JoinWrappers.<UserDO>lambda()
|
||||
.selectAll(UserDO.class)
|
||||
.select(AddressDO::getAddress)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).clone());
|
||||
assert list.get(0).get("ADDRESS") != null || list.get(0).get("address") != null;
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
@ -719,7 +719,7 @@ class LambdaWrapperTest {
|
||||
void testMP() {
|
||||
List<UserDO> dos = userMapper.selectList(new LambdaQueryWrapper<UserDO>()
|
||||
.gt(UserDO::getId, 3)
|
||||
.lt(UserDO::getId, 8));
|
||||
.lt(UserDO::getId, 8).clone());
|
||||
assert dos.size() == 4;
|
||||
|
||||
ThreadLocalUtils.set(
|
||||
@ -728,7 +728,7 @@ class LambdaWrapperTest {
|
||||
"SELECT * FROM `user` t WHERE t.del=false AND (t.id > ? AND t.id < ?) ");
|
||||
List<UserDO> dos1 = userMapper.selectList(new MPJLambdaWrapper<UserDO>()
|
||||
.gt(UserDO::getId, 3)
|
||||
.lt(UserDO::getId, 8));
|
||||
.lt(UserDO::getId, 8).clone());
|
||||
assert dos1.size() == 4;
|
||||
}
|
||||
|
||||
@ -758,13 +758,13 @@ class LambdaWrapperTest {
|
||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId);
|
||||
Object integer = userMapper.selectCount(wrapper);
|
||||
Object integer = userMapper.selectCount(wrapper.clone());
|
||||
|
||||
ThreadLocalUtils.set("SELECT COUNT( * ) FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) WHERE t.del=false AND t1.del=false AND t2.del=false");
|
||||
MPJLambdaWrapper<UserDO> wrapper1 = new MPJLambdaWrapper<UserDO>()
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId);
|
||||
Long aLong1 = userMapper.selectJoinCount(wrapper1);
|
||||
Long aLong1 = userMapper.selectJoinCount(wrapper1.clone());
|
||||
}
|
||||
|
||||
|
||||
@ -786,7 +786,7 @@ class LambdaWrapperTest {
|
||||
.orderByDesc(UserDO::getId)
|
||||
.setTableName(name -> String.format("(select * from %s)", name));
|
||||
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper.clone());
|
||||
}
|
||||
|
||||
|
||||
@ -835,7 +835,7 @@ class LambdaWrapperTest {
|
||||
.le(UserDO::getId, 10000)
|
||||
.orderByDesc(UserDO::getId);
|
||||
System.out.println(wrapper.getFrom());
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper.clone());
|
||||
|
||||
assert list.get(0).getAddressList() != null && list.get(0).getAddressList().get(0).getId() != null;
|
||||
list.forEach(System.out::println);
|
||||
@ -909,7 +909,7 @@ class LambdaWrapperTest {
|
||||
.le(UserDO::getId, 10000)
|
||||
.orderByDesc(UserDO::getId);
|
||||
|
||||
List<UserDTO> list = wrapper.list(UserDTO.class);
|
||||
List<UserDTO> list = wrapper.clone().list(UserDTO.class);
|
||||
|
||||
System.out.println(list);
|
||||
assert list.get(0).getAddressList() != null && list.get(0).getAddressList().get(0).getId() != null;
|
||||
@ -924,7 +924,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(UserDO.class, UserDO::getAddressId, AddressDO::getId)
|
||||
.leftJoin(UserDO.class, UserDO::getPid, UserDO::getId);
|
||||
|
||||
List<AddressDO> addressDOS = wrapper.list();
|
||||
List<AddressDO> addressDOS = wrapper.clone().list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -938,7 +938,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.eq(AddressDO::getId, AddressDO::getId);
|
||||
|
||||
List<UserDO> addressDOS = wrapper.list();
|
||||
List<UserDO> addressDOS = wrapper.clone().list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -952,7 +952,7 @@ class LambdaWrapperTest {
|
||||
.leftJoin(AddressDO.class, "aaa", AddressDO::getUserId, UserDO::getId, ext -> ext
|
||||
.eq(AddressDO::getId, AddressDO::getId))
|
||||
.eq(AddressDO::getId, AddressDO::getId);
|
||||
List<UserDO> addressDOS = wrapper.list();
|
||||
List<UserDO> addressDOS = wrapper.clone().list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -969,7 +969,7 @@ class LambdaWrapperTest {
|
||||
"SELECT id,user_id,name FROM order_t t");
|
||||
}
|
||||
MPJLambdaWrapper<OrderDO> wrapper = JoinWrappers.lambda(OrderDO.class);
|
||||
List<OrderDO> list = wrapper.list();
|
||||
List<OrderDO> list = wrapper.clone().list();
|
||||
|
||||
if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3") >= 0) {
|
||||
ThreadLocalUtils.set("SELECT t.id,t.user_id,t.name,t1.`name` AS userName FROM order_t t LEFT JOIN `user` t1 ON (t1.id = t.user_id) WHERE t1.del=false ORDER BY t.name DESC",
|
||||
@ -982,7 +982,7 @@ class LambdaWrapperTest {
|
||||
.selectAll(OrderDO.class)
|
||||
.selectAs(UserDO::getName, OrderDO::getUserName)
|
||||
.leftJoin(UserDO.class, UserDO::getId, OrderDO::getUserId);
|
||||
List<OrderDO> l = w.list();
|
||||
List<OrderDO> l = w.clone().list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -996,6 +996,6 @@ class LambdaWrapperTest {
|
||||
.le(UserDO::getId, 100)
|
||||
.checkSqlInjection()
|
||||
.orderByDesc("t.id");
|
||||
wrapper.list();
|
||||
wrapper.clone().list();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.github.yulichang.test.join.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.github.yulichang.wrapper.segments.Fun;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class CloneTest {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void cloneTest() {
|
||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(UserDO::getId, AddressDO::getUserId), "12")
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(
|
||||
Fun.f("t", UserDO::getId),
|
||||
Fun.f("t1", AddressDO::getUserId)), "12");
|
||||
|
||||
wrapper.list().forEach(System.out::println);
|
||||
|
||||
MPJLambdaWrapper<UserDO> clone = wrapper.clone();
|
||||
|
||||
clone.list().forEach(System.out::println);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user