1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.cache;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.ibatis.cache.decorators.TransactionalCache;
22
23
24
25
26 public class TransactionalCacheManager {
27
28 private final Map<Cache, TransactionalCache> transactionalCaches = new HashMap<>();
29
30 public void clear(Cache cache) {
31 getTransactionalCache(cache).clear();
32 }
33
34 public Object getObject(Cache cache, CacheKey key) {
35 return getTransactionalCache(cache).getObject(key);
36 }
37
38 public void putObject(Cache cache, CacheKey key, Object value) {
39 getTransactionalCache(cache).putObject(key, value);
40 }
41
42 public void commit() {
43 for (TransactionalCache txCache : transactionalCaches.values()) {
44 txCache.commit();
45 }
46 }
47
48 public void rollback() {
49 for (TransactionalCache txCache : transactionalCaches.values()) {
50 txCache.rollback();
51 }
52 }
53
54 private TransactionalCache getTransactionalCache(Cache cache) {
55 return transactionalCaches.computeIfAbsent(cache, TransactionalCache::new);
56 }
57
58 }