mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
fix: 修复apt问题
This commit is contained in:
parent
9d37dd4d7c
commit
f8e51aa958
@ -11,8 +11,10 @@ import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.apt.Column;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
@ -30,6 +32,7 @@ import lombok.Getter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY;
|
||||
@ -416,12 +419,6 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children groupBy(Column column, Column... columns) {
|
||||
return groupBy(true, column, columns);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Children groupBy(boolean condition, Column column, Column... columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
@ -444,25 +441,6 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderByAsc(Column column, Column... columns) {
|
||||
return orderByAsc(true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc("id", "name")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
@Override
|
||||
public Children orderByAsc(boolean condition, Column column, Column... columns) {
|
||||
return orderBy(condition, true, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderByDesc(boolean condition, List<Column> columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
@ -473,26 +451,6 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderByDesc(Column column, Column... columns) {
|
||||
return orderByDesc(true, column, columns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
* <p>例: orderByDesc("id", "name")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
@Override
|
||||
public Children orderByDesc(boolean condition, Column column, Column... columns) {
|
||||
return orderBy(condition, false, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderBy(boolean condition, boolean isAsc, Column column, Column... columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
@ -832,6 +790,67 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
/* ****************************************** **/
|
||||
|
||||
|
||||
/* ******* lambda group by order by ********* */
|
||||
|
||||
@Override
|
||||
public <X> Children groupByLambda(boolean condition, List<SFunction<X, ?>> columns) {
|
||||
return groupBy(condition, columns.stream().map(LambdaUtils::getName).collect(joining(StringPool.COMMA)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children groupBy(SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return groupBy(true, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children groupBy(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return groupBy(condition, LambdaUtils.getName(column), Arrays.stream(columns).map(LambdaUtils::getName).toArray(String[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children orderByAscLambda(boolean condition, List<SFunction<X, ?>> columns) {
|
||||
return orderByAscStr(condition, columns.stream().map(LambdaUtils::getName).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children orderByAsc(SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return orderByAsc(true, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children orderByAsc(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return orderByAsc(condition, LambdaUtils.getName(column), Arrays.stream(columns).map(LambdaUtils::getName).toArray(String[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children orderByDescLambda(boolean condition, List<SFunction<X, ?>> columns) {
|
||||
return orderByDescStr(condition, columns.stream().map(LambdaUtils::getName).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children orderByDesc(SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return orderByDesc(true, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children orderByDesc(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return orderByDesc(condition, LambdaUtils.getName(column), Arrays.stream(columns).map(LambdaUtils::getName).toArray(String[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
public final <X> Children orderBy(boolean condition, boolean isAsc, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||
return orderBy(condition, isAsc, LambdaUtils.getName(column), Arrays.stream(columns).map(LambdaUtils::getName).toArray(String[]::new));
|
||||
}
|
||||
/* ******************************************** */
|
||||
|
||||
|
||||
@Override
|
||||
public <V> Children allEqStr(boolean condition, Map<String, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
|
@ -2,7 +2,6 @@ package com.github.yulichang.wrapper.apt.interfaces;
|
||||
|
||||
import com.github.yulichang.apt.Column;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@ -13,7 +12,7 @@ import java.util.function.Consumer;
|
||||
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Func<Children> extends Serializable {
|
||||
public interface Func<Children> extends FuncLambda<Children> {
|
||||
|
||||
|
||||
default Children isNull(Column column) {
|
||||
@ -64,7 +63,6 @@ public interface Func<Children> extends Serializable {
|
||||
|
||||
Children inSql(boolean condition, Column column, String inValue);
|
||||
|
||||
|
||||
default Children notInSql(Column column, String inValue) {
|
||||
return notInSql(true, column, inValue);
|
||||
}
|
||||
@ -133,7 +131,6 @@ public interface Func<Children> extends Serializable {
|
||||
return orderByAsc(true, column, columns);
|
||||
}
|
||||
|
||||
|
||||
default Children orderByAsc(boolean condition, Column column, Column... columns) {
|
||||
return orderBy(condition, true, column, columns);
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.github.yulichang.wrapper.apt.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 将原来的泛型R改成SFunction<X,?>
|
||||
* <p>
|
||||
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public interface FuncLambda<Children> extends Serializable {
|
||||
|
||||
default <X> Children groupBy(SFunction<X, ?> column) {
|
||||
return groupBy(true, column);
|
||||
}
|
||||
|
||||
default <X> Children groupByLambda(List<SFunction<X, ?>> column) {
|
||||
return groupByLambda(true, column);
|
||||
}
|
||||
|
||||
<X> Children groupByLambda(boolean condition, List<SFunction<X, ?>> columns);
|
||||
|
||||
<X> Children groupBy(SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
<X> Children groupBy(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
|
||||
default <X> Children orderByAsc(SFunction<X, ?> column) {
|
||||
return orderByAsc(true, column);
|
||||
}
|
||||
|
||||
default <X> Children orderByAscLambda(List<SFunction<X, ?>> columns) {
|
||||
return orderByAscLambda(true, columns);
|
||||
}
|
||||
|
||||
<X> Children orderByAscLambda(boolean condition, List<SFunction<X, ?>> columns);
|
||||
|
||||
|
||||
<X> Children orderByAsc(SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
<X> Children orderByAsc(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
default <X> Children orderByDesc(SFunction<X, ?> column) {
|
||||
return orderByDesc(true, column);
|
||||
}
|
||||
|
||||
default <X> Children orderByDescLambda(List<SFunction<X, ?>> columns) {
|
||||
return orderByDescLambda(true, columns);
|
||||
}
|
||||
|
||||
<X> Children orderByDescLambda(boolean condition, List<SFunction<X, ?>> columns);
|
||||
|
||||
<X> Children orderByDesc(SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
<X> Children orderByDesc(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
|
||||
<X> Children orderBy(boolean condition, boolean isAsc, SFunction<X, ?> column, SFunction<X, ?>... columns);
|
||||
}
|
@ -3,16 +3,24 @@ package com.github.yulichang.test.util;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EnabledIf {
|
||||
public class EnabledIfConfig {
|
||||
|
||||
public static final String runWithMysql = "#{T(com.github.yulichang.test.util.EnabledIfConfig).runWithMysql()}";
|
||||
|
||||
public static boolean runWithMysql() {
|
||||
return DbTypeUtil.getDbType() == DbType.MYSQL;
|
||||
}
|
||||
|
||||
|
||||
public static final String runWithPgsql = "#{T(com.github.yulichang.test.util.EnabledIfConfig).runWithPgsql()}";
|
||||
|
||||
public static boolean runWithPgsql() {
|
||||
return DbTypeUtil.getDbType() == DbType.POSTGRE_SQL;
|
||||
}
|
||||
|
||||
|
||||
public static final String runWithExcludingOracle = "#{T(com.github.yulichang.test.util.EnabledIfConfig).runWithExcludingOracle()}";
|
||||
|
||||
public static boolean runWithExcludingOracle() {
|
||||
return DbTypeUtil.getDbType() != DbType.ORACLE;
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.AddressDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
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.segments.Fun;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class ApplyFuncTest {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void applyFunc() {
|
||||
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 address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false " +
|
||||
"AND (concat(t.id, t1.user_id, ?) IS NOT NULL " +
|
||||
"AND concat(t.id, t1.user_id, ?) IS NOT NULL)");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr = new AddressDOCol();
|
||||
|
||||
List<UserDO> list = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.leftJoin(addr, addr.userId, u.id)
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(u.id, addr.userId), "12")
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(u.id, addr.userId), "12")
|
||||
.list();
|
||||
|
||||
list.forEach(System.out::println);
|
||||
|
||||
ThreadLocalUtils.set("SELECT 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 address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false " +
|
||||
"AND (concat(t.id, t1.user_id, ?) IS NOT NULL " +
|
||||
"AND concat(t.id, t1.user_id, ?) IS NOT NULL)");
|
||||
|
||||
UserDOCol u1 = new UserDOCol();
|
||||
AddressDOCol addr1 = new AddressDOCol();
|
||||
|
||||
List<UserDO> list1 = JoinWrappers.apt(u1)
|
||||
.selectAll(u1, u1.id)
|
||||
.leftJoin(addr1, addr1.userId, u1.id)
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(u1.id, addr1.userId), "12")
|
||||
.applyFunc("concat(%s,%s,{0}) is not null", arg -> arg.accept(u1.id,addr1.userId), "12")
|
||||
.list();
|
||||
|
||||
list1.forEach(System.out::println);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
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.MPJLambdaWrapper;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class AroundTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void around() {
|
||||
ThreadLocalUtils.set("SELECT * 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 FROM `user` t WHERE t.del = false) tmp");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.around("select * from (", ") tmp");
|
||||
wrapper.list().forEach(System.out::println);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserTenantaDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserTenantDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserTenantaDOCol;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class ChineseFieldTest {
|
||||
|
||||
@Test
|
||||
void chineseField() {
|
||||
UserTenantaDOCol ut = new UserTenantaDOCol();
|
||||
List<UserTenantaDO> list = JoinWrappers.apt(ut).list();
|
||||
assert list.get(0).getDetail() != null;
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.apt.BaseColumn;
|
||||
import com.github.yulichang.apt.Column;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@SpringBootTest
|
||||
public class CustomWrapperTest {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
//自定义wrapper扩展
|
||||
public static class CWrapper<T> extends AptQueryWrapper<T> {
|
||||
|
||||
public CWrapper(BaseColumn<T> baseColumn) {
|
||||
super(baseColumn);
|
||||
}
|
||||
|
||||
public CWrapper(BaseColumn<T> baseColumn, T entity) {
|
||||
super(baseColumn, entity);
|
||||
}
|
||||
|
||||
public static <T> CWrapper<T> toCWrapper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CWrapper<T> eqIfExists(Column column, Object val) {
|
||||
super.eq(Objects.nonNull(val), column, val);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWrapperCustomer() {
|
||||
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 WHERE t.del = false AND (t.id = ?)");
|
||||
UserDOCol u = new UserDOCol();
|
||||
CWrapper<UserDO> wrapper = new CWrapper<>(u)
|
||||
.selectAll()
|
||||
.toChildren(CWrapper::toCWrapper)
|
||||
.eqIfExists(u.id, 1);
|
||||
List<UserDO> dos = userMapper.selectList(wrapper);
|
||||
dos.forEach(System.out::println);
|
||||
|
||||
UserDOCol u1 = new UserDOCol();
|
||||
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 WHERE t.del = false");
|
||||
CWrapper<UserDO> wrapper1 = new CWrapper<>(u1)
|
||||
.selectAll()
|
||||
.toChildren(new Ref<CWrapper<UserDO>>())
|
||||
.eqIfExists(u1.id, null);
|
||||
List<UserDO> dos1 = userMapper.selectList(wrapper1);
|
||||
dos1.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class EqSqlTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void eqSql() {
|
||||
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 WHERE t.del = false AND (t.id = (SELECT id FROM `user` WHERE id = 1))");
|
||||
UserDOCol u = new UserDOCol();
|
||||
JoinWrappers.apt(u).eqSql(u.id, "select id from `user` where id = 1").list();
|
||||
|
||||
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 WHERE t.del = false AND (t.id = (SELECT id FROM `user` WHERE id = 1))");
|
||||
UserDOCol u1 = new UserDOCol();
|
||||
JoinWrappers.apt(u1).eqSql("t.id", "select id from `user` where id = 1").list();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.UserTenantDO;
|
||||
import com.github.yulichang.test.join.entity.apt.AddressDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserTenantDOCol;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.join.mapper.UserTenantMapper;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class FieldAliasTest {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private UserTenantMapper userTenantMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void fieldAlias() {
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr = new AddressDOCol();
|
||||
List<UserDO> list = userMapper.selectList(JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.leftJoin(addr, addr.userId, u.id));
|
||||
|
||||
list.forEach(System.out::println);
|
||||
|
||||
assert list.get(0).getImg() != null;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldAlias1() {
|
||||
UserTenantDOCol ut = new UserTenantDOCol();
|
||||
UserDOCol u = new UserDOCol();
|
||||
AptQueryWrapper<UserTenantDO> wrapper = JoinWrappers.apt(ut)
|
||||
.selectAll()
|
||||
.leftJoin(u, u.id, ut.uuid);
|
||||
List<UserTenantDO> list = userTenantMapper.selectList(wrapper);
|
||||
|
||||
assert list.get(0).getIdea() != null;
|
||||
assert list.get(0).getUuid() != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.dto.AreaDTO;
|
||||
import com.github.yulichang.test.join.entity.AreaDO;
|
||||
import com.github.yulichang.test.join.entity.apt.AreaDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDtoCol;
|
||||
import com.github.yulichang.test.join.mapper.AreaMapper;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class FieldNameTest {
|
||||
|
||||
@Autowired
|
||||
private AreaMapper areaMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testFieldName() {
|
||||
AreaDOCol ar = new AreaDOCol();
|
||||
UserDtoCol ud = new UserDtoCol();
|
||||
List<AreaDO> list = areaMapper.selectJoinList(AreaDO.class, JoinWrappers.apt(ar)
|
||||
.select(ar.Postcode)
|
||||
.leftJoin(ud, ud.id, ar.id));
|
||||
|
||||
assert list.get(0).getPostcode() != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFieldName1() {
|
||||
AreaDOCol ar = new AreaDOCol();
|
||||
UserDtoCol ud = new UserDtoCol();
|
||||
List<AreaDTO> list = areaMapper.selectJoinList(AreaDTO.class, JoinWrappers.apt(ar)
|
||||
.selectAs(ar.Postcode, AreaDTO::getPostcode)
|
||||
.leftJoin(ud, ud.id, ar.id));
|
||||
|
||||
assert list.get(0).getPostcode() != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
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.MPJLambdaWrapper;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class IfExistsTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void IfExists() {
|
||||
assert IfExistsEnum.NOT_EMPTY.test("\t");
|
||||
assert !IfExistsEnum.NOT_EMPTY.test("");
|
||||
assert IfExistsEnum.NOT_EMPTY.test(" ");
|
||||
assert IfExistsEnum.NOT_EMPTY.test("\r");
|
||||
assert IfExistsEnum.NOT_EMPTY.test("a");
|
||||
assert IfExistsEnum.NOT_EMPTY.test(1);
|
||||
assert IfExistsEnum.NOT_EMPTY.test(true);
|
||||
assert IfExistsEnum.NOT_EMPTY.test('A');
|
||||
|
||||
assert !IfExistsEnum.NOT_BLANK.test("\t");
|
||||
assert !IfExistsEnum.NOT_BLANK.test("");
|
||||
assert !IfExistsEnum.NOT_BLANK.test(" ");
|
||||
assert !IfExistsEnum.NOT_BLANK.test("\r");
|
||||
assert IfExistsEnum.NOT_BLANK.test("a");
|
||||
assert IfExistsEnum.NOT_EMPTY.test(1);
|
||||
assert IfExistsEnum.NOT_EMPTY.test(true);
|
||||
assert IfExistsEnum.NOT_EMPTY.test('A');
|
||||
|
||||
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 " +
|
||||
"WHERE t.del = false AND (t.id = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.eqIfExists(u.id, 1)
|
||||
.eqIfExists(u.pid, null)
|
||||
.eqIfExists(u.addressId, "")
|
||||
.eqIfExists(u.img, "\t")
|
||||
.eqIfExists(u.name, "张三 1");
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
|
||||
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 " +
|
||||
"WHERE t.del = false AND (t.id = ? AND t.`name` = ?)");
|
||||
UserDOCol u1 = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper1 = JoinWrappers.apt(u1)
|
||||
.selectAll()
|
||||
.setIfExists(IfExistsEnum.NOT_BLANK)
|
||||
.eqIfExists(u1.id, 1)
|
||||
.eqIfExists(u1.pid, null)
|
||||
.eqIfExists(u1.addressId, "")
|
||||
.eqIfExists(u1.img, "\t")
|
||||
.eqIfExists(u1.name, "张三 1");
|
||||
List<UserDO> list1 = wrapper1.list();
|
||||
list1.forEach(System.out::println);
|
||||
|
||||
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 " +
|
||||
"WHERE t.del = false AND (t.id = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||
UserDOCol u2 = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper2 = JoinWrappers.apt(u2)
|
||||
.selectAll()
|
||||
.setIfExists(o -> true)
|
||||
.eqIfExists(u2.id, 1)
|
||||
.eqIfExists(u2.name, "")
|
||||
.eqIfExists(u2.img, "\t")
|
||||
.eqIfExists(u2.name, "张三 1");
|
||||
List<UserDO> list2 = wrapper2.list();
|
||||
list2.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
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.MPJLambdaWrapper;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class NotLikeLeftRightTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void notLikeLeftRight() {
|
||||
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 WHERE t.del = false AND (t.`name` NOT LIKE ?)");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.notLikeLeft(u.name, "aa");
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
|
||||
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 WHERE t.del = false AND (t.`name` NOT LIKE ?)");
|
||||
UserDOCol u1 = new UserDOCol();
|
||||
AptQueryWrapper<UserDO> wrapper1 = JoinWrappers.apt(u1)
|
||||
.selectAll()
|
||||
.notLikeRight(u1.name, "aa");
|
||||
List<UserDO> list1 = wrapper1.list();
|
||||
list1.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.apt.Column;
|
||||
import com.github.yulichang.test.join.dto.UserDTO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.AddressDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle,loadContext = true)
|
||||
public class OrderByTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderBy() {
|
||||
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 WHERE t.del = false AND (t.id = ?) ORDER BY t.id ASC, t.`name` ASC, t.pid ASC");
|
||||
UserDOCol u = new UserDOCol();
|
||||
List<Column> columList = Arrays.asList(u.id, u.name, u.pid);
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.eq(u.id, 1)
|
||||
.orderByAsc(columList);
|
||||
|
||||
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderBy1() {
|
||||
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 WHERE t.del = false AND (t.id = ?) GROUP BY t.id, t.`name`, t.pid");
|
||||
UserDOCol u = new UserDOCol();
|
||||
List<Column> columList = Arrays.asList(u.id, u.name, u.pid);
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.eq(u.id, 1)
|
||||
.groupBy(columList);
|
||||
|
||||
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void orderBy2() {
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr = new AddressDOCol();
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.selectAs(addr.id, UserDTO::getAddress)
|
||||
.leftJoin(addr, addr.userId, u.id)
|
||||
.orderByAsc(UserDTO::getAddress);
|
||||
|
||||
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
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.EnabledIfConfig;
|
||||
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.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle, loadContext = true)
|
||||
public class SelectSubTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* select 子查询
|
||||
*/
|
||||
@Test
|
||||
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 <= ?)");
|
||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||
.selectSub(UserDO.class, w -> w.select(UserDO::getId)
|
||||
.eq(UserDO::getId, UserDO::getId)
|
||||
.eq(UserDO::getId, 2)
|
||||
.last("limit 1"), UserDO::getId)
|
||||
.selectSub(UserDO.class, w -> w.select(UserDO::getId)
|
||||
.eq(UserDO::getId, UserDO::getId)
|
||||
.eq(UserDO::getId, 3)
|
||||
.last("limit 1"), UserDO::getName)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.le(UserDO::getId, 100);
|
||||
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 <= ?)");
|
||||
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
||||
.selectSub(AreaDO.class, w -> w.select(AreaDO::getId)
|
||||
.eq(AreaDO::getId, AddressDO::getId)
|
||||
.last("limit 1"), UserDO::getId)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.le(UserDO::getId, 100);
|
||||
wrapper1.list();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sub1() {
|
||||
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)
|
||||
.selectSub(AreaDO.class, w -> w.select(AreaDO::getId)
|
||||
.eq(AreaDO::getId, AddressDO::getId)
|
||||
.setTableName(t -> "`" + t + "`")
|
||||
.last("limit 1"), UserDO::getId)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||
.le(UserDO::getId, 100);
|
||||
wrapper1.list();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.dto.UserDTO;
|
||||
import com.github.yulichang.test.join.entity.apt.AddressDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
import com.github.yulichang.wrapper.apt.AptQueryWrapper;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class StringColumTest {
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void stringColum() {
|
||||
ThreadLocalUtils.set("SELECT (SELECT id FROM `user` u WHERE u.id = t.id) id, t.`name` AS PName, t.`name` PName, t.`name`," +
|
||||
" (SELECT id FROM `user` u WHERE u.id = t.id), t1.id AS joina_id, t1.user_id, t1.area_id, t1.tel, " +
|
||||
"t1.address, t1.del FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr = new AddressDOCol();
|
||||
List<UserDTO> l3 = userMapper.selectJoinList(UserDTO.class, new AptQueryWrapper<>(u)
|
||||
.select("(select id from `user` u where u.id = t.id) id")
|
||||
.select("t.`name` as PName")
|
||||
.select("t.`name` PName")
|
||||
.select("t.`name`")
|
||||
.select("(select id from `user` u where u.id = t.id) ")
|
||||
.selectAssociation(addr, UserDTO::getAddressDTO)
|
||||
.leftJoin(addr, addr.userId, u.id));
|
||||
assert l3.get(0).getPName() != null;
|
||||
l3.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.apt.AddressDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.AreaDOCol;
|
||||
import com.github.yulichang.test.join.entity.apt.UserDOCol;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.apt.AptQueryWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle, loadContext = true)
|
||||
public class TableAliasTest {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void tableAlias() {
|
||||
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 address addr1 ON (addr1.id = t.address_id) " +
|
||||
"LEFT JOIN address addr2 ON (addr2.id = t.address_id2) " +
|
||||
"LEFT JOIN area area1 ON (area1.id = addr1.area_id) " +
|
||||
"WHERE t.del = false AND addr1.del = false AND addr2.del = false AND area1.del = false " +
|
||||
"GROUP BY t.id");
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr1 = new AddressDOCol("addr1");
|
||||
AddressDOCol addr2 = new AddressDOCol("addr2");
|
||||
AreaDOCol area1 = new AreaDOCol("area1");
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.leftJoin(addr1, addr1.id, u.addressId)
|
||||
.leftJoin(addr2, addr2.id, u.addressId2)
|
||||
.leftJoin(area1, area1.id, addr1.areaId)
|
||||
.groupBy(u.id);
|
||||
|
||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
dos.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tableAlias2() {
|
||||
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 address addr1 ON (addr1.id = t.address_id) " +
|
||||
"LEFT JOIN address addr2 ON (addr2.id = t.address_id2) " +
|
||||
"LEFT JOIN area area1 ON (area1.id = addr2.area_id) " +
|
||||
"WHERE t.del = false AND addr1.del = false AND addr2.del = false AND area1.del = false " +
|
||||
"GROUP BY t.id,addr1.id ORDER BY addr1.id DESC");
|
||||
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr1 = new AddressDOCol("addr1");
|
||||
AddressDOCol addr2 = new AddressDOCol("addr2");
|
||||
AreaDOCol area1 = new AreaDOCol("area1");
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.leftJoin(addr1, addr1.id, u.addressId)
|
||||
.leftJoin(addr2, addr2.id, u.addressId2)
|
||||
.leftJoin(area1, area1.id, addr2.areaId)
|
||||
.groupBy(u.id)
|
||||
.groupBy(addr1.id)
|
||||
.orderByDesc(addr1.id);
|
||||
|
||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
dos.forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void tableAliasEQ() {
|
||||
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 address addr1 ON (addr1.id = t.address_id) " +
|
||||
"LEFT JOIN address addr2 ON (addr2.id = t.address_id2) " +
|
||||
"LEFT JOIN area area1 ON (area1.id = addr2.area_id) WHERE t.del = false AND addr1.del = false AND addr2.del = false AND area1.del = false " +
|
||||
"AND (addr1.id = ? AND addr2.id = ? AND addr1.id = ?)");
|
||||
|
||||
UserDOCol u = new UserDOCol();
|
||||
AddressDOCol addr1 = new AddressDOCol("addr1");
|
||||
AddressDOCol addr2 = new AddressDOCol("addr2");
|
||||
AreaDOCol area1 = new AreaDOCol("area1");
|
||||
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u)
|
||||
.selectAll()
|
||||
.leftJoin(addr1, addr1.id, u.addressId)
|
||||
.leftJoin(addr2, addr2.id, u.addressId2)
|
||||
.leftJoin(area1, area1.id, addr2.areaId)
|
||||
.eq(addr1.id, 1)
|
||||
.eq(addr2.id, 2)
|
||||
.eq(addr1.id, 3);
|
||||
|
||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);
|
||||
dos.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tableAlias3() {
|
||||
ThreadLocalUtils.set("SELECT aaa.id, aaa.pid, aaa.`name`, aaa.`json`, aaa.sex, aaa.head_img, aaa.create_time, " +
|
||||
"aaa.address_id, aaa.address_id2, aaa.del, aaa.create_by, aaa.update_by FROM `user` aaa WHERE aaa.`name` = ? AND aaa.del = false");
|
||||
|
||||
UserDOCol u = new UserDOCol("aaa");
|
||||
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setName("aaa");
|
||||
AptQueryWrapper<UserDO> wrapper = JoinWrappers.apt(u, userDO);
|
||||
wrapper.list();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.yulichang.test.join.apt.unit;
|
||||
|
||||
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.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class UnionTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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 = ?))");
|
||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||
.select(UserDO::getId)
|
||||
.eq(UserDO::getId, 1)
|
||||
.unionAll(AddressDO.class, union -> union
|
||||
.select(AddressDO::getId)
|
||||
.disableLogicDel()
|
||||
.eq(UserDO::getId, 2))
|
||||
.unionAll(AreaDO.class, union -> union
|
||||
.selectSub(AreaDO.class, sub -> sub
|
||||
.select(AreaDO::getId)
|
||||
.eq(AreaDO::getId, 3)
|
||||
.and(and -> and.eq(AreaDO::getId, 4)), AreaDO::getId)
|
||||
.eq(AreaDO::getId, 5)
|
||||
.and(and -> and.eq(AreaDO::getId, 6)));
|
||||
List<UserDO> list = wrapper.list();
|
||||
assert list.size() == 2 && list.get(0).getId() != null;
|
||||
}
|
||||
}
|
@ -3,22 +3,23 @@ package com.github.yulichang.test.join.mysql;
|
||||
import com.github.yulichang.test.join.entity.*;
|
||||
import com.github.yulichang.test.join.mapper.OrderMapper;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.DeleteJoinWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
/**
|
||||
* 连表删除没有同意语法语法,不同数据库差别较大
|
||||
* MPJ 连表更新 目前只支持 mysql
|
||||
*/
|
||||
@SpringBootTest("spring.profiles.active=mysql")
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithMysql, loadContext = true)
|
||||
public class DeleteJoinTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -3,22 +3,23 @@ package com.github.yulichang.test.join.mysql;
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
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.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
/**
|
||||
* 由于不同数据库函数支持情况不同
|
||||
* 此类用于测试 mysql 专属语法或函数
|
||||
*/
|
||||
@SpringBootTest("spring.profiles.active=mysql")
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithMysql, loadContext = true)
|
||||
public class MysqlTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -6,15 +6,16 @@ import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.OrderDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.UpdateJoinWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,7 +25,7 @@ import java.util.List;
|
||||
* MPJ 连表更新 目前只支持 mysql
|
||||
*/
|
||||
@SpringBootTest("spring.profiles.active=mysql")
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithMysql,loadContext = true)
|
||||
public class UpdateJoinTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -4,20 +4,21 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.test.join.dto.UserDTO;
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle, loadContext = true)
|
||||
public class OrderByTest {
|
||||
|
||||
@BeforeEach
|
||||
|
@ -3,17 +3,18 @@ package com.github.yulichang.test.join.unit;
|
||||
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.EnabledIfConfig;
|
||||
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.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle, loadContext = true)
|
||||
public class SelectSubTest {
|
||||
|
||||
@BeforeEach
|
||||
|
@ -4,20 +4,21 @@ 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.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.util.EnabledIfConfig;
|
||||
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.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||
@EnabledIf(value = EnabledIfConfig.runWithExcludingOracle, loadContext = true)
|
||||
public class TableAliasTest {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
Loading…
x
Reference in New Issue
Block a user