|
@@ -15,21 +15,19 @@
|
|
|
*/
|
|
|
package com.baomidou.mybatisplus.test.h2.service.impl;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
|
|
|
import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
|
import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* Service层测试
|
|
@@ -41,12 +39,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
@Service
|
|
|
public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> implements IH2UserService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private H2UserMapper userMapper;
|
|
|
-
|
|
|
@Override
|
|
|
public int myInsert(String name, int version) {
|
|
|
- return userMapper.myInsertWithNameVersion(name, version);
|
|
|
+ return baseMapper.myInsertWithNameVersion(name, version);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -54,7 +49,7 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
|
|
|
H2User user = new H2User();
|
|
|
user.setName(name);
|
|
|
user.setVersion(version);
|
|
|
- return userMapper.myInsertWithParam(user);
|
|
|
+ return baseMapper.myInsertWithParam(user);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -62,17 +57,17 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
|
|
|
H2User user = new H2User();
|
|
|
user.setName(name);
|
|
|
user.setVersion(version);
|
|
|
- return userMapper.myInsertWithoutParam(user);
|
|
|
+ return baseMapper.myInsertWithoutParam(user);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int myUpdate(Long id, String name) {
|
|
|
- return userMapper.myUpdateWithNameId(id, name);
|
|
|
+ return baseMapper.myUpdateWithNameId(id, name);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<H2User> queryWithParamInSelectStatememt(Map<String, Object> param) {
|
|
|
- return userMapper.selectUserWithParamInSelectStatememt(param);
|
|
|
+ return baseMapper.selectUserWithParamInSelectStatememt(param);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -84,45 +79,45 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
|
|
|
|
|
|
@Override
|
|
|
public int selectCountWithParamInSelectItems(Map<String, Object> param) {
|
|
|
- return userMapper.selectCountWithParamInSelectItems(param);
|
|
|
+ return baseMapper.selectCountWithParamInSelectItems(param);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Map> mySelectMaps() {
|
|
|
- return userMapper.mySelectMaps();
|
|
|
+ return baseMapper.mySelectMaps();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void testBatchTransactional() {
|
|
|
- saveBatch(Arrays.asList(new H2User("batch1",0),new H2User("batch2",0),new H2User("batch3",0)));
|
|
|
- saveBatch(Arrays.asList(new H2User("batch4",0),new H2User("batch5",0),new H2User("batch6",0)));
|
|
|
+ saveBatch(Arrays.asList(new H2User("batch1", 0), new H2User("batch2", 0), new H2User("batch3", 0)));
|
|
|
+ saveBatch(Arrays.asList(new H2User("batch4", 0), new H2User("batch5", 0), new H2User("batch6", 0)));
|
|
|
throw new MybatisPlusException("测试批量插入事务回滚");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void testSimpleTransactional() {
|
|
|
- save(new H2User("simple1",0));
|
|
|
- save(new H2User("simple2",0));
|
|
|
+ save(new H2User("simple1", 0));
|
|
|
+ save(new H2User("simple2", 0));
|
|
|
throw new MybatisPlusException("测试普通插入事务回滚");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void testSaveOrUpdateBatchTransactional() {
|
|
|
- saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate1",0),new H2User("savOrUpdate2",0),new H2User("savOrUpdate3",0)),1);
|
|
|
- saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate4",0),new H2User("savOrUpdate5",0),new H2User("savOrUpdate6",0)),1);
|
|
|
+ saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate1", 0), new H2User("savOrUpdate2", 0), new H2User("savOrUpdate3", 0)), 1);
|
|
|
+ saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate4", 0), new H2User("savOrUpdate5", 0), new H2User("savOrUpdate6", 0)), 1);
|
|
|
throw new MybatisPlusException("测试普通插入事务回滚");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void testSimpleAndBatchTransactional() {
|
|
|
- save(new H2User("simpleAndBatchTx1",0));
|
|
|
- saveBatch(Arrays.asList(new H2User("simpleAndBatchTx2",0),new H2User("simpleAndBatchTx3",0),new H2User("simpleAndBatchTx4",0)),1);
|
|
|
- saveOrUpdateBatch(Arrays.asList(new H2User("simpleAndBatchTx5",0),new H2User("simpleAndBatchTx6",0),new H2User("simpleAndBatchTx7",0)),1);
|
|
|
+ save(new H2User("simpleAndBatchTx1", 0));
|
|
|
+ saveBatch(Arrays.asList(new H2User("simpleAndBatchTx2", 0), new H2User("simpleAndBatchTx3", 0), new H2User("simpleAndBatchTx4", 0)), 1);
|
|
|
+ saveOrUpdateBatch(Arrays.asList(new H2User("simpleAndBatchTx5", 0), new H2User("simpleAndBatchTx6", 0), new H2User("simpleAndBatchTx7", 0)), 1);
|
|
|
throw new MybatisPlusException("测试事务回滚");
|
|
|
}
|
|
|
}
|