1
2 package hoplugins.teamAnalyzer.dao;
3
4 import hoplugins.Commons;
5
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8
9
10 /***
11 * DB Access Manager for Configuration
12 *
13 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
14 */
15 public class PluginConfiguration {
16
17
18 private static boolean isNumericRating;
19 private static boolean isLineup;
20 private static boolean tacticDetail;
21 private static boolean isDescriptionRating;
22 private static boolean isShowUnavailable;
23 private static boolean isMixedLineup;
24 private static boolean isStars;
25 private static boolean isTotalStrength;
26 private static boolean isSquad;
27 private static boolean isSmartSquad;
28 private static boolean isLoddarStats;
29 private static boolean isShowPlayerInfo;
30 private static boolean isCheckTeamName;
31
32
33
34 /***
35 * Creates a new PluginConfiguration object.
36 */
37 public PluginConfiguration() {
38 checkTable();
39
40 isNumericRating = getValue("numericRating", false);
41 isDescriptionRating = getValue("descriptionRating", true);
42 isLineup = getValue("lineupCompare", true);
43 isMixedLineup = getValue("mixedLineup", false);
44 tacticDetail = getValue("tacticDetail", false);
45 isStars = getValue("isStars", true);
46 isTotalStrength = getValue("isTotalStrength", true);
47 isSquad = getValue("isSquad", true);
48 isSmartSquad = getValue("isSmartSquad", true);
49 isLoddarStats = getValue("isLoddarStats", true);
50 isShowPlayerInfo = getValue("isShowPlayerInfo", false);
51 isCheckTeamName = getValue("isCheckTeamName", true);
52
53
54 isShowUnavailable = true;
55 }
56
57
58
59 /***
60 * TODO Missing Method Documentation
61 *
62 * @param b TODO Missing Method Parameter Documentation
63 */
64 public void setCheckTeamName(boolean b) {
65 isCheckTeamName = b;
66 setValue("isCheckTeamName", b);
67 }
68
69 /***
70 * TODO Missing Method Documentation
71 *
72 * @return TODO Missing Return Method Documentation
73 */
74 public boolean isCheckTeamName() {
75 return isCheckTeamName;
76 }
77
78 /***
79 * Document Me!
80 *
81 * @param b
82 */
83 public void setDescriptionRating(boolean b) {
84 isDescriptionRating = b;
85 setValue("descriptionRating", b);
86 }
87
88 /***
89 * Document Me!
90 *
91 * @return
92 */
93 public boolean isDescriptionRating() {
94 return isDescriptionRating;
95 }
96
97 /***
98 * Document Me!
99 *
100 * @param b
101 */
102 public void setLineup(boolean b) {
103 isLineup = b;
104 setValue("lineupCompare", b);
105 }
106
107 /***
108 * Document Me!
109 *
110 * @return
111 */
112 public boolean isLineup() {
113 return isLineup;
114 }
115
116 /***
117 * TODO Missing Method Documentation
118 *
119 * @param b TODO Missing Method Parameter Documentation
120 */
121 public void setLoddarStats(boolean b) {
122 isLoddarStats = b;
123 setValue("isLoddarStats", b);
124 }
125
126 /***
127 * TODO Missing Method Documentation
128 *
129 * @return TODO Missing Return Method Documentation
130 */
131 public boolean isLoddarStats() {
132 return isLoddarStats;
133 }
134
135 /***
136 * Document Me!
137 *
138 * @param b
139 */
140 public void setMixedLineup(boolean b) {
141 isMixedLineup = b;
142 setValue("mixedLineup", b);
143 }
144
145 /***
146 * Document Me!
147 *
148 * @return
149 */
150 public boolean isMixedLineup() {
151 return isMixedLineup;
152 }
153
154 /***
155 * Document Me!
156 *
157 * @param b
158 */
159 public void setNumericRating(boolean b) {
160 isNumericRating = b;
161 setValue("numericRating", b);
162 }
163
164 /***
165 * Document Me!
166 *
167 * @return
168 */
169 public boolean isNumericRating() {
170 return isNumericRating;
171 }
172
173 /***
174 * TODO Missing Method Documentation
175 *
176 * @param b TODO Missing Method Parameter Documentation
177 */
178 public void setShowPlayerInfo(boolean b) {
179 isShowPlayerInfo = b;
180 setValue("isShowPlayerInfo", b);
181 }
182
183 /***
184 * TODO Missing Method Documentation
185 *
186 * @return TODO Missing Return Method Documentation
187 */
188 public boolean isShowPlayerInfo() {
189 return isShowPlayerInfo;
190 }
191
192 /***
193 * Document Me!
194 *
195 * @param b TODO Missing Constructuor Parameter Documentation
196 */
197 public void setShowUnavailable(boolean b) {
198 isShowUnavailable = b;
199 setValue("showUnavailable", b);
200 }
201
202 /***
203 * Document Me!
204 *
205 * @return TODO Missing Return Method Documentation
206 */
207 public boolean isShowUnavailable() {
208 return isShowUnavailable;
209 }
210
211 /***
212 * Document Me!
213 *
214 * @param b
215 */
216 public void setSmartSquad(boolean b) {
217 isSmartSquad = b;
218 setValue("isSmartSquad", b);
219 }
220
221 /***
222 * Document Me!
223 *
224 * @return
225 */
226 public boolean isSmartSquad() {
227 return isSmartSquad;
228 }
229
230 /***
231 * Document Me!
232 *
233 * @param b
234 */
235 public void setSquad(boolean b) {
236 isSquad = b;
237 setValue("isSquad", b);
238 }
239
240 /***
241 * Document Me!
242 *
243 * @return
244 */
245 public boolean isSquad() {
246 return isSquad;
247 }
248
249 /***
250 * Document Me!
251 *
252 * @param b
253 */
254 public void setStars(boolean b) {
255 isStars = b;
256 setValue("isStars", b);
257 }
258
259 /***
260 * Document Me!
261 *
262 * @return
263 */
264 public boolean isStars() {
265 return isStars;
266 }
267
268 /***
269 * Document Me!
270 *
271 * @param b
272 */
273 public void setTacticDetail(boolean b) {
274 tacticDetail = b;
275 setValue("tacticDetail", b);
276 }
277
278 /***
279 * Document Me!
280 *
281 * @return
282 */
283 public boolean isTacticDetail() {
284 return tacticDetail;
285 }
286
287 /***
288 * Document Me!
289 *
290 * @param b
291 */
292 public void setTotalStrength(boolean b) {
293 isTotalStrength = b;
294 setValue("isTotalStrength", b);
295 }
296
297 /***
298 * Document Me!
299 *
300 * @return
301 */
302 public boolean isTotalStrength() {
303 return isTotalStrength;
304 }
305
306 /***
307 * Set the value in the databse
308 *
309 * @param key The key
310 * @param value the value
311 */
312 private void setValue(String key, boolean value) {
313 String val = (value) ? "1" : "0";
314
315 String query = "update TEAMANALYZER_SETTINGS set VALUE = " + val + " where NAME = '" + key
316 + "'";
317 int count = Commons.getModel().getAdapter().executeUpdate(query);
318
319 if (count == 0) {
320 Commons.getModel().getAdapter().executeUpdate("insert into TEAMANALYZER_SETTINGS (NAME, VALUE) values ('"
321 + key + "', " + val + ")");
322 }
323 }
324
325 /***
326 * Returns a value
327 *
328 * @param key the key to be returned
329 * @param defaultValue to be used if not existing
330 *
331 * @return the value
332 */
333 private boolean getValue(String key, boolean defaultValue) {
334 String query = "select VALUE from TEAMANALYZER_SETTINGS where NAME='" + key + "'";
335 ResultSet rs = Commons.getModel().getAdapter().executeQuery(query);
336
337 try {
338 rs.next();
339
340 return rs.getBoolean("VALUE");
341 } catch (SQLException e) {
342 return defaultValue;
343 }
344 }
345
346 /***
347 * Check if the table exists, if not create it with default values
348 */
349 private void checkTable() {
350 try {
351 ResultSet rs = Commons.getModel().getAdapter().executeQuery("select * from TEAMANALYZER_SETTINGS");
352 rs.next();
353 } catch (Exception e) {
354 Commons.getModel().getAdapter().executeUpdate("CREATE TABLE TEAMANALYZER_SETTINGS(NAME varchar(32),VALUE bit)");
355 }
356
357 try {
358 ResultSet rs = Commons.getModel().getAdapter().executeQuery("select NAME from TEAMANALYZER_SETTINGS");
359 rs.next();
360 } catch (Exception e) {
361 Commons.getModel().getAdapter().executeUpdate("ALTER TABLE TEAMANALYZER_SETTINGS ADD COLUMN NAME varchar(20)");
362 Commons.getModel().getAdapter().executeUpdate("UPDATE TEAMANALYZER_SETTINGS SET NAME=KEY");
363 Commons.getModel().getAdapter().executeUpdate("ALTER TABLE TEAMANALYZER_SETTINGS DROP COLUMN KEY");
364 }
365 }
366 }