1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ibatis.sqlmap.engine.config;
17
18 import com.ibatis.sqlmap.engine.cache.CacheController;
19 import com.ibatis.sqlmap.engine.cache.CacheModel;
20 import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
21 import com.ibatis.sqlmap.engine.scope.ErrorContext;
22
23 import java.util.Properties;
24
25
26
27
28 public class CacheModelConfig {
29
30
31 private ErrorContext errorContext;
32
33
34 private CacheModel cacheModel;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 CacheModelConfig(SqlMapConfiguration config, String id, CacheController controller, boolean readOnly,
51 boolean serialize) {
52 this.errorContext = config.getErrorContext();
53 this.cacheModel = new CacheModel();
54 SqlMapClientImpl client = config.getClient();
55 errorContext.setActivity("building a cache model");
56 cacheModel.setReadOnly(readOnly);
57 cacheModel.setSerialize(serialize);
58 errorContext.setObjectId(id + " cache model");
59 errorContext.setMoreInfo("Check the cache model type.");
60 cacheModel.setId(id);
61 cacheModel.setResource(errorContext.getResource());
62 try {
63 cacheModel.setCacheController(controller);
64 } catch (Exception e) {
65 throw new RuntimeException("Error setting Cache Controller Class. Cause: " + e, e);
66 }
67 errorContext.setMoreInfo("Check the cache model configuration.");
68 if (client.getDelegate().isCacheModelsEnabled()) {
69 client.getDelegate().addCacheModel(cacheModel);
70 }
71 errorContext.setMoreInfo(null);
72 errorContext.setObjectId(null);
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public void setFlushInterval(long hours, long minutes, long seconds, long milliseconds) {
88 errorContext.setMoreInfo("Check the cache model flush interval.");
89 long t = 0L;
90 t += milliseconds;
91 t += seconds * 1000L;
92 t += minutes * 60L * 1000L;
93 t += hours * 60L * 60L * 1000L;
94 if (t < 1L)
95 throw new RuntimeException(
96 "A flush interval must specify one or more of milliseconds, seconds, minutes or hours.");
97 cacheModel.setFlushInterval(t);
98 }
99
100
101
102
103
104
105
106 public void addFlushTriggerStatement(String statement) {
107 errorContext.setMoreInfo("Check the cache model flush on statement elements.");
108 cacheModel.addFlushTriggerStatement(statement);
109 }
110
111
112
113
114
115
116 public CacheModel getCacheModel() {
117 return cacheModel;
118 }
119
120
121
122
123
124
125
126 public void setControllerProperties(Properties cacheProps) {
127 cacheModel.setControllerProperties(cacheProps);
128 }
129 }