1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.global_variables_defaults;
17
18 import java.lang.reflect.Field;
19 import java.util.Properties;
20
21 import org.apache.ibatis.cache.Cache;
22 import org.apache.ibatis.cache.impl.PerpetualCache;
23 import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
24
25 public class SupportClasses {
26
27 public static class CustomObjectFactory extends DefaultObjectFactory {
28 private static final long serialVersionUID = 4576592418878031661L;
29 private Properties properties;
30
31 @Override
32 public void setProperties(Properties properties) {
33 this.properties = properties;
34 }
35
36 public Properties getProperties() {
37 return properties;
38 }
39 }
40
41 public static class CustomCache extends PerpetualCache {
42 private String name;
43
44 public CustomCache(String id) {
45 super(id);
46 }
47
48 public String getName() {
49 return name;
50 }
51
52 public void setName(String name) {
53 this.name = name;
54 }
55 }
56
57 static class Utils {
58 static SupportClasses.CustomCache unwrap(Cache cache) {
59 Field field;
60 try {
61 field = cache.getClass().getDeclaredField("delegate");
62 } catch (NoSuchFieldException e) {
63 throw new IllegalStateException(e);
64 }
65 try {
66 field.setAccessible(true);
67 return (SupportClasses.CustomCache) field.get(cache);
68 } catch (IllegalAccessException e) {
69 throw new IllegalStateException(e);
70 } finally {
71 field.setAccessible(false);
72 }
73 }
74
75 private Utils() {
76 }
77 }
78
79 }