1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.event;
25
26 import org.dbforms.config.DbFormsConfig;
27 import org.dbforms.config.Field;
28 import org.dbforms.config.FieldValue;
29 import org.dbforms.config.FieldValues;
30 import org.dbforms.config.MultipleValidationException;
31 import org.dbforms.config.Table;
32 import org.dbforms.config.ValidationException;
33 import org.dbforms.interfaces.DbEventInterceptorData;
34 import org.dbforms.interfaces.IDbEventInterceptor;
35
36 import java.sql.Connection;
37
38 import java.util.Map;
39
40 import javax.servlet.http.HttpServletRequest;
41
42
43
44 /***
45 * convenience class
46 *
47 * @author Joe Peer
48 */
49 public class DbEventInterceptorSupport implements IDbEventInterceptor {
50 private Map params;
51
52
53
54
55 public void setParameterMap(Map params) {
56 this.params = params;
57 }
58
59
60
61
62
63 public Map getParameterMap() {
64 return params;
65 }
66
67
68
69
70 public String getParameter(String key) {
71 return (String)params.get(key);
72 }
73
74
75
76
77
78 public void postAddRow(DbEventInterceptorData data) {
79 }
80
81
82
83
84
85 public void postDelete(DbEventInterceptorData data) {
86 postDelete(data.getRequest(), data.getConfig(), data.getConnection());
87 }
88
89
90 /***
91 * DOCUMENT ME!
92 *
93 * @param request DOCUMENT ME!
94 * @param config DOCUMENT ME!
95 * @param con DOCUMENT ME!
96 *
97 * @deprecated
98 */
99 public void postDelete(HttpServletRequest request,
100 DbFormsConfig config,
101 Connection con) {
102 }
103
104
105
106
107
108 public void postInsert(DbEventInterceptorData data) {
109 postInsert(data.getRequest(), data.getConfig(), data.getConnection());
110 }
111
112
113 /***
114 * DOCUMENT ME!
115 *
116 * @param request DOCUMENT ME!
117 * @param config DOCUMENT ME!
118 * @param con DOCUMENT ME!
119 *
120 * @deprecated
121 */
122 public void postInsert(HttpServletRequest request,
123 DbFormsConfig config,
124 Connection con) {
125 }
126
127
128
129
130
131 public void postSelect(DbEventInterceptorData data) {
132 postSelect(data.getRequest(), data.getConfig(), data.getConnection());
133 }
134
135
136 /***
137 * DOCUMENT ME!
138 *
139 * @param request DOCUMENT ME!
140 * @param config DOCUMENT ME!
141 * @param con DOCUMENT ME!
142 *
143 * @deprecated
144 */
145 public void postSelect(HttpServletRequest request,
146 DbFormsConfig config,
147 Connection con) {
148 }
149
150
151
152
153
154 public void postUpdate(DbEventInterceptorData data) {
155 postUpdate(data.getRequest(), data.getConfig(), data.getConnection());
156 }
157
158
159 /***
160 * DOCUMENT ME!
161 *
162 * @param request DOCUMENT ME!
163 * @param config DOCUMENT ME!
164 * @param con DOCUMENT ME!
165 *
166 * @deprecated
167 */
168 public void postUpdate(HttpServletRequest request,
169 DbFormsConfig config,
170 Connection con) {
171 }
172
173
174
175
176
177 public int preAddRow(DbEventInterceptorData data)
178 throws ValidationException, MultipleValidationException {
179 return GRANT_OPERATION;
180 }
181
182
183
184
185
186 public int preDelete(DbEventInterceptorData data)
187 throws ValidationException, MultipleValidationException {
188 return preDelete(data.getRequest(), data.getTable(),
189 (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
190 data.getConfig(), data.getConnection());
191 }
192
193
194 /***
195 * DOCUMENT ME!
196 *
197 * @param request DOCUMENT ME!
198 * @param table DOCUMENT ME!
199 * @param fieldValues DOCUMENT ME!
200 * @param config DOCUMENT ME!
201 * @param con DOCUMENT ME!
202 *
203 * @return DOCUMENT ME!
204 *
205 * @throws ValidationException DOCUMENT ME!
206 *
207 * @deprecated
208 */
209 public int preDelete(HttpServletRequest request,
210 Table table,
211 FieldValues fieldValues,
212 DbFormsConfig config,
213 Connection con) throws ValidationException {
214 return GRANT_OPERATION;
215 }
216
217
218
219
220
221 public int preInsert(DbEventInterceptorData data)
222 throws ValidationException, MultipleValidationException {
223 return preInsert(data.getRequest(), data.getTable(),
224 (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
225 data.getConfig(), data.getConnection());
226 }
227
228
229 /***
230 * DOCUMENT ME!
231 *
232 * @param request DOCUMENT ME!
233 * @param table DOCUMENT ME!
234 * @param fieldValues DOCUMENT ME!
235 * @param config DOCUMENT ME!
236 * @param con DOCUMENT ME!
237 *
238 * @return DOCUMENT ME!
239 *
240 * @throws ValidationException DOCUMENT ME!
241 *
242 * @deprecated
243 */
244 public int preInsert(HttpServletRequest request,
245 Table table,
246 FieldValues fieldValues,
247 DbFormsConfig config,
248 Connection con) throws ValidationException {
249 return GRANT_OPERATION;
250 }
251
252
253
254
255
256 public int preSelect(DbEventInterceptorData data)
257 throws ValidationException, MultipleValidationException {
258 return preSelect(data.getRequest(), data.getConfig(), data.getConnection());
259 }
260
261
262 /***
263 * DOCUMENT ME!
264 *
265 * @param request DOCUMENT ME!
266 * @param config DOCUMENT ME!
267 * @param con DOCUMENT ME!
268 *
269 * @return DOCUMENT ME!
270 *
271 * @throws ValidationException DOCUMENT ME!
272 *
273 * @deprecated
274 */
275 public int preSelect(HttpServletRequest request,
276 DbFormsConfig config,
277 Connection con) throws ValidationException {
278 return GRANT_OPERATION;
279 }
280
281
282
283
284
285 public int preUpdate(DbEventInterceptorData data)
286 throws ValidationException, MultipleValidationException {
287 return preUpdate(data.getRequest(), data.getTable(),
288 (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
289 data.getConfig(), data.getConnection());
290 }
291
292
293 /***
294 * DOCUMENT ME!
295 *
296 * @param request DOCUMENT ME!
297 * @param table DOCUMENT ME!
298 * @param fieldValues DOCUMENT ME!
299 * @param config DOCUMENT ME!
300 * @param con DOCUMENT ME!
301 *
302 * @return DOCUMENT ME!
303 *
304 * @throws ValidationException DOCUMENT ME!
305 *
306 * @deprecated
307 */
308 public int preUpdate(HttpServletRequest request,
309 Table table,
310 FieldValues fieldValues,
311 DbFormsConfig config,
312 Connection con) throws ValidationException {
313 return GRANT_OPERATION;
314 }
315
316
317 /***
318 * adds or replace a value in the fieldValues
319 *
320 * @param table wich should be used to lookup for the fieldName
321 * @param fieldValues to add/replace value to
322 * @param fieldName to add/replace value
323 * @param value to add/replace
324 */
325 protected void setValue(Table table,
326 FieldValues fieldValues,
327 String fieldName,
328 String value) {
329 FieldValue fv = fieldValues.get(fieldName);
330 Field f = table.getFieldByName(fieldName);
331
332 if (f != null) {
333 if (fv == null) {
334 fv = new FieldValue(f, value);
335 fieldValues.put(fv);
336 } else {
337 fv.setFieldValue(value);
338 }
339 }
340 }
341 }