暂时不修改方法名,清理removeByIds代码.
This commit is contained in:
parent
f16da35bf6
commit
4b9a42bc8a
@ -174,23 +174,9 @@ public interface BaseMapper<T> extends Mapper<T> {
|
|||||||
* 删除(根据ID或实体 批量删除)
|
* 删除(根据ID或实体 批量删除)
|
||||||
*
|
*
|
||||||
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
|
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
|
||||||
* @since 3.5.7
|
|
||||||
*/
|
*/
|
||||||
default int deleteByIds(@Param(Constants.COLL) Collection<?> idList) {
|
|
||||||
return deleteByIds(idList, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除(根据ID或实体 批量删除)
|
|
||||||
*
|
|
||||||
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
|
|
||||||
* @see #deleteByIds(Collection)
|
|
||||||
* @deprecated 3.5.7
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList) {
|
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList) {
|
||||||
return deleteByIds(idList, true);
|
return deleteBatchIds(idList, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,7 +186,7 @@ public interface BaseMapper<T> extends Mapper<T> {
|
|||||||
* @param useFill 逻辑删除下是否填充
|
* @param useFill 逻辑删除下是否填充
|
||||||
* @since 3.5.7
|
* @since 3.5.7
|
||||||
*/
|
*/
|
||||||
default int deleteByIds(@Param(Constants.COLL) Collection<?> collections, boolean useFill) {
|
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> collections, boolean useFill) {
|
||||||
MybatisMapperProxy<?> mybatisMapperProxy = (MybatisMapperProxy<?>) Proxy.getInvocationHandler(this);
|
MybatisMapperProxy<?> mybatisMapperProxy = (MybatisMapperProxy<?>) Proxy.getInvocationHandler(this);
|
||||||
Class<?> entityClass = GenericTypeUtils.resolveTypeArguments(getClass(), BaseMapper.class)[0];
|
Class<?> entityClass = GenericTypeUtils.resolveTypeArguments(getClass(), BaseMapper.class)[0];
|
||||||
SqlSession sqlSession = mybatisMapperProxy.getSqlSession();
|
SqlSession sqlSession = mybatisMapperProxy.getSqlSession();
|
||||||
|
@ -155,7 +155,7 @@ public interface IService<T> {
|
|||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
|
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,15 +166,11 @@ public interface IService<T> {
|
|||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
default boolean removeByIds(Collection<?> list, boolean useFill) {
|
default boolean removeByIds(Collection<?> list, boolean useFill) {
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (useFill) {
|
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
|
||||||
return removeBatchByIds(list, true);
|
|
||||||
}
|
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,7 +193,6 @@ public interface IService<T> {
|
|||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
default boolean removeBatchByIds(Collection<?> list, boolean useFill) {
|
default boolean removeBatchByIds(Collection<?> list, boolean useFill) {
|
||||||
return removeBatchByIds(list, DEFAULT_BATCH_SIZE, useFill);
|
return removeBatchByIds(list, DEFAULT_BATCH_SIZE, useFill);
|
||||||
}
|
}
|
||||||
@ -208,9 +203,8 @@ public interface IService<T> {
|
|||||||
* @param list 主键ID或实体列表
|
* @param list 主键ID或实体列表
|
||||||
* @param batchSize 批次大小
|
* @param batchSize 批次大小
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
* @see #removeBatchByIds(Collection, boolean)
|
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
* @deprecated 3.5.7
|
* @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
default boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
default boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
||||||
@ -224,9 +218,8 @@ public interface IService<T> {
|
|||||||
* @param batchSize 批次大小
|
* @param batchSize 批次大小
|
||||||
* @param useFill 是否启用填充(为true的情况,会将入参转换实体进行delete删除)
|
* @param useFill 是否启用填充(为true的情况,会将入参转换实体进行delete删除)
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
* @see #removeBatchByIds(Collection, boolean)
|
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
* @deprecated 3.5.7
|
* @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
default boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
default boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
||||||
|
@ -295,45 +295,20 @@ public abstract class ServiceImpl<M extends BaseMapper<T>, T> implements IServic
|
|||||||
protected <E> boolean executeBatch(Collection<E> list, BiConsumer<SqlSession, E> consumer) {
|
protected <E> boolean executeBatch(Collection<E> list, BiConsumer<SqlSession, E> consumer) {
|
||||||
return executeBatch(list, DEFAULT_BATCH_SIZE, consumer);
|
return executeBatch(list, DEFAULT_BATCH_SIZE, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean removeById(Serializable id) {
|
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean removeByIds(Collection<?> list) {
|
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeById(Serializable id, boolean useFill) {
|
public boolean removeById(Serializable id, boolean useFill) {
|
||||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
|
return SqlHelper.retBool(getBaseMapper().deleteById(id, useFill));
|
||||||
if (useFill && tableInfo.isWithLogicDelete()) {
|
|
||||||
if (!entityClass.isAssignableFrom(id.getClass())) {
|
|
||||||
T instance = tableInfo.newInstance();
|
|
||||||
Object value = tableInfo.getKeyType() != id.getClass() ? conversionService.convert(id, tableInfo.getKeyType()) : id;
|
|
||||||
tableInfo.setPropertyValue(instance, tableInfo.getKeyProperty(), value);
|
|
||||||
return removeById(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteById(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
public boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
|
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
||||||
return SqlHelper.retBool(getBaseMapper().deleteByIds(list, useFill));
|
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -315,14 +315,14 @@ class H2UserMapperTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRemoveByIds() {
|
void testRemoveByIds() {
|
||||||
Assertions.assertEquals(userMapper.deleteByIds(List.of(666666661, "2")), userMapper.deleteByIds(List.of(666666661, "2"), false));
|
Assertions.assertEquals(userMapper.deleteBatchIds(List.of(666666661, "2")), userMapper.deleteBatchIds(List.of(666666661, "2"), false));
|
||||||
H2User h2User = new H2User("testRemoveByIds");
|
H2User h2User = new H2User("testRemoveByIds");
|
||||||
userMapper.insert(h2User);
|
userMapper.insert(h2User);
|
||||||
userMapper.deleteByIds(List.of(h2User));
|
userMapper.deleteBatchIds(List.of(h2User));
|
||||||
Assertions.assertNotNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
|
Assertions.assertNotNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
|
||||||
h2User = new H2User("testRemoveByIds");
|
h2User = new H2User("testRemoveByIds");
|
||||||
userMapper.insert(h2User);
|
userMapper.insert(h2User);
|
||||||
userMapper.deleteByIds(List.of(h2User), false);
|
userMapper.deleteBatchIds(List.of(h2User), false);
|
||||||
Assertions.assertNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
|
Assertions.assertNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user