update和delete添加链式调用

This commit is contained in:
yulichang 2024-01-17 16:48:51 +08:00
parent fde21a04dd
commit 34e4acdc6a
4 changed files with 118 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import com.github.yulichang.toolkit.Asserts;
import com.github.yulichang.toolkit.LogicInfoUtils;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.TableList;
import com.github.yulichang.wrapper.interfaces.DeleteChain;
import java.util.ArrayList;
import java.util.Arrays;
@ -21,7 +22,7 @@ import java.util.stream.Collectors;
* @author yulichang
* @since 1.4.5
*/
public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoinWrapper<T>> {
public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoinWrapper<T>> implements DeleteChain<T> {
/**
* 删除表

View File

@ -12,6 +12,7 @@ import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.TableList;
import com.github.yulichang.wrapper.interfaces.Update;
import com.github.yulichang.wrapper.interfaces.UpdateChain;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -29,7 +30,7 @@ import java.util.stream.Collectors;
*/
@SuppressWarnings("unused")
public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoinWrapper<T>>
implements Update<UpdateJoinWrapper<T>> {
implements Update<UpdateJoinWrapper<T>>, UpdateChain<T> {
/**
* SQL 更新字段内容例如name='1', age=2
*/

View File

@ -0,0 +1,36 @@
package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.SqlHelper;
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错<br />
* new DeleteJoinWrapper(User.class)<br />
* JoinWrappers.delete(User.class)<br />
*
* @author yulichang
* @since 1.4.10
*/
public interface DeleteChain<T> {
Class<T> getEntityClass();
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错 <br />
* new DeleteJoinWrapper(User.class)<br />
* JoinWrappers.delete(User.class)<br />
*/
@SuppressWarnings({"unused", "unchecked"})
default int deleteJoin() {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper<T>) mapper).deleteJoin((MPJBaseJoin<T>) this);
});
}
}

View File

@ -0,0 +1,78 @@
package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.SqlHelper;
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错<br />
* new UpdateJoinWrapper(User.class)<br />
* JoinWrappers.update(User.class)<br />
*
* @author yulichang
* @since 1.4.10
*/
@SuppressWarnings({"unchecked", "unused"})
public interface UpdateChain<T> {
Class<T> getEntityClass();
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错 <br />
* new UpdateJoinWrapper(User.class)<br />
* JoinWrappers.update(User.class)<br />
*/
default int update() {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper<T>) mapper).updateJoin(null, (MPJBaseJoin<T>) this);
});
}
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错 <br />
* new UpdateJoinWrapper(User.class)<br />
* JoinWrappers.update(User.class)<br />
*/
default int update(T entity) {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper<T>) mapper).updateJoin(entity, (MPJBaseJoin<T>) this);
});
}
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错 <br />
* new UpdateJoinWrapper(User.class)<br />
* JoinWrappers.update(User.class)<br />
*/
default int updateAndNull() {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper<T>) mapper).updateJoinAndNull(null, (MPJBaseJoin<T>) this);
});
}
/**
* 链式调用
* <p>
* 构造方法必须传 class entity 否则会报错 <br />
* new UpdateJoinWrapper(User.class)<br />
* JoinWrappers.update(User.class)<br />
*/
default int updateAndNull(T entity) {
return SqlHelper.exec(getEntityClass(), mapper -> {
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
return ((MPJBaseMapper<T>) mapper).updateJoinAndNull(entity, (MPJBaseJoin<T>) this);
});
}
}