mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
test: 代码调整
This commit is contained in:
parent
79e875f8d1
commit
629101a774
@ -0,0 +1,15 @@
|
|||||||
|
package com.github.yulichang.test.util;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class EnabledIf {
|
||||||
|
|
||||||
|
public static boolean runWithMysql() {
|
||||||
|
return DbTypeUtil.getDbType() == DbType.MYSQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean runWithExcludingOracle() {
|
||||||
|
return DbTypeUtil.getDbType() != DbType.ORACLE;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ public class Reset {
|
|||||||
|
|
||||||
@SuppressWarnings({"DataFlowIssue"})
|
@SuppressWarnings({"DataFlowIssue"})
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
|
ThreadLocalUtils.set("");
|
||||||
SqlSession session = SpringContentUtils.getBean(SqlSessionTemplate.class)
|
SqlSession session = SpringContentUtils.getBean(SqlSessionTemplate.class)
|
||||||
.getSqlSessionFactory().openSession(true);
|
.getSqlSessionFactory().openSession(true);
|
||||||
Connection connection = session.getConnection();
|
Connection connection = session.getConnection();
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package com.github.yulichang.test.util;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
|
||||||
import com.github.yulichang.wrapper.interfaces.DoSomething;
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Throw {
|
|
||||||
|
|
||||||
|
|
||||||
public static void tryDo(DoSomething doSomething) {
|
|
||||||
try {
|
|
||||||
doSomething.doIt();
|
|
||||||
} catch (BadSqlGrammarException e) {
|
|
||||||
if (DbTypeUtil.getDbType() != DbType.H2) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tryDo(DoSomething doSomething, DbType... ignore) {
|
|
||||||
try {
|
|
||||||
doSomething.doIt();
|
|
||||||
} catch (BadSqlGrammarException e) {
|
|
||||||
if (DbTypeUtil.getDbType() != DbType.H2 && Arrays.stream(ignore).noneMatch(n -> n == DbTypeUtil.getDbType())) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tryDoIgnore(DoSomething doSomething) {
|
|
||||||
try {
|
|
||||||
doSomething.doIt();
|
|
||||||
} catch (BadSqlGrammarException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.yulichang.test.join;
|
package com.github.yulichang.test.join;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
|
||||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@ -15,18 +14,16 @@ import com.github.yulichang.test.join.entity.*;
|
|||||||
import com.github.yulichang.test.join.mapper.*;
|
import com.github.yulichang.test.join.mapper.*;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
import com.github.yulichang.test.util.Throw;
|
|
||||||
import com.github.yulichang.toolkit.JoinWrappers;
|
import com.github.yulichang.toolkit.JoinWrappers;
|
||||||
import com.github.yulichang.wrapper.DeleteJoinWrapper;
|
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.github.yulichang.wrapper.UpdateJoinWrapper;
|
import lombok.SneakyThrows;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -656,7 +653,11 @@ class LambdaWrapperTest {
|
|||||||
"WHERE t.del = false\n" +
|
"WHERE t.del = false\n" +
|
||||||
" AND t1.del = false\n" +
|
" AND t1.del = false\n" +
|
||||||
" AND (t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?)\n" +
|
" AND (t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?)\n" +
|
||||||
"LIMIT ?");
|
"LIMIT ?",
|
||||||
|
"SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, " +
|
||||||
|
"t.create_time, t.address_id, t.address_id2, t.del, t.create_by, t.update_by, t1.address FROM `user` t " +
|
||||||
|
"LEFT JOIN address t1 ON (t.id = t1.user_id AND t.id = t1.user_id) WHERE t.del = false AND t1.del = false AND " +
|
||||||
|
"(t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?) ) TMP WHERE ROWNUM <=?) WHERE ROW_ID > ?");
|
||||||
IPage<UserDTO> page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class,
|
IPage<UserDTO> page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class,
|
||||||
JoinWrappers.<UserDO>lambda()
|
JoinWrappers.<UserDO>lambda()
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
@ -684,38 +685,17 @@ class LambdaWrapperTest {
|
|||||||
System.out.println(one);
|
System.out.println(one);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忽略个别查询字段
|
* 忽略个别查询字段
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void test6() {
|
@SneakyThrows
|
||||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
void test8() throws BadSqlGrammarException {
|
||||||
.selectAll(UserDO.class)
|
|
||||||
.selectFilter(AddressDO.class, p -> true)
|
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
|
||||||
.eq(UserDO::getId, 1);
|
|
||||||
IPage<UserDTO> page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, wrapper);
|
|
||||||
assert page.getRecords().get(0).getAddress() != null;
|
|
||||||
page.getRecords().forEach(System.out::println);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 忽略个别查询字段
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void test8() {
|
|
||||||
ThreadLocalUtils.set("SELECT t.`name` FROM `user` t WHERE t.del=false AND (t.`name` = ?)");
|
ThreadLocalUtils.set("SELECT t.`name` FROM `user` t WHERE t.del=false AND (t.`name` = ?)");
|
||||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
||||||
.select(UserDO::getName)
|
.select(UserDO::getName)
|
||||||
.eq(UserDO::getName, "ref");
|
.eq(UserDO::getName, "ref");
|
||||||
userMapper.selectList(wrapper);
|
userMapper.selectList(wrapper);
|
||||||
Throw.tryDo(() -> {
|
|
||||||
userMapper.insertBatchSomeColumn(new ArrayList<UserDO>() {{
|
|
||||||
add(new UserDO());
|
|
||||||
}});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -752,21 +732,6 @@ class LambdaWrapperTest {
|
|||||||
assert dos1.size() == 4;
|
assert dos1.size() == 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 函数测试
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void testFunc() {
|
|
||||||
ThreadLocalUtils.set("SELECT if(t1.user_id < 5,t1.user_id,t1.user_id + 100) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del=false AND t1.del=false");
|
|
||||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
|
||||||
.selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId)
|
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId);
|
|
||||||
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);
|
|
||||||
},DbType.ORACLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 泛型测试
|
* 泛型测试
|
||||||
*/
|
*/
|
||||||
@ -808,20 +773,20 @@ class LambdaWrapperTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testTable() {
|
void testTable() {
|
||||||
ThreadLocalUtils.set("SELECT t.id FROM bbbbbbb t LEFT JOIN addressaaaaaaaaaa t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id <= ?) ORDER BY t.id DESC");
|
ThreadLocalUtils.set("SELECT t.id FROM (SELECT * FROM `user`) t LEFT JOIN (SELECT * FROM address) t1 ON " +
|
||||||
|
"(t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) WHERE t.del = false AND t1.del = false " +
|
||||||
|
"AND t2.del = false AND (t.id <= ?) ORDER BY t.id DESC");
|
||||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
||||||
.select(UserDO::getId)
|
.select(UserDO::getId)
|
||||||
.leftJoin(AddressDO.class, on -> on
|
.leftJoin(AddressDO.class, on -> on
|
||||||
.eq(AddressDO::getUserId, UserDO::getId)
|
.eq(AddressDO::getUserId, UserDO::getId)
|
||||||
.setTableName(name -> name + "aaaaaaaaaa"))
|
.setTableName(name -> String.format("(select * from %s)", name)))
|
||||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
||||||
.le(UserDO::getId, 10000)
|
.le(UserDO::getId, 10000)
|
||||||
.orderByDesc(UserDO::getId)
|
.orderByDesc(UserDO::getId)
|
||||||
.setTableName(name -> "bbbbbbb");
|
.setTableName(name -> String.format("(select * from %s)", name));
|
||||||
|
|
||||||
Throw.tryDoIgnore(() -> {
|
|
||||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1020,63 +985,6 @@ class LambdaWrapperTest {
|
|||||||
List<OrderDO> l = w.list();
|
List<OrderDO> l = w.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 同一个类字段比较
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void delete() {
|
|
||||||
//物理删除
|
|
||||||
ThreadLocalUtils.set("DELETE t FROM order_t t LEFT JOIN user_dto t1 ON (t1.id = t.user_id) WHERE (t.id = ?)");
|
|
||||||
DeleteJoinWrapper<OrderDO> w = JoinWrappers.delete(OrderDO.class)
|
|
||||||
.leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId)
|
|
||||||
.eq(OrderDO::getId, 1);
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
int i = orderMapper.deleteJoin(w);
|
|
||||||
});
|
|
||||||
//忽略异常 h2不支持连表删除
|
|
||||||
//逻辑删除
|
|
||||||
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)");
|
|
||||||
DeleteJoinWrapper<UserDO> wrapper = JoinWrappers.delete(UserDO.class)
|
|
||||||
.deleteAll()
|
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
|
||||||
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
|
||||||
.eq(OrderDO::getId, 1);
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
DeleteJoinWrapper<UserDO> wrapper1 = new DeleteJoinWrapper<>(UserDO.class);
|
|
||||||
int i = userMapper.deleteJoin(wrapper);
|
|
||||||
});
|
|
||||||
//忽略异常 h2不支持连表删除
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void update() {
|
|
||||||
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.update_by=?, t.`name`=?,t1.address=?,t1.tel=?,t1.address=?,t.`name`=?,t.update_by=?,t1.user_id=?,t1.area_id=?,t1.tel=?,t1.address=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
|
|
||||||
UpdateJoinWrapper<UserDO> update = JoinWrappers.update(UserDO.class)
|
|
||||||
.set(UserDO::getName, "aaaaaa")
|
|
||||||
.set(AddressDO::getAddress, "bbbbb")
|
|
||||||
.setUpdateEntity(new AddressDO().setAddress("sadf").setTel("qqqqqqqq"),
|
|
||||||
new UserDO().setName("nnnnnnnnnnnn").setUpdateBy(1))
|
|
||||||
.setUpdateEntityAndNull(new AddressDO())
|
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
|
||||||
.eq(OrderDO::getId, 1);
|
|
||||||
System.out.println(update.getSqlSet());
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
int i = userMapper.updateJoin(new UserDO().setUpdateBy(123123), update);
|
|
||||||
});
|
|
||||||
//忽略异常 h2不支持连表删除
|
|
||||||
|
|
||||||
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, " +
|
|
||||||
"t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, " +
|
|
||||||
"t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
|
|
||||||
|
|
||||||
UpdateJoinWrapper<UserDO> up = JoinWrappers.update(UserDO.class)
|
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
|
||||||
.eq(OrderDO::getId, 1);
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
int i = userMapper.updateJoinAndNull(new UserDO(), up);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* select 子查询
|
* select 子查询
|
||||||
*/
|
*/
|
||||||
|
@ -8,9 +8,9 @@ import com.github.yulichang.test.join.entity.UserDO;
|
|||||||
import com.github.yulichang.test.join.entity.UserTenantDO;
|
import com.github.yulichang.test.join.entity.UserTenantDO;
|
||||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||||
import com.github.yulichang.test.join.mapper.UserTenantMapper;
|
import com.github.yulichang.test.join.mapper.UserTenantMapper;
|
||||||
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
import com.github.yulichang.test.util.Throw;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import com.github.yulichang.toolkit.JoinWrappers;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@ -27,26 +27,9 @@ class QueryWrapperTest {
|
|||||||
private UserTenantMapper userTenantMapper;
|
private UserTenantMapper userTenantMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
@BeforeEach
|
||||||
* 链表查询
|
void setUp() {
|
||||||
*/
|
Reset.reset();
|
||||||
@Test
|
|
||||||
void test1() {
|
|
||||||
UserDTO dto = userMapper.selectJoinOne(UserDTO.class, new MPJQueryWrapper<UserDO>()
|
|
||||||
.selectAll(UserDO.class)
|
|
||||||
.select("name AS nameName")
|
|
||||||
.last("LIMIT 1"));
|
|
||||||
System.out.println(dto);
|
|
||||||
|
|
||||||
|
|
||||||
IPage<UserDTO> iPage1 = userTenantMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class,
|
|
||||||
JoinWrappers.query(UserTenantDO.class)
|
|
||||||
.selectAll(UserTenantDO.class)
|
|
||||||
.select("t1.name as PName")
|
|
||||||
.leftJoin("(select * from `user` where id <> -1) t1 on t1.id = t.user_id")
|
|
||||||
.apply("t.id <> -1"));
|
|
||||||
|
|
||||||
iPage1.getRecords().forEach(System.out::println);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,17 +37,16 @@ class QueryWrapperTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void table() {
|
void table() {
|
||||||
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,name AS nameName FROM fwear t WHERE t.del=false LIMIT 1",
|
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||||
"SELECT t.id,t.pid,t.`name`,t.`json`,t.sex,t.head_img AS img,t.create_time,t.address_id,t.address_id2,t.del,t.create_by,t.update_by,name AS nameName FROM fwear t WHERE t.del=false LIMIT 1");
|
"t.address_id2, t.del, t.create_by, t.update_by, `name` AS nameName FROM (SELECT * FROM `user`) t " +
|
||||||
|
"WHERE t.del = false AND t.id = 1");
|
||||||
MPJQueryWrapper<UserDO> wrapper = new MPJQueryWrapper<UserDO>()
|
MPJQueryWrapper<UserDO> wrapper = new MPJQueryWrapper<UserDO>()
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.setTableName(name -> "fwear")
|
.setTableName(name -> String.format("(select * from %s)", name))
|
||||||
.select("name AS nameName")
|
.select("`name` AS nameName")
|
||||||
.last("LIMIT 1");
|
.last("AND t.id = 1");
|
||||||
|
|
||||||
Throw.tryDoIgnore(() -> {
|
|
||||||
userMapper.selectJoinOne(UserDTO.class, wrapper);
|
userMapper.selectJoinOne(UserDTO.class, wrapper);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连表删除没有同意语法语法,不同数据库差别较大
|
||||||
|
* MPJ 连表更新 目前只支持 mysql
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||||
|
public class DeleteJoinTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
Reset.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同一个类字段比较
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void delete() {
|
||||||
|
//物理删除
|
||||||
|
ThreadLocalUtils.set("DELETE t FROM order_t t LEFT JOIN user_dto t1 ON (t1.id = t.user_id) WHERE (t.id = ?)");
|
||||||
|
DeleteJoinWrapper<OrderDO> w = JoinWrappers.delete(OrderDO.class)
|
||||||
|
.leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId)
|
||||||
|
.eq(OrderDO::getId, 1);
|
||||||
|
|
||||||
|
orderMapper.deleteJoin(w);
|
||||||
|
|
||||||
|
//逻辑删除
|
||||||
|
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)");
|
||||||
|
DeleteJoinWrapper<UserDO> wrapper = JoinWrappers.delete(UserDO.class)
|
||||||
|
.deleteAll()
|
||||||
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||||
|
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
|
||||||
|
.eq(OrderDO::getId, 1);
|
||||||
|
userMapper.deleteJoin(wrapper);
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,26 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.mysql;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
import com.github.yulichang.test.util.Throw;
|
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.github.yulichang.wrapper.segments.Fun;
|
import com.github.yulichang.wrapper.segments.Fun;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 由于不同数据库函数支持情况不同
|
||||||
|
* 此类用于测试 mysql 专属语法或函数
|
||||||
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class FuncAliasTest {
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||||
|
public class MysqlTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
@ -24,6 +29,19 @@ public class FuncAliasTest {
|
|||||||
Reset.reset();
|
Reset.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函数测试
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testFunc() {
|
||||||
|
ThreadLocalUtils.set("SELECT if(t1.user_id < 5,t1.user_id,t1.user_id + 100) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del=false AND t1.del=false");
|
||||||
|
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
||||||
|
.selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId)
|
||||||
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId);
|
||||||
|
userMapper.selectJoinList(UserDO.class, wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void funcAlias() {
|
void funcAlias() {
|
||||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||||
@ -43,8 +61,7 @@ public class FuncAliasTest {
|
|||||||
.leftJoin(AddressDO.class, "addr", AddressDO::getUserId, UserDO::getId)
|
.leftJoin(AddressDO.class, "addr", AddressDO::getUserId, UserDO::getId)
|
||||||
.groupBy(UserDO::getId);
|
.groupBy(UserDO::getId);
|
||||||
|
|
||||||
Throw.tryDo(() -> {
|
|
||||||
userMapper.selectJoinList(UserDO.class, wrapper);
|
userMapper.selectJoinList(UserDO.class, wrapper);
|
||||||
}, DbType.POSTGRE_SQL, DbType.ORACLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,25 +1,31 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.mysql;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
||||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
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.entity.UserDO;
|
||||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
import com.github.yulichang.test.util.Throw;
|
|
||||||
import com.github.yulichang.toolkit.JoinWrappers;
|
import com.github.yulichang.toolkit.JoinWrappers;
|
||||||
import com.github.yulichang.wrapper.UpdateJoinWrapper;
|
import com.github.yulichang.wrapper.UpdateJoinWrapper;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连表更新没有同意语法语法,不同数据库差别较大
|
||||||
|
* MPJ 连表更新 目前只支持 mysql
|
||||||
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class UpdateIncTest {
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql")
|
||||||
|
public class UpdateJoinTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
@ -29,7 +35,6 @@ public class UpdateIncTest {
|
|||||||
Reset.reset();
|
Reset.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateInc() {
|
void updateInc() {
|
||||||
ThreadLocalUtils.set("UPDATE `user` t SET t.id = t.id + 100 WHERE t.del = false");
|
ThreadLocalUtils.set("UPDATE `user` t SET t.id = t.id + 100 WHERE t.del = false");
|
||||||
@ -47,10 +52,8 @@ public class UpdateIncTest {
|
|||||||
@Test
|
@Test
|
||||||
void updateInc1() {
|
void updateInc1() {
|
||||||
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t1.address = t.head_img WHERE t.del = false AND t1.del = false");
|
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t1.address = t.head_img WHERE t.del = false AND t1.del = false");
|
||||||
Throw.tryDo(() -> {
|
|
||||||
JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg)
|
JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg)
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update();
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update();
|
||||||
});
|
|
||||||
JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println);
|
JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,4 +81,28 @@ public class UpdateIncTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void update() {
|
||||||
|
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.update_by=?, t.`name`=?,t1.address=?,t1.tel=?,t1.address=?,t.`name`=?,t.update_by=?,t1.user_id=?,t1.area_id=?,t1.tel=?,t1.address=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
|
||||||
|
UpdateJoinWrapper<UserDO> update = JoinWrappers.update(UserDO.class)
|
||||||
|
.set(UserDO::getName, "aaaaaa")
|
||||||
|
.set(AddressDO::getAddress, "bbbbb")
|
||||||
|
.setUpdateEntity(new AddressDO().setAddress("sadf").setTel("qqqqqqqq"),
|
||||||
|
new UserDO().setName("nnnnnnnnnnnn").setUpdateBy(1))
|
||||||
|
.setUpdateEntityAndNull(new AddressDO())
|
||||||
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||||
|
.eq(OrderDO::getId, 1);
|
||||||
|
System.out.println(update.getSqlSet());
|
||||||
|
userMapper.updateJoin(new UserDO().setUpdateBy(123123), update);
|
||||||
|
|
||||||
|
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, " +
|
||||||
|
"t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, " +
|
||||||
|
"t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
|
||||||
|
|
||||||
|
UpdateJoinWrapper<UserDO> up = JoinWrappers.update(UserDO.class)
|
||||||
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
||||||
|
.eq(OrderDO::getId, 1);
|
||||||
|
userMapper.updateJoinAndNull(new UserDO(), up);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.UserTenantaDO;
|
import com.github.yulichang.test.join.entity.UserTenantaDO;
|
||||||
import com.github.yulichang.toolkit.JoinWrappers;
|
import com.github.yulichang.toolkit.JoinWrappers;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
@ -20,12 +20,12 @@ public class EqSqlTest {
|
|||||||
@Test
|
@Test
|
||||||
void eqSql() {
|
void eqSql() {
|
||||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
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` LIMIT 1))");
|
"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))");
|
||||||
JoinWrappers.lambda(UserDO.class).eqSql(UserDO::getId, "select id from `user` limit 1").list();
|
JoinWrappers.lambda(UserDO.class).eqSql(UserDO::getId, "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, " +
|
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` LIMIT 1))");
|
"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))");
|
||||||
JoinWrappers.lambda(UserDO.class).eqSql("t.id", "select id from `user` limit 1").list();
|
JoinWrappers.lambda(UserDO.class).eqSql("t.id", "select id from `user` where id = 1").list();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.dto.AreaDTO;
|
import com.github.yulichang.test.join.dto.AreaDTO;
|
||||||
import com.github.yulichang.test.join.entity.AreaDO;
|
import com.github.yulichang.test.join.entity.AreaDO;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.config.enums.IfExistsEnum;
|
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
@ -69,12 +69,11 @@ public class IfExistsTest {
|
|||||||
|
|
||||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
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 " +
|
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t " +
|
||||||
"WHERE t.del = false AND (t.id = ? AND t.pid = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)");
|
"WHERE t.del = false AND (t.id = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||||
MPJLambdaWrapper<UserDO> wrapper2 = JoinWrappers.lambda(UserDO.class)
|
MPJLambdaWrapper<UserDO> wrapper2 = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.setIfExists(o -> true)
|
.setIfExists(o -> true)
|
||||||
.eqIfExists(UserDO::getId, 1)
|
.eqIfExists(UserDO::getId, 1)
|
||||||
.eqIfExists(UserDO::getPid, null)
|
|
||||||
.eqIfExists(UserDO::getName, "")
|
.eqIfExists(UserDO::getName, "")
|
||||||
.eqIfExists(UserDO::getImg, "\t")
|
.eqIfExists(UserDO::getImg, "\t")
|
||||||
.eqIfExists(UserDO::getName, "张三 1");
|
.eqIfExists(UserDO::getName, "张三 1");
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.test.join.dto.UserDTO;
|
import com.github.yulichang.test.join.dto.UserDTO;
|
||||||
@ -10,12 +10,14 @@ import com.github.yulichang.toolkit.JoinWrappers;
|
|||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||||
public class OrderByTest {
|
public class OrderByTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
import com.github.yulichang.test.join.entity.AreaDO;
|
import com.github.yulichang.test.join.entity.AreaDO;
|
||||||
@ -9,9 +9,11 @@ import com.github.yulichang.toolkit.JoinWrappers;
|
|||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||||
public class SelectSubTest {
|
public class SelectSubTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.dto.UserDTO;
|
import com.github.yulichang.test.join.dto.UserDTO;
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
@ -32,7 +32,7 @@ public class StringColumTest {
|
|||||||
void stringColum() {
|
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`," +
|
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, " +
|
" (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 LIMIT 1");
|
"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");
|
||||||
List<UserDTO> l3 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>()
|
List<UserDTO> l3 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper<UserDO>()
|
||||||
.select("(select id from `user` u where u.id = t.id) id")
|
.select("(select id from `user` u where u.id = t.id) id")
|
||||||
.select("t.`name` as PName")
|
.select("t.`name` as PName")
|
||||||
@ -40,8 +40,7 @@ public class StringColumTest {
|
|||||||
.select("t.`name`")
|
.select("t.`name`")
|
||||||
.select("(select id from `user` u where u.id = t.id) ")
|
.select("(select id from `user` u where u.id = t.id) ")
|
||||||
.selectAssociation(AddressDO.class, UserDTO::getAddressDTO)
|
.selectAssociation(AddressDO.class, UserDTO::getAddressDTO)
|
||||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
|
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||||
.last("limit 1"));
|
|
||||||
assert l3.get(0).getPName() != null;
|
assert l3.get(0).getPName() != null;
|
||||||
l3.forEach(System.out::println);
|
l3.forEach(System.out::println);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
import com.github.yulichang.test.join.entity.AreaDO;
|
import com.github.yulichang.test.join.entity.AreaDO;
|
||||||
@ -10,12 +10,14 @@ import com.github.yulichang.toolkit.JoinWrappers;
|
|||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle")
|
||||||
public class TableAliasTest {
|
public class TableAliasTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
import com.github.yulichang.test.join.entity.AddressDO;
|
import com.github.yulichang.test.join.entity.AddressDO;
|
||||||
import com.github.yulichang.test.join.entity.AreaDO;
|
import com.github.yulichang.test.join.entity.AreaDO;
|
Loading…
x
Reference in New Issue
Block a user