com.github.yulichang.wrapper.interfaces.Chain Maven / Gradle / Ivy
Show all versions of mybatis-plus-join-core Show documentation
package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.SqlHelper;
import java.util.List;
/**
* 链式调用
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*
* @author yulichang
* @since 1.4.4
*/
@SuppressWarnings({"unchecked", "unused"})
public interface Chain {
Class getEntityClass();
/**
* 链式调用 等效于MP mapper的 selectCount()
*
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default Long count() {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper) mapper).selectJoinCount((MPJBaseJoin) this);
});
}
/**
* 链式调用 等效于 selectOne
*
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default T one() {
return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectOne((Wrapper) this));
}
/**
* 链式调用 等效于 selectJoinOne
*
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default R one(Class resultType) {
return SqlHelper.execJoin(getEntityClass(), mapper -> mapper.selectJoinOne(resultType, (MPJBaseJoin) this));
}
/**
* 链式调用 查询列表第一个 匹配多个不会抛异常
*
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default T first() {
List list = list();
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
/**
* 链式调用 查询列表第一个 匹配多个不会抛异常
*
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default R first(Class resultType) {
List list = list(resultType);
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
/**
* 链式调用
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default List list() {
return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectList((Wrapper) this));
}
/**
* 链式调用
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default List list(Class resultType) {
return SqlHelper.execJoin(getEntityClass(), mapper -> mapper.selectJoinList(resultType, (MPJBaseJoin) this));
}
/**
* 链式调用
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default > P page(P page) {
return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectPage(page, (Wrapper) this));
}
/**
* 链式调用
* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* new MPJQueryWrapper(User.class)
* JoinWrappers.\lambdaJoin(User.class)
* JoinWrappers.\queryJoin(User.class)
*/
default > P page(P page, Class resultType) {
return SqlHelper.execJoin(getEntityClass(), mapper -> mapper.selectJoinPage(page, resultType, (MPJBaseJoin) this));
}
}