瀏覽代碼

移除批量操作自定义条件处理.

1.与UpdateWrapper<Entity>().lambda().set()可能存在冲突
2.更新set字段包含where字段
nieqiuqiu 4 年之前
父節點
當前提交
6580edf667

+ 0 - 48
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/IService.java

@@ -37,7 +37,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Objects;
 import java.util.function.Function;
 import java.util.function.Function;
-import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
@@ -98,34 +97,6 @@ public interface IService<T> {
      */
      */
     boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);
     boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);
     
     
-    /**
-     * 批量更新或新增
-     *
-     * @param list      数据集合
-     * @param batchSize 批量大小
-     * @param predicate 新增条件 notNull
-     * @param function  更新条件 notNull
-     * @return 操作结果
-     * @since 3.3.3
-     */
-    default boolean saveOrUpdateBatch(Collection<T> list, int batchSize, Predicate<T> predicate, Function<T, Wrapper<T>> function) {
-        throw new UnsupportedOperationException();
-    }
-    
-    /**
-     * 批量更新或新增
-     *
-     * @param list      数据集合
-     * @param predicate 新增条件 notNull
-     * @param function  更新条件 notNull
-     * @return 操作结果
-     * @since 3.3.3
-     */
-    @Transactional(rollbackFor = Exception.class)
-    default boolean saveOrUpdateBatch(Collection<T> list, Predicate<T> predicate, Function<T, Wrapper<T>> function) {
-        return saveOrUpdateBatch(list, DEFAULT_BATCH_SIZE, predicate, function);
-    }
-
     /**
     /**
      * 根据 ID 删除
      * 根据 ID 删除
      *
      *
@@ -219,25 +190,6 @@ public interface IService<T> {
      */
      */
     boolean saveOrUpdate(T entity);
     boolean saveOrUpdate(T entity);
     
     
-    /**
-     * 更新或保存
-     *
-     * @param entity    实体
-     * @param predicate 新增条件 notNull
-     * @param function  更新条件 notNull
-     * @return 操作结果
-     * @since 3.3.3
-     */
-    @Transactional(rollbackFor = Exception.class)
-    default boolean saveOrUpdate(T entity, Predicate<T> predicate, Function<T, Wrapper<T>> function) {
-        if (predicate.test(entity)) {
-            return save(entity);
-        } else {
-            Wrapper<T> wrapper = function.apply(entity);
-            return update(entity, wrapper);
-        }
-    }
-
     /**
     /**
      * 根据 ID 查询
      * 根据 ID 查询
      *
      *

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

@@ -38,7 +38,6 @@ import java.util.Objects;
 import java.util.function.BiConsumer;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Function;
-import java.util.function.Predicate;
 
 
 /**
 /**
  * IService 实现类( 泛型:M 是 mapper 对象,T 是实体 )
  * IService 实现类( 泛型:M 是 mapper 对象,T 是实体 )
@@ -227,18 +226,4 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         return executeBatch(list, DEFAULT_BATCH_SIZE, consumer);
         return executeBatch(list, DEFAULT_BATCH_SIZE, consumer);
     }
     }
     
     
-    @Transactional(rollbackFor = Exception.class)
-    @Override
-    public boolean saveOrUpdateBatch(Collection<T> list, int batchSize, Predicate<T> predicate, Function<T, Wrapper<T>> function) {
-        TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
-        return SqlHelper.saveOrUpdateBatch(this.entityClass, this.log, list, batchSize, predicate, ((sqlSession, entity) -> {
-            String sqlStatement = tableInfo.getSqlStatement(SqlMethod.UPDATE.getMethod());
-            MapperMethod.ParamMap<Object> param = new MapperMethod.ParamMap<>();
-            Wrapper<T> wrapper = function.apply(entity);
-            param.put(Constants.ENTITY, entity);
-            param.put(Constants.WRAPPER, wrapper);
-            sqlSession.update(sqlStatement, param);
-        }));
-    }
-    
 }
 }

+ 4 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/CacheTest.java

@@ -211,10 +211,10 @@ class CacheTest {
         Assertions.assertEquals(cache.getSize(), 2);
         Assertions.assertEquals(cache.getSize(), 2);
     }
     }
 
 
-    @Test
-    void testCustomSaveOrUpdateBatch(){
-        Assertions.assertTrue(cacheService.testCustomSaveOrUpdateBatch());
-    }
+//    @Test
+//    void testCustomSaveOrUpdateBatch(){
+//        Assertions.assertTrue(cacheService.testCustomSaveOrUpdateBatch());
+//    }
     
     
     private Cache getCache() {
     private Cache getCache() {
         return sqlSessionFactory.getConfiguration().getCache(CacheMapper.class.getName());
         return sqlSessionFactory.getConfiguration().getCache(CacheMapper.class.getName());

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/service/ICacheService.java

@@ -19,5 +19,5 @@ public interface ICacheService extends IService<CacheModel> {
 
 
     long testBatchTransactionalClear7();
     long testBatchTransactionalClear7();
 
 
-    boolean testCustomSaveOrUpdateBatch();
+//    boolean testCustomSaveOrUpdateBatch();
 }
 }

+ 9 - 9
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/service/impl/CacheServiceImpl.java

@@ -22,15 +22,15 @@ public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> imple
         executeBatch(idList, (sqlSession, id) -> sqlSession.delete(sqlStatement, id));
         executeBatch(idList, (sqlSession, id) -> sqlSession.delete(sqlStatement, id));
     }
     }
 
 
-    @Override
-    @Transactional
-    public boolean testCustomSaveOrUpdateBatch() {
-        CacheModel model1 = new CacheModel();
-        CacheModel model2 = new CacheModel("旺仔");
-        //name为空写入,不为空按条件更新
-        boolean result = saveOrUpdateBatch(Arrays.asList(model1, model2), entity -> entity.getName() == null, (entity) -> new QueryWrapper<CacheModel>().lambda().eq(CacheModel::getName, entity.getName()));
-        return model1.getId() != null && model2.getId() == null && result;
-    }
+//    @Override
+//    @Transactional
+//    public boolean testCustomSaveOrUpdateBatch() {
+//        CacheModel model1 = new CacheModel();
+//        CacheModel model2 = new CacheModel("旺仔");
+//        //name为空写入,不为空按条件更新
+//        boolean result = saveOrUpdateBatch(Arrays.asList(model1, model2), entity -> entity.getName() == null, (entity) -> new QueryWrapper<CacheModel>().lambda().eq(CacheModel::getName, entity.getName()));
+//        return model1.getId() != null && model2.getId() == null && result;
+//    }
 
 
     @Override
     @Override
     @Transactional
     @Transactional