|
@@ -1,6 +1,5 @@
|
|
package com.baomidou.mybatisplus.test.h2.cache.service.impl;
|
|
package com.baomidou.mybatisplus.test.h2.cache.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.test.h2.cache.mapper.CacheMapper;
|
|
import com.baomidou.mybatisplus.test.h2.cache.mapper.CacheMapper;
|
|
import com.baomidou.mybatisplus.test.h2.cache.model.CacheModel;
|
|
import com.baomidou.mybatisplus.test.h2.cache.model.CacheModel;
|
|
@@ -8,18 +7,11 @@ import com.baomidou.mybatisplus.test.h2.cache.service.ICacheService;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> implements ICacheService {
|
|
public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> implements ICacheService {
|
|
|
|
|
|
- //手动撸一个批量删除.
|
|
|
|
- private void removeBatchById(Collection<Long> idList) {
|
|
|
|
- String sqlStatement = sqlStatement(SqlMethod.DELETE_BY_ID);
|
|
|
|
- executeBatch(idList, (sqlSession, id) -> sqlSession.delete(sqlStatement, id));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public long testBatchTransactionalClear1() {
|
|
public long testBatchTransactionalClear1() {
|
|
@@ -66,7 +58,7 @@ public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> imple
|
|
public long testBatchTransactionalClear5() {
|
|
public long testBatchTransactionalClear5() {
|
|
CacheModel model = new CacheModel("靓仔");
|
|
CacheModel model = new CacheModel("靓仔");
|
|
save(model);
|
|
save(model);
|
|
- removeBatchById(Collections.singletonList(model.getId()));
|
|
|
|
|
|
+ removeBatchByIds(Collections.singletonList(model.getId()));
|
|
removeById(model.getId());
|
|
removeById(model.getId());
|
|
return model.getId();
|
|
return model.getId();
|
|
}
|
|
}
|
|
@@ -76,7 +68,7 @@ public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> imple
|
|
public long testBatchTransactionalClear6() {
|
|
public long testBatchTransactionalClear6() {
|
|
CacheModel model = new CacheModel("靓仔");
|
|
CacheModel model = new CacheModel("靓仔");
|
|
save(model);
|
|
save(model);
|
|
- removeBatchById(Collections.singletonList(model.getId()));
|
|
|
|
|
|
+ removeBatchByIds(Collections.singletonList(model.getId()));
|
|
return model.getId();
|
|
return model.getId();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,7 +78,7 @@ public class CacheServiceImpl extends ServiceImpl<CacheMapper, CacheModel> imple
|
|
CacheModel model = new CacheModel("靓仔");
|
|
CacheModel model = new CacheModel("靓仔");
|
|
save(model);
|
|
save(model);
|
|
updateBatchById(Collections.singletonList(new CacheModel(model.getId(), "旺仔")));
|
|
updateBatchById(Collections.singletonList(new CacheModel(model.getId(), "旺仔")));
|
|
- removeBatchById(Collections.singletonList(model.getId()));
|
|
|
|
|
|
+ removeBatchByIds(Collections.singletonList(model.getId()));
|
|
return model.getId();
|
|
return model.getId();
|
|
}
|
|
}
|
|
}
|
|
}
|