1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection;
17
18 import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.ConcurrentMap;
20
21 import org.apache.ibatis.util.MapUtil;
22
23 public class DefaultReflectorFactory implements ReflectorFactory {
24 private boolean classCacheEnabled = true;
25 private final ConcurrentMap<Class<?>, Reflector> reflectorMap = new ConcurrentHashMap<>();
26
27 public DefaultReflectorFactory() {
28 }
29
30 @Override
31 public boolean isClassCacheEnabled() {
32 return classCacheEnabled;
33 }
34
35 @Override
36 public void setClassCacheEnabled(boolean classCacheEnabled) {
37 this.classCacheEnabled = classCacheEnabled;
38 }
39
40 @Override
41 public Reflector findForClass(Class<?> type) {
42 if (classCacheEnabled) {
43
44 return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new);
45 }
46 return new Reflector(type);
47 }
48
49 }