Bladeren bron

暂时不修改方法名,清理removeByIds代码.

nieqiurong 1 jaar geleden
bovenliggende
commit
4b9a42bc8a

+ 2 - 16
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -174,23 +174,9 @@ public interface BaseMapper<T> extends Mapper<T> {
      * 删除(根据ID或实体 批量删除)
      *
      * @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) {
-        return deleteByIds(idList, true);
+        return deleteBatchIds(idList, true);
     }
 
     /**
@@ -200,7 +186,7 @@ public interface BaseMapper<T> extends Mapper<T> {
      * @param useFill     逻辑删除下是否填充
      * @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);
         Class<?> entityClass = GenericTypeUtils.resolveTypeArguments(getClass(), BaseMapper.class)[0];
         SqlSession sqlSession = mybatisMapperProxy.getSqlSession();

+ 4 - 11
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/IService.java

@@ -155,7 +155,7 @@ public interface IService<T> {
         if (CollectionUtils.isEmpty(list)) {
             return false;
         }
-        return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
+        return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
     }
 
     /**
@@ -166,15 +166,11 @@ public interface IService<T> {
      * @return 删除结果
      * @since 3.5.0
      */
-    @Transactional(rollbackFor = Exception.class)
     default boolean removeByIds(Collection<?> list, boolean useFill) {
         if (CollectionUtils.isEmpty(list)) {
             return false;
         }
-        if (useFill) {
-            return removeBatchByIds(list, true);
-        }
-        return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
+        return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
     }
 
     /**
@@ -197,7 +193,6 @@ public interface IService<T> {
      * @return 删除结果
      * @since 3.5.0
      */
-    @Transactional(rollbackFor = Exception.class)
     default boolean removeBatchByIds(Collection<?> list, boolean useFill) {
         return removeBatchByIds(list, DEFAULT_BATCH_SIZE, useFill);
     }
@@ -208,9 +203,8 @@ public interface IService<T> {
      * @param list      主键ID或实体列表
      * @param batchSize 批次大小
      * @return 删除结果
-     * @see #removeBatchByIds(Collection, boolean)
      * @since 3.5.0
-     * @deprecated 3.5.7
+     * @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
      */
     @Deprecated
     default boolean removeBatchByIds(Collection<?> list, int batchSize) {
@@ -224,9 +218,8 @@ public interface IService<T> {
      * @param batchSize 批次大小
      * @param useFill   是否启用填充(为true的情况,会将入参转换实体进行delete删除)
      * @return 删除结果
-     * @see #removeBatchByIds(Collection, boolean)
      * @since 3.5.0
-     * @deprecated 3.5.7
+     * @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
      */
     @Deprecated
     default boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {

+ 4 - 29
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

@@ -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) {
         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
     public boolean removeById(Serializable id, boolean useFill) {
-        TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
-        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));
+        return SqlHelper.retBool(getBaseMapper().deleteById(id, useFill));
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public boolean removeBatchByIds(Collection<?> list, int batchSize) {
-        return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
+        return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
-        return SqlHelper.retBool(getBaseMapper().deleteByIds(list, useFill));
+        return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
     }
 
 }

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserMapperTest.java

@@ -315,14 +315,14 @@ class H2UserMapperTest extends BaseTest {
 
     @Test
     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");
         userMapper.insert(h2User);
-        userMapper.deleteByIds(List.of(h2User));
+        userMapper.deleteBatchIds(List.of(h2User));
         Assertions.assertNotNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
         h2User = new H2User("testRemoveByIds");
         userMapper.insert(h2User);
-        userMapper.deleteByIds(List.of(h2User), false);
+        userMapper.deleteBatchIds(List.of(h2User), false);
         Assertions.assertNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
     }