Mercurial > dive4elements > gnv-client
annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/cache/CacheCleaner.java @ 1120:d387a97807a3
Added an INFO log statement displaying the execution time of a database query.
geo-backend/trunk@1137 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 31 May 2010 07:23:21 +0000 |
parents | 02cd2935b5fa |
children | ebeb56428409 |
rev | line source |
---|---|
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.geobackend.base.query.cache; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
6 import java.sql.Date; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 import java.util.Collection; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
8 import java.util.Iterator; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.gnv.geobackend.base.Result; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.gnv.geobackend.base.query.DefaultQueryExceutor; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.gnv.geobackend.util.DateUtils; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 * Thread that looks every n - Minutes if an Cache has to be cleanedup. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 * You can configure the Timeout in Seconds using the Systemproperty |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 * |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 public class CacheCleaner extends Thread { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 * the logger, used to log exceptions and additonaly information |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 private static Logger log = Logger.getLogger(CacheCleaner.class); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 * The Systemproperty-identifier for the Configuration of the TimeInterval |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 public static final String CACHE_CLEANER_INTERVAL = "caching.cleaner.interval"; |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
36 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 * The Time To wait between two Cleanups. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
39 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 private long timeout = 1000 * 60; // 1 Minute |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
41 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 * The Border which has to be used to Query the updated Tables. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 private long lowerBorderTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 * The Id to Lookup the SQL-Statement for fetchung the Names of the |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 * updated Tables. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 private String queryID = "updated_tables"; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 public CacheCleaner() { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 public CacheCleaner(Runnable arg0) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 super(arg0); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
71 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 public CacheCleaner(String arg0) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
74 super(arg0); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
77 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
78 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
79 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
82 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
83 public CacheCleaner(ThreadGroup arg0, Runnable arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
85 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
86 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
87 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
91 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 public CacheCleaner(ThreadGroup arg0, String arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
94 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
95 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
97 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
98 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
99 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
100 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
101 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
103 public CacheCleaner(Runnable arg0, String arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
105 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
106 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
107 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
108 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
109 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
110 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
111 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
112 * @param arg2 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
113 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
114 public CacheCleaner(ThreadGroup arg0, Runnable arg1, String arg2) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
115 super(arg0, arg1, arg2); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
116 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
117 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
118 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
119 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
120 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
121 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
122 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
123 * @param arg2 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
124 * @param arg3 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
125 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
126 public CacheCleaner(ThreadGroup arg0, Runnable arg1, String arg2, long arg3) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
127 super(arg0, arg1, arg2, arg3); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
128 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
129 } |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
130 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
131 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
132 * Sets up the members of the CacheCleaner. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
133 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
134 protected void setUp(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
135 String intervalValue = System.getProperty(CACHE_CLEANER_INTERVAL); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
136 if (intervalValue != null){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
137 log.info("Set Interval to "+intervalValue+" Seconds"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
138 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
139 this.timeout = Long.parseLong(intervalValue) * 1000; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
140 } catch (NumberFormatException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
141 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
142 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
143 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
144 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
145 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
146 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
147 * This Method can be used do run the Main-Mechanism of the Thread e.g |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
148 * from a Unittest. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
149 * @return |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
150 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
151 public boolean test(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
152 log.debug("CacheCleaner.test"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
153 this.cleanup(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
154 return true; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
155 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
156 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
157 @Override |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
158 public void run() { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
159 log.debug("CacheCleaner.run"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
160 long requiredTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
161 this.lowerBorderTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
162 while (true){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
163 long startTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
164 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
165 long nextTimeout = timeout-requiredTime; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
166 if (nextTimeout > 0){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
167 Thread.sleep(nextTimeout); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
168 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
169 startTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
170 log.debug("Sleep "+nextTimeout+"ms cleanup Cache now"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
171 this.cleanup(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
172 } catch (InterruptedException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
173 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
174 } catch (Exception e){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
175 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
176 } catch (Throwable t){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
177 log.error(t,t); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
178 }finally{ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
179 requiredTime = System.currentTimeMillis() - startTime; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
180 log.debug("CleanUp required "+requiredTime); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
181 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
182 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
183 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
184 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
185 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
186 * Method that do the Cleanup-Work |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
187 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
188 protected void cleanup(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
189 log.debug("CacheCleaner.cleanup"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
190 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
191 // We have to go this Way to avoid using the Cache for this Query. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
192 String[] tableNames = this.getUpdatedTableNames(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
193 if (tableNames != null){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
194 QueryExecutorFactory.getInstance() |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
195 .getQueryExecutor().clearCache(tableNames); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
196 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
197 } catch (QueryException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
198 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
199 } |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
200 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
201 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
202 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
203 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
204 * Returns the Names of the Tables which have been updated. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
205 * @return the Names of the Tables which have been updated. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
206 * @throws QueryException |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
207 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
208 protected String[] getUpdatedTableNames()throws QueryException { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
209 String[] tableNames = null; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
210 QueryExecutor queryExecutor = new DefaultQueryExceutor(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
211 Date date = new Date(this.lowerBorderTime); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
212 this.lowerBorderTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
213 log.debug("New Lookup at "+DateUtils.getPatternedDateAmer(new Date(lowerBorderTime))); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
214 String queryDate = DateUtils.getPatternedDateAmer(date); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
215 Collection<Result> result = queryExecutor. |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
216 executeQuery(queryID, |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
217 new String[]{queryDate}); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
218 if (result != null && !result.isEmpty()){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
219 tableNames = new String[result.size()]; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
220 Iterator<Result> it = result.iterator(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
221 int i = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
222 while (it.hasNext()){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
223 tableNames[i++] = it.next().getString(0).toUpperCase(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
224 log.debug("Table that was updated: "+tableNames[i-1]); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
225 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
226 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
227 return tableNames; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
228 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
229 } |