|
@@ -19,12 +19,15 @@ import java.util.List;
|
19
|
19
|
|
20
|
20
|
public class Test3 {
|
21
|
21
|
UserMapper userMapper;
|
|
22
|
+ UserMapper userMapper2;
|
22
|
23
|
SqlSession sqlSession;
|
|
24
|
+ SqlSession sqlSession2;
|
23
|
25
|
@Before
|
24
|
26
|
public void before() throws IOException {
|
25
|
27
|
InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
|
26
|
28
|
SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
|
27
|
29
|
sqlSession = build.openSession(true);
|
|
30
|
+ sqlSession2 = build.openSession(true);
|
28
|
31
|
userMapper = sqlSession.getMapper(UserMapper.class);
|
29
|
32
|
}
|
30
|
33
|
@Test
|
|
@@ -43,6 +46,35 @@ public class Test3 {
|
43
|
46
|
// integers.add(2);
|
44
|
47
|
List<UserEntity> userForEach = userMapper.findUserForEach(integers);
|
45
|
48
|
}
|
|
49
|
+
|
|
50
|
+ /**
|
|
51
|
+ * 测试一级缓存
|
|
52
|
+ */
|
|
53
|
+ @Test
|
|
54
|
+ public void testCache() {
|
|
55
|
+ userMapper2 = sqlSession.getMapper(UserMapper.class);
|
|
56
|
+ ArrayList<Integer> integers = new ArrayList<>();
|
|
57
|
+// integers.add(1);
|
|
58
|
+// integers.add(2);
|
|
59
|
+ List<UserEntity> userForEach1 = userMapper.findUserForEach(integers);
|
|
60
|
+ List<UserEntity> userForEach2 = userMapper2.findUserForEach(integers);
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ /**
|
|
64
|
+ * 二级缓存 sqlSessionFactory级别
|
|
65
|
+ */
|
|
66
|
+ @Test
|
|
67
|
+ public void testTwoCache() {
|
|
68
|
+ ArrayList<Integer> integers = new ArrayList<>();
|
|
69
|
+ UserMapper mapper1 = sqlSession.getMapper(UserMapper.class);
|
|
70
|
+ UserMapper mapper2 = sqlSession2.getMapper(UserMapper.class);
|
|
71
|
+ List<UserEntity> userForEach1 = mapper1.findUserForEach(integers);
|
|
72
|
+ sqlSession.close();
|
|
73
|
+ List<UserEntity> userForEach2 = mapper2.findUserForEach(integers);
|
|
74
|
+ sqlSession2.close();
|
|
75
|
+
|
|
76
|
+ }
|
|
77
|
+
|
46
|
78
|
@Test
|
47
|
79
|
public void delete() {
|
48
|
80
|
userMapper.deleteOne(2);
|