mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
feat: join support wrapper
This commit is contained in:
parent
047faf4891
commit
7e4b778f79
@ -14,6 +14,7 @@ import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
|||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.*;
|
||||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
||||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||||
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
||||||
import com.github.yulichang.wrapper.segments.PageInfo;
|
import com.github.yulichang.wrapper.segments.PageInfo;
|
||||||
@ -177,6 +178,12 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Children setAlias(String alias) {
|
||||||
|
this.alias = alias;
|
||||||
|
tableList.setAlias(alias);
|
||||||
|
return typedThis;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主表分页
|
* 根据主表分页
|
||||||
*/
|
*/
|
||||||
@ -426,11 +433,29 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
|||||||
* 内部调用, 不建议使用
|
* 内部调用, 不建议使用
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <R> Children join(String keyWord, Class<R> clazz, String tableAlias, BiConsumer<JoinAbstractLambdaWrapper<T, ?>, Children> consumer) {
|
public <R> Children join(String keyWord, Class<R> clazz, MConsumer<MPJLambdaWrapper<R>> table, String tableAlias, BiConsumer<JoinAbstractLambdaWrapper<T, ?>, Children> consumer) {
|
||||||
|
String tabName;
|
||||||
|
if (table != null) {
|
||||||
|
MPJLambdaWrapper<R> tableWrapper = new MPJLambdaWrapper<R>(null, clazz, SharedString.emptyString(),
|
||||||
|
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||||
|
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
|
new TableList(), null, null, null, null, ifExists) {
|
||||||
|
};
|
||||||
|
tableWrapper.tableList.setAlias(ConfigProperties.tableAlias);
|
||||||
|
tableWrapper.tableList.setRootClass(clazz);
|
||||||
|
|
||||||
|
table.accept(tableWrapper);
|
||||||
|
if (MPJStringUtils.isBlank(tableWrapper.getSqlSelect())) {
|
||||||
|
tableWrapper.selectAll();
|
||||||
|
}
|
||||||
|
tabName = "(" + WrapperUtils.buildUnionSqlByWrapper(clazz, tableWrapper) + ")";
|
||||||
|
} else {
|
||||||
|
TableInfo info = TableHelper.getAssert(clazz);
|
||||||
|
tabName = info.getTableName();
|
||||||
|
}
|
||||||
Integer oldIndex = this.getIndex();
|
Integer oldIndex = this.getIndex();
|
||||||
int newIndex = tableIndex;
|
int newIndex = tableIndex;
|
||||||
TableInfo info = TableHelper.getAssert(clazz);
|
Children instance = instance(newIndex, keyWord, clazz, tabName);
|
||||||
Children instance = instance(newIndex, keyWord, clazz, info.getTableName());
|
|
||||||
instance.isOn = true;
|
instance.isOn = true;
|
||||||
instance.isMain = false;
|
instance.isMain = false;
|
||||||
onWrappers.add(instance);
|
onWrappers.add(instance);
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package com.github.yulichang.wrapper;
|
package com.github.yulichang.wrapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
import com.github.yulichang.toolkit.LambdaUtils;
|
||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.TableList;
|
||||||
|
import com.github.yulichang.toolkit.WrapperUtils;
|
||||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.*;
|
import com.github.yulichang.wrapper.interfaces.*;
|
||||||
@ -54,17 +55,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
*/
|
*/
|
||||||
private SharedString unionSql;
|
private SharedString unionSql;
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义wrapper索引
|
|
||||||
*/
|
|
||||||
private AtomicInteger wrapperIndex;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义wrapper
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private Map<String, Wrapper<?>> wrapperMap;
|
|
||||||
|
|
||||||
private List<MConsumer<Object>> fill;
|
private List<MConsumer<Object>> fill;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -273,7 +263,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
wrapper.tableList.setParent(this.tableList);
|
wrapper.tableList.setParent(this.tableList);
|
||||||
wrapper.alias = st;
|
wrapper.alias = st;
|
||||||
wrapper.subTableAlias = st;
|
wrapper.subTableAlias = st;
|
||||||
addCustomWrapper(wrapper);
|
|
||||||
consumer.accept(wrapper);
|
consumer.accept(wrapper);
|
||||||
this.selectColumns.add(new SelectSub(() -> WrapperUtils.buildSubSqlByWrapper(clazz, wrapper, alias), hasAlias, this.alias, alias));
|
this.selectColumns.add(new SelectSub(() -> WrapperUtils.buildSubSqlByWrapper(clazz, wrapper, alias), hasAlias, this.alias, alias));
|
||||||
return typedThis;
|
return typedThis;
|
||||||
@ -288,8 +277,13 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
* @since 1.4.8
|
* @since 1.4.8
|
||||||
*/
|
*/
|
||||||
public <U> MPJLambdaWrapper<T> union(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
public <U> MPJLambdaWrapper<T> union(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||||
MPJLambdaWrapper<U> unionWrapper = JoinWrappers.lambda(clazz);
|
MPJLambdaWrapper<U> unionWrapper = new MPJLambdaWrapper<U>(null, clazz, SharedString.emptyString(),
|
||||||
addCustomWrapper(unionWrapper);
|
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||||
|
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
|
new TableList(), null, null, null, null, ifExists) {
|
||||||
|
};
|
||||||
|
unionWrapper.tableList.setAlias(ConfigProperties.tableAlias);
|
||||||
|
unionWrapper.tableList.setRootClass(clazz);
|
||||||
consumer.accept(unionWrapper);
|
consumer.accept(unionWrapper);
|
||||||
|
|
||||||
String sb = " UNION " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
String sb = " UNION " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
||||||
@ -326,8 +320,13 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
* @since 1.4.8
|
* @since 1.4.8
|
||||||
*/
|
*/
|
||||||
public <U> MPJLambdaWrapper<T> unionAll(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
public <U> MPJLambdaWrapper<T> unionAll(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||||
MPJLambdaWrapper<U> unionWrapper = JoinWrappers.lambda(clazz);
|
MPJLambdaWrapper<U> unionWrapper = new MPJLambdaWrapper<U>(null, clazz, SharedString.emptyString(),
|
||||||
addCustomWrapper(unionWrapper);
|
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||||
|
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
|
new TableList(), null, null, null, null, ifExists) {
|
||||||
|
};
|
||||||
|
unionWrapper.tableList.setAlias(ConfigProperties.tableAlias);
|
||||||
|
unionWrapper.tableList.setRootClass(clazz);
|
||||||
consumer.accept(unionWrapper);
|
consumer.accept(unionWrapper);
|
||||||
|
|
||||||
String sb = " UNION ALL " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
String sb = " UNION ALL " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
||||||
@ -339,19 +338,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCustomWrapper(MPJLambdaWrapper<?> wrapper) {
|
|
||||||
if (Objects.isNull(wrapperIndex)) {
|
|
||||||
wrapperIndex = new AtomicInteger(0);
|
|
||||||
}
|
|
||||||
int index = wrapperIndex.incrementAndGet();
|
|
||||||
if (Objects.isNull(wrapperMap)) {
|
|
||||||
wrapperMap = new HashMap<>();
|
|
||||||
}
|
|
||||||
String key = "ew" + index;
|
|
||||||
wrapper.setParamAlias(getParamAlias() + ".wrapperMap." + key);
|
|
||||||
wrapperMap.put(key, wrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条件 SQL 片段
|
* 查询条件 SQL 片段
|
||||||
*/
|
*/
|
||||||
@ -426,8 +412,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
selectDistinct = false;
|
selectDistinct = false;
|
||||||
sqlSelect.toNull();
|
sqlSelect.toNull();
|
||||||
selectColumns.clear();
|
selectColumns.clear();
|
||||||
wrapperIndex = new AtomicInteger(0);
|
|
||||||
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
|
|
||||||
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
||||||
resultMapMybatisLabel.clear();
|
resultMapMybatisLabel.clear();
|
||||||
ifExists = ConfigProperties.ifExists;
|
ifExists = ConfigProperties.ifExists;
|
||||||
|
@ -5,13 +5,13 @@ import com.github.yulichang.interfaces.MPJBaseJoin;
|
|||||||
import com.github.yulichang.query.interfaces.StringJoin;
|
import com.github.yulichang.query.interfaces.StringJoin;
|
||||||
import com.github.yulichang.toolkit.Constant;
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.wrapper.JoinAbstractLambdaWrapper;
|
import com.github.yulichang.wrapper.JoinAbstractLambdaWrapper;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, StringJoin<Children, Entity> {
|
public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, StringJoin<Children, Entity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +34,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, left, rightAlias, right);
|
return join(Constant.LEFT_JOIN, clazz, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param function 条件`
|
* @param function 条件`
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children leftJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, function);
|
return join(Constant.LEFT_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, left, right, ext);
|
return join(Constant.LEFT_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +72,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param consumer 条件
|
* @param consumer 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children leftJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, consumer);
|
return join(Constant.LEFT_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +84,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, alias, left, right);
|
return join(Constant.LEFT_JOIN, clazz, alias, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +97,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, alias, left, rightAlias, right);
|
return join(Constant.LEFT_JOIN, clazz, alias, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +110,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param function 条件
|
* @param function 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children leftJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, alias, function);
|
return join(Constant.LEFT_JOIN, clazz, alias, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +122,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children leftJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, alias, left, right, ext);
|
return join(Constant.LEFT_JOIN, clazz, alias, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,21 +135,149 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param consumer 条件
|
* @param consumer 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children leftJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.LEFT_JOIN, clazz, alias, consumer);
|
return join(Constant.LEFT_JOIN, clazz, alias, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param rightAlias 条件字段别名
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join 多条件
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param function 条件`
|
||||||
|
*/
|
||||||
|
default <T> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join 多条件
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param consumer 条件
|
||||||
|
*/
|
||||||
|
default <T> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, alias, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param rightAlias 条件字段别名
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, alias, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join 多条件
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param function 条件
|
||||||
|
*/
|
||||||
|
default <T> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, alias, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, alias, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* left join 多条件
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param consumer 条件
|
||||||
|
*/
|
||||||
|
default <T> Children leftJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.LEFT_JOIN, clazz, table, alias, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
return join(Constant.RIGHT_JOIN, clazz, left, right);
|
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, left, rightAlias, right);
|
return join(Constant.RIGHT_JOIN, clazz, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +285,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children rightJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children rightJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, function);
|
return join(Constant.RIGHT_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,20 +293,31 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, left, right, ext);
|
return join(Constant.RIGHT_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children rightJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, consumer);
|
return join(Constant.RIGHT_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, alias, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children rightJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, alias, left, rightAlias, right);
|
return join(Constant.RIGHT_JOIN, clazz, alias, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +325,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children rightJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children rightJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, alias, function);
|
return join(Constant.RIGHT_JOIN, clazz, alias, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,21 +333,105 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children rightJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, alias, left, right, ext);
|
return join(Constant.RIGHT_JOIN, clazz, alias, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children rightJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.RIGHT_JOIN, clazz, alias, consumer);
|
return join(Constant.RIGHT_JOIN, clazz, alias, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, left, right);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, alias, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, alias, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, alias, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, alias, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children rightJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.RIGHT_JOIN, clazz, table, alias, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, left, right);
|
return join(Constant.INNER_JOIN, clazz, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +439,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, left, rightAlias, right);
|
return join(Constant.INNER_JOIN, clazz, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +447,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children innerJoin(Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, function);
|
return join(Constant.INNER_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +455,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, left, right, ext);
|
return join(Constant.INNER_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +463,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children innerJoin(Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, consumer);
|
return join(Constant.INNER_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,13 +472,23 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
return join(Constant.INNER_JOIN, clazz, alias, on -> on.eq(left, right));
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, alias, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, alias, left, rightAlias, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children innerJoin(Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, alias, function);
|
return join(Constant.INNER_JOIN, clazz, alias, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,23 +496,99 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
return join(Constant.INNER_JOIN, clazz, alias, left, right, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return join(Constant.INNER_JOIN, clazz, alias, left, right, ext);
|
||||||
* innerjoin两个表支持别名 参考 left join
|
|
||||||
*/
|
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
|
||||||
return join(Constant.INNER_JOIN, clazz, alias, left, rightAlias, right);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children innerJoin(Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
return join(Constant.INNER_JOIN, clazz, alias, consumer);
|
return join(Constant.INNER_JOIN, clazz, alias, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, alias, left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, alias, left, rightAlias, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, alias, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T, X> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, alias, left, right, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore 参考 left join
|
||||||
|
*/
|
||||||
|
default <T> Children innerJoin(Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(Constant.INNER_JOIN, clazz, table, alias, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
@ -348,7 +671,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 扩展 用于关联表的 select 和 where
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
return join(keyWord, clazz, on -> on.eq(left, right));
|
|
||||||
|
return join(keyWord, clazz, null, null, (on, e) -> on.eq(left, right));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -362,7 +686,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 扩展 用于关联表的 select 和 where
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
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, null, null, (on, e) -> on.eq(left, rightAlias, right));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,7 +699,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param function 条件
|
* @param function 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children join(String keyWord, Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children join(String keyWord, Class<T> clazz, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(keyWord, clazz, (on, e) -> function.apply(on));
|
|
||||||
|
return join(keyWord, clazz, null, null, (on, e) -> function.apply(on));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -385,12 +711,21 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
return join(keyWord, clazz, (on, e) -> {
|
|
||||||
|
return join(keyWord, clazz, null, null, (on, e) -> {
|
||||||
on.eq(left, right);
|
on.eq(left, right);
|
||||||
ext.apply(e);
|
ext.apply(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部使用, 不建议直接调用
|
||||||
|
*/
|
||||||
|
default <T> Children join(String keyWord, Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, null, null, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义连表关键词
|
* 自定义连表关键词
|
||||||
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
||||||
@ -403,7 +738,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 扩展 用于关联表的 select 和 where
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
return join(keyWord, clazz, alias, on -> on.eq(left, right));
|
|
||||||
|
return join(keyWord, clazz, null, alias, (on, e) -> on.eq(left, right));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -418,7 +754,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 扩展 用于关联表的 select 和 where
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
return join(keyWord, clazz, alias, on -> on.eq(left, rightAlias, right));
|
|
||||||
|
return join(keyWord, clazz, null, alias, (on, e) -> on.eq(left, rightAlias, right));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -430,7 +767,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param function 条件
|
* @param function 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children join(String keyWord, Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
default <T> Children join(String keyWord, Class<T> clazz, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(keyWord, clazz, alias, (on, e) -> function.apply(on));
|
|
||||||
|
return join(keyWord, clazz, null, alias, (on, e) -> function.apply(on));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,7 +779,8 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
return join(keyWord, clazz, alias, (on, e) -> {
|
|
||||||
|
return join(keyWord, clazz, null, alias, (on, e) -> {
|
||||||
on.eq(left, right);
|
on.eq(left, right);
|
||||||
ext.apply(e);
|
ext.apply(e);
|
||||||
});
|
});
|
||||||
@ -450,12 +789,140 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity>, String
|
|||||||
/**
|
/**
|
||||||
* 内部使用, 不建议直接调用
|
* 内部使用, 不建议直接调用
|
||||||
*/
|
*/
|
||||||
default <T> Children join(String keyWord, Class<T> clazz, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
default <T> Children join(String keyWord, Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
return join(keyWord, clazz, null, consumer);
|
|
||||||
|
return join(keyWord, clazz, null, alias, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
||||||
|
* <p>
|
||||||
|
* 查询基类 可以直接调用此方法实现以上所有功能
|
||||||
|
*
|
||||||
|
* @param keyWord 连表关键字
|
||||||
|
* @param clazz 连表实体类
|
||||||
|
* @param left 关联条件
|
||||||
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, null, (on, e) -> on.eq(left, right));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* <p>
|
||||||
|
* 查询基类 可以直接调用此方法实现以上所有功能
|
||||||
|
*
|
||||||
|
* @param keyWord 连表关键字
|
||||||
|
* @param clazz 连表实体类
|
||||||
|
* @param left 关联条件
|
||||||
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, null, (on, e) -> on.eq(left, rightAlias, right));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param function 条件
|
||||||
|
*/
|
||||||
|
default <T> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, null, (on, e) -> function.apply(on));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, null, (on, e) -> {
|
||||||
|
on.eq(left, right);
|
||||||
|
ext.apply(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内部使用, 不建议直接调用
|
* 内部使用, 不建议直接调用
|
||||||
*/
|
*/
|
||||||
<T> Children join(String keyWord, Class<T> clazz, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer);
|
default <T> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, null, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
||||||
|
* <p>
|
||||||
|
* 查询基类 可以直接调用此方法实现以上所有功能
|
||||||
|
*
|
||||||
|
* @param keyWord 连表关键字
|
||||||
|
* @param clazz 连表实体类
|
||||||
|
* @param left 关联条件
|
||||||
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, alias, (on, e) -> on.eq(left, right));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
||||||
|
* <p>
|
||||||
|
* 查询基类 可以直接调用此方法实现以上所有功能
|
||||||
|
*
|
||||||
|
* @param keyWord 连表关键字
|
||||||
|
* @param clazz 连表实体类
|
||||||
|
* @param left 关联条件
|
||||||
|
* @param right 扩展 用于关联表的 select 和 where
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, String rightAlias, SFunction<X, ?> right) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, alias, (on, e) -> on.eq(left, rightAlias, right));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
* <p>
|
||||||
|
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||||
|
*
|
||||||
|
* @param clazz 关联实体类
|
||||||
|
* @param function 条件
|
||||||
|
*/
|
||||||
|
default <T> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, MFunction<JoinAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, alias, (on, e) -> function.apply(on));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义连表关键词
|
||||||
|
*
|
||||||
|
* @param clazz 关联的实体类
|
||||||
|
* @param left 条件
|
||||||
|
* @param right 条件
|
||||||
|
*/
|
||||||
|
default <T, X> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, SFunction<T, ?> left, SFunction<X, ?> right, MFunction<Children> ext) {
|
||||||
|
|
||||||
|
return join(keyWord, clazz, table, alias, (on, e) -> {
|
||||||
|
on.eq(left, right);
|
||||||
|
ext.apply(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部使用, 不建议直接调用
|
||||||
|
*/
|
||||||
|
<T> Children join(String keyWord, Class<T> clazz, MConsumer<MPJLambdaWrapper<T>> table, String alias, BiConsumer<JoinAbstractLambdaWrapper<Entity, ?>, Children> consumer);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,234 @@
|
|||||||
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||||
|
import com.github.yulichang.test.join.dto.UserDTO;
|
||||||
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
|
import com.github.yulichang.test.join.entity.AreaDO;
|
||||||
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
|
import com.github.yulichang.test.util.Reset;
|
||||||
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
|
import com.github.yulichang.toolkit.JoinWrappers;
|
||||||
|
import com.github.yulichang.wrapper.JoinAbstractLambdaWrapper;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
||||||
|
import org.apache.ibatis.logging.nologging.NoLoggingImpl;
|
||||||
|
import org.apache.ibatis.logging.stdout.StdOutImpl;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JoinTest {
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
Reset.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void joinTest() {
|
||||||
|
ThreadLocalUtils.set("""
|
||||||
|
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
|
||||||
|
FROM `user` t
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT
|
||||||
|
tt.id,
|
||||||
|
tt.user_id,
|
||||||
|
tt.area_id,
|
||||||
|
tt.tel,
|
||||||
|
tt.address,
|
||||||
|
tt.del
|
||||||
|
FROM address tt
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT
|
||||||
|
t.id,
|
||||||
|
t.province,
|
||||||
|
t.city,
|
||||||
|
t.area,
|
||||||
|
t.postcode,
|
||||||
|
t.del
|
||||||
|
FROM area t
|
||||||
|
WHERE t.del = false
|
||||||
|
AND (t.id >= ?)) t1
|
||||||
|
ON (t1.id = tt.area_id)
|
||||||
|
WHERE tt.del = false
|
||||||
|
AND t1.del = false
|
||||||
|
AND (tt.id >= ?)) t1 ON (t1.user_id = t.id)
|
||||||
|
WHERE t.del = false
|
||||||
|
AND t1.del = false
|
||||||
|
AND (t1.id <= ?)
|
||||||
|
""");
|
||||||
|
JoinWrappers.lambda(UserDO.class)
|
||||||
|
.selectAll()
|
||||||
|
.leftJoin(AddressDO.class, t -> t
|
||||||
|
.setAlias("tt")
|
||||||
|
.selectAll()
|
||||||
|
.leftJoin(AreaDO.class, tt -> tt
|
||||||
|
.selectAll()
|
||||||
|
.ge(AreaDO::getId, -1), AreaDO::getId, AddressDO::getAreaId)
|
||||||
|
.ge(AddressDO::getId, 0), AddressDO::getUserId, UserDO::getId)
|
||||||
|
.le(AddressDO::getId, 10000)
|
||||||
|
.list(UserDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
void joinTest1() {
|
||||||
|
//remove log
|
||||||
|
TableInfoHelper.getTableInfo(UserDO.class).getConfiguration().setLogImpl(NoLoggingImpl.class);
|
||||||
|
//@formatter:off
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.leftJoin(AddressDO.class, t -> {}, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.rightJoin(AddressDO.class, t -> {}, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.innerJoin(AddressDO.class, t -> {}, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapperF(w -> w.fullJoin(AddressDO.class, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, (on, ext) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, "a", AddressDO::getUserId, UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, "b", AddressDO::getUserId, "t", UserDO::getId));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, "c", on -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, "d", AddressDO::getUserId, UserDO::getId, ext -> ext));
|
||||||
|
getWrapper(w -> w.join("left join", AddressDO.class, t -> {}, "e", (on, e) -> on.eq(AddressDO::getUserId, UserDO::getId)));
|
||||||
|
|
||||||
|
//@formatter:on
|
||||||
|
assert set.size() == 90;
|
||||||
|
//reset log
|
||||||
|
TableInfoHelper.getTableInfo(UserDO.class).getConfiguration().setLogImpl(StdOutImpl.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Set<String> set = new TreeSet<>();
|
||||||
|
|
||||||
|
private MPJLambdaWrapper<UserDO> w() {
|
||||||
|
return new MPJLambdaWrapper<>(UserDO.class) {
|
||||||
|
@Override
|
||||||
|
public <R> MPJLambdaWrapper<UserDO> join(String keyWord, Class<R> clazz, MConsumer<MPJLambdaWrapper<R>> table, String tableAlias,
|
||||||
|
BiConsumer<JoinAbstractLambdaWrapper<UserDO, ?>, MPJLambdaWrapper<UserDO>> consumer) {
|
||||||
|
String line = Arrays.stream(Thread.getAllStackTraces().get(Thread.currentThread()))
|
||||||
|
.filter(f -> Objects.equals(QueryJoin.class.getName(), f.getClassName()))
|
||||||
|
.map(f -> f.getLineNumber() + "")
|
||||||
|
.collect(Collectors.joining("-"));
|
||||||
|
if (!set.contains(line)) {
|
||||||
|
set.add(line);
|
||||||
|
return super.join(keyWord, clazz, table, tableAlias, consumer);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("repeat line number " + line);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getWrapper(MFunction<MPJLambdaWrapper<UserDO>> consumer) {
|
||||||
|
consumer.apply(w().selectAll()).list(UserDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getWrapperF(MFunction<MPJLambdaWrapper<UserDO>> consumer) {
|
||||||
|
consumer.apply(w().selectAll());
|
||||||
|
}
|
||||||
|
}
|
@ -28,9 +28,33 @@ public class SelectSubTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void sub() {
|
void sub() {
|
||||||
ThreadLocalUtils.set("SELECT (SELECT st.id FROM `user` st WHERE st.del = false AND (st.id = t.id AND st.id = ?) LIMIT 1) AS id, (SELECT st.id FROM `user` st WHERE st.del = false AND (st.id = t.id AND st.id = ?) LIMIT 1) AS name FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false AND (t.id <= ?)");
|
ThreadLocalUtils.set("""
|
||||||
|
SELECT
|
||||||
|
(SELECT
|
||||||
|
(SELECT st.id
|
||||||
|
FROM `user` st
|
||||||
|
WHERE st.del = false
|
||||||
|
AND (st.id = st.id) LIMIT 1) AS id
|
||||||
|
FROM `user` st
|
||||||
|
WHERE st.del = false
|
||||||
|
AND (st.id = t.id AND st.id = ?) LIMIT 1) AS id,
|
||||||
|
(SELECT
|
||||||
|
st.id
|
||||||
|
FROM `user` st
|
||||||
|
WHERE st.del = false
|
||||||
|
AND (st.id = t.id AND st.id = ?) LIMIT 1) AS name
|
||||||
|
FROM `user` t
|
||||||
|
LEFT JOIN address t1 ON (t1.user_id = t.id)
|
||||||
|
WHERE t.del = false
|
||||||
|
AND t1.del = false
|
||||||
|
AND (t.id <= ?)
|
||||||
|
""");
|
||||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectSub(UserDO.class, w -> w.select(UserDO::getId)
|
.selectSub(UserDO.class, w -> w
|
||||||
|
.selectSub(UserDO.class, ww -> ww
|
||||||
|
.select(UserDO::getId)
|
||||||
|
.eq(UserDO::getId, UserDO::getId)
|
||||||
|
.last("limit 1"), UserDO::getId)
|
||||||
.eq(UserDO::getId, UserDO::getId)
|
.eq(UserDO::getId, UserDO::getId)
|
||||||
.eq(UserDO::getId, 2)
|
.eq(UserDO::getId, 2)
|
||||||
.last("limit 1"), UserDO::getId)
|
.last("limit 1"), UserDO::getId)
|
||||||
@ -42,14 +66,14 @@ public class SelectSubTest {
|
|||||||
.le(UserDO::getId, 100);
|
.le(UserDO::getId, 100);
|
||||||
wrapper.list();
|
wrapper.list();
|
||||||
|
|
||||||
ThreadLocalUtils.set("SELECT (SELECT st.id FROM area st WHERE st.del = false AND (st.id = t1.id) LIMIT 1) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false AND (t.id <= ?)");
|
// ThreadLocalUtils.set("SELECT (SELECT st.id FROM area st WHERE st.del = false AND (st.id = t1.id) LIMIT 1) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false AND (t.id <= ?)");
|
||||||
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
// MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectSub(AreaDO.class, w -> w.select(AreaDO::getId)
|
// .selectSub(AreaDO.class, w -> w.select(AreaDO::getId)
|
||||||
.eq(AreaDO::getId, AddressDO::getId)
|
// .eq(AreaDO::getId, AddressDO::getId)
|
||||||
.last("limit 1"), UserDO::getId)
|
// .last("limit 1"), UserDO::getId)
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
// .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||||
.le(UserDO::getId, 100);
|
// .le(UserDO::getId, 100);
|
||||||
wrapper1.list();
|
// wrapper1.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -24,7 +24,28 @@ public class UnionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void unionAll1() {
|
void unionAll1() {
|
||||||
ThreadLocalUtils.set("SELECT t.id FROM `user` t WHERE t.del = false AND (t.id = ?) UNION ALL SELECT t.id FROM address t WHERE (t.id = ?) UNION ALL SELECT (SELECT st.id FROM area st WHERE st.del = false AND (st.id = ? AND (st.id = ?))) AS id FROM area t WHERE t.del = false AND (t.id = ? AND (t.id = ?))");
|
ThreadLocalUtils.set("""
|
||||||
|
SELECT
|
||||||
|
t.id
|
||||||
|
FROM `user` t
|
||||||
|
WHERE t.del = false
|
||||||
|
AND (t.id = ?)
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
t.id
|
||||||
|
FROM address t
|
||||||
|
WHERE (t.id = ?)
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
(SELECT
|
||||||
|
st.id
|
||||||
|
FROM area st
|
||||||
|
WHERE st.del = false
|
||||||
|
AND (st.id = ? AND (st.id = ?))) AS id
|
||||||
|
FROM area t
|
||||||
|
WHERE t.del = false
|
||||||
|
AND (t.id = ? AND (t.id = ?))
|
||||||
|
""");
|
||||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||||
.select(UserDO::getId)
|
.select(UserDO::getId)
|
||||||
.eq(UserDO::getId, 1)
|
.eq(UserDO::getId, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user