|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| package org.objectledge.parameters.db; |
|
30 |
| |
|
31 |
| import java.sql.Connection; |
|
32 |
| import java.sql.PreparedStatement; |
|
33 |
| import java.sql.SQLException; |
|
34 |
| import java.util.ArrayList; |
|
35 |
| import java.util.Arrays; |
|
36 |
| import java.util.Collections; |
|
37 |
| import java.util.Date; |
|
38 |
| import java.util.HashSet; |
|
39 |
| import java.util.Iterator; |
|
40 |
| import java.util.List; |
|
41 |
| import java.util.Set; |
|
42 |
| |
|
43 |
| import org.jcontainer.dna.Logger; |
|
44 |
| import org.objectledge.database.Database; |
|
45 |
| import org.objectledge.database.DatabaseUtils; |
|
46 |
| import org.objectledge.parameters.DefaultParameters; |
|
47 |
| import org.objectledge.parameters.Parameters; |
|
48 |
| import org.objectledge.parameters.ScopedParameters; |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class DBParameters implements Parameters |
|
57 |
| { |
|
58 |
| |
|
59 |
| private Logger logger; |
|
60 |
| |
|
61 |
| |
|
62 |
| private Database database; |
|
63 |
| |
|
64 |
| |
|
65 |
| private long id; |
|
66 |
| |
|
67 |
| |
|
68 |
| private DefaultParameters container; |
|
69 |
| |
|
70 |
| |
|
71 |
| private DefaultParameters shadow; |
|
72 |
| |
|
73 |
| |
|
74 |
| private HashSet<String> modified; |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
2346
| public DBParameters(Parameters parameters, long id, Database database, Logger logger)
|
|
85 |
| { |
|
86 |
2346
| modified = new HashSet<String>();
|
|
87 |
2346
| this.logger = logger;
|
|
88 |
2346
| this.database = database;
|
|
89 |
2346
| if(parameters != null)
|
|
90 |
| { |
|
91 |
46
| container = new DefaultParameters(parameters);
|
|
92 |
46
| shadow = new DefaultParameters(parameters);
|
|
93 |
| } |
|
94 |
| else |
|
95 |
| { |
|
96 |
2300
| container = new DefaultParameters();
|
|
97 |
2300
| shadow = new DefaultParameters();
|
|
98 |
| } |
|
99 |
2346
| this.id = id;
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
276
| public String get(String name)
|
|
106 |
| { |
|
107 |
276
| return container.get(name);
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
230
| public String get(String name, String defaultValue)
|
|
114 |
| { |
|
115 |
230
| return container.get(name, defaultValue);
|
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
322
| public String[] getStrings(String name)
|
|
122 |
| { |
|
123 |
322
| return container.getStrings(name); }
|
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
184
| public boolean getBoolean(String name)
|
|
129 |
| { |
|
130 |
184
| return container.getBoolean(name);
|
|
131 |
| } |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
276
| public boolean getBoolean(String name, boolean defaultValue)
|
|
137 |
| { |
|
138 |
276
| return container.getBoolean(name, defaultValue);
|
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
322
| public boolean[] getBooleans(String name)
|
|
145 |
| { |
|
146 |
322
| return container.getBooleans(name);
|
|
147 |
| } |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
184
| public Date getDate(String name)
|
|
154 |
| { |
|
155 |
184
| return container.getDate(name);
|
|
156 |
| } |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
92
| public Date getDate(String name, Date defaultValue)
|
|
162 |
| { |
|
163 |
92
| return container.getDate(name, defaultValue);
|
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
184
| public Date[] getDates(String name)
|
|
170 |
| { |
|
171 |
184
| return container.getDates(name);
|
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
184
| public float getFloat(String name) throws NumberFormatException
|
|
178 |
| { |
|
179 |
184
| return container.getFloat(name);
|
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
322
| public float getFloat(String name, float defaultValue)
|
|
186 |
| { |
|
187 |
322
| return container.getFloat(name, defaultValue);
|
|
188 |
| } |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
230
| public float[] getFloats(String name) throws NumberFormatException
|
|
194 |
| { |
|
195 |
230
| return container.getFloats(name);
|
|
196 |
| } |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
184
| public int getInt(String name) throws NumberFormatException
|
|
202 |
| { |
|
203 |
184
| return container.getInt(name);
|
|
204 |
| |
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
184
| public int getInt(String name, int defaultValue)
|
|
211 |
| { |
|
212 |
184
| return container.getInt(name, defaultValue);
|
|
213 |
| } |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
368
| public int[] getInts(String name)
|
|
219 |
| { |
|
220 |
368
| return container.getInts(name);
|
|
221 |
| } |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
184
| public long getLong(String name) throws NumberFormatException
|
|
227 |
| { |
|
228 |
184
| return container.getLong(name);
|
|
229 |
| } |
|
230 |
| |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
184
| public long getLong(String name, long defaultValue)
|
|
235 |
| { |
|
236 |
184
| return container.getLong(name,defaultValue);
|
|
237 |
| } |
|
238 |
| |
|
239 |
| |
|
240 |
| |
|
241 |
| |
|
242 |
184
| public long[] getLongs(String name) throws NumberFormatException
|
|
243 |
| { |
|
244 |
184
| return container.getLongs(name);
|
|
245 |
| } |
|
246 |
| |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
552
| public String[] getParameterNames()
|
|
251 |
| { |
|
252 |
552
| return container.getParameterNames();
|
|
253 |
| } |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
598
| public boolean isDefined(String name)
|
|
259 |
| { |
|
260 |
598
| return container.isDefined(name);
|
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
46
| public void remove()
|
|
267 |
| { |
|
268 |
46
| container.remove();
|
|
269 |
46
| List<String> all = Arrays.asList(container.getParameterNames());
|
|
270 |
46
| modified.addAll(all);
|
|
271 |
46
| update();
|
|
272 |
| } |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
46
| public void remove(String name)
|
|
278 |
| { |
|
279 |
46
| container.remove(name);
|
|
280 |
46
| modified.add(name);
|
|
281 |
46
| update();
|
|
282 |
| } |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
92
| public void remove(String name, String value)
|
|
288 |
| { |
|
289 |
92
| container.remove(name,value);
|
|
290 |
92
| modified.add(name);
|
|
291 |
92
| update();
|
|
292 |
| } |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
0
| public void remove(String name, Date value)
|
|
298 |
| { |
|
299 |
0
| container.remove(name,value);
|
|
300 |
0
| modified.add(name);
|
|
301 |
0
| update();
|
|
302 |
| } |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
46
| public void remove(String name, float value)
|
|
308 |
| { |
|
309 |
46
| container.remove(name,value);
|
|
310 |
46
| modified.add(name);
|
|
311 |
46
| update();
|
|
312 |
| } |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
46
| public void remove(String name, int value)
|
|
318 |
| { |
|
319 |
46
| container.remove(name,value);
|
|
320 |
46
| modified.add(name);
|
|
321 |
46
| update();
|
|
322 |
| } |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
46
| public void remove(String name, long value)
|
|
328 |
| { |
|
329 |
46
| container.remove(name,value);
|
|
330 |
46
| modified.add(name);
|
|
331 |
46
| update();
|
|
332 |
| } |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
46
| public void remove(Set<String> keys)
|
|
340 |
| { |
|
341 |
46
| container.remove(keys);
|
|
342 |
46
| modified.addAll(keys);
|
|
343 |
46
| update();
|
|
344 |
| } |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
| |
|
351 |
46
| public void removeExcept(Set<String> keys)
|
|
352 |
| { |
|
353 |
46
| container.removeExcept(keys);
|
|
354 |
46
| List<String> all = new ArrayList<String>(Arrays.asList(container.getParameterNames()));
|
|
355 |
46
| all.removeAll(keys);
|
|
356 |
46
| modified.addAll(all);
|
|
357 |
46
| update();
|
|
358 |
| } |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
1012
| public void set(String name, String value)
|
|
364 |
| { |
|
365 |
1012
| container.set(name, value);
|
|
366 |
1012
| modified.add(name);
|
|
367 |
1012
| update();
|
|
368 |
| } |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
46
| public void set(String name, String[] values)
|
|
374 |
| { |
|
375 |
46
| container.set(name, values);
|
|
376 |
46
| modified.add(name);
|
|
377 |
46
| update();
|
|
378 |
| } |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
0
| public void set(String name, Date value)
|
|
384 |
| { |
|
385 |
0
| container.set(name, value);
|
|
386 |
0
| modified.add(name);
|
|
387 |
0
| update();
|
|
388 |
| } |
|
389 |
| |
|
390 |
| |
|
391 |
| |
|
392 |
| |
|
393 |
0
| public void set(String name, Date[] values)
|
|
394 |
| { |
|
395 |
0
| container.set(name, values);
|
|
396 |
0
| modified.add(name);
|
|
397 |
0
| update();
|
|
398 |
| } |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
138
| public void set(String name, boolean value)
|
|
404 |
| { |
|
405 |
138
| container.set(name, value);
|
|
406 |
138
| modified.add(name);
|
|
407 |
138
| update();
|
|
408 |
| } |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
46
| public void set(String name, boolean[] values)
|
|
414 |
| { |
|
415 |
46
| container.set(name, values);
|
|
416 |
46
| modified.add(name);
|
|
417 |
46
| update();
|
|
418 |
| } |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
138
| public void set(String name, float value)
|
|
424 |
| { |
|
425 |
138
| container.set(name, value);
|
|
426 |
138
| modified.add(name);
|
|
427 |
138
| update();
|
|
428 |
| } |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
46
| public void set(String name, float[] values)
|
|
434 |
| { |
|
435 |
46
| container.set(name, values);
|
|
436 |
46
| modified.add(name);
|
|
437 |
46
| update();
|
|
438 |
| } |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
138
| public void set(String name, int value)
|
|
444 |
| { |
|
445 |
138
| container.set(name, value);
|
|
446 |
138
| modified.add(name);
|
|
447 |
138
| update();
|
|
448 |
| } |
|
449 |
| |
|
450 |
| |
|
451 |
| |
|
452 |
| |
|
453 |
46
| public void set(String name, int[] values)
|
|
454 |
| { |
|
455 |
46
| container.set(name, values);
|
|
456 |
46
| modified.add(name);
|
|
457 |
46
| update();
|
|
458 |
| } |
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
138
| public void set(String name, long value)
|
|
464 |
| { |
|
465 |
138
| container.set(name, value);
|
|
466 |
138
| modified.add(name);
|
|
467 |
138
| update();
|
|
468 |
| } |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
46
| public void set(String name, long[] values)
|
|
474 |
| { |
|
475 |
46
| container.set(name, values);
|
|
476 |
46
| modified.add(name);
|
|
477 |
46
| update();
|
|
478 |
| } |
|
479 |
| |
|
480 |
| |
|
481 |
| |
|
482 |
| |
|
483 |
0
| public void set(Parameters parameters)
|
|
484 |
| { |
|
485 |
0
| String[] names = container.getParameterNames();
|
|
486 |
0
| for(String name:names)
|
|
487 |
| { |
|
488 |
0
| modified.add(name);
|
|
489 |
| } |
|
490 |
0
| container.set(parameters);
|
|
491 |
0
| names = parameters.getParameterNames();
|
|
492 |
0
| for(String name:names)
|
|
493 |
| { |
|
494 |
0
| modified.add(name);
|
|
495 |
| } |
|
496 |
0
| update();
|
|
497 |
| } |
|
498 |
| |
|
499 |
| |