01: package com.bostechcorp.cbesb.common.util.runtimedb;
02:
03: import java.util.HashMap;
04: import java.util.List;
05: import java.util.Map;
06:
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09:
10: import com.bostechcorp.cbesb.common.util.runtimedb.vo.ConsoleSettingVO;
11:
12: public class ConsoleSettingDB extends AbstractRuntimeDB {
13: protected static final int DEFAULT_INTERVAL = 60000;
14: private static Log log = LogFactory.getLog(ConsoleSettingDB.class);
15:
16: public static Map<String, ConsoleSettingVO> getSettingByUserId(
17: String userId) throws Exception {
18: List<ConsoleSettingVO> list = null;
19: HashMap<String, ConsoleSettingVO> map = new HashMap<String, ConsoleSettingVO>();
20: if (userId.equals("0"))
21: list = sqlMap.queryForList("queryById", userId);
22: else
23: list = sqlMap.queryForList("querySettingById", userId);
24: for (ConsoleSettingVO object : list) {
25: map.put(object.getSetting(), object);
26: }
27: return map;
28: }
29:
30: public static void saveConsoleSetting(String userId,
31: List<ConsoleSettingVO> settingList) throws Exception {
32: // delete(userId);
33: for (ConsoleSettingVO settingVO : settingList) {
34:
35: if ((select(settingVO)) == null)
36: sqlMap.insert("insertConsoleSetting", settingVO);
37: else
38: sqlMap.update("updateConsoleSetting", settingVO);
39:
40: }
41: }
42:
43: private static ConsoleSettingVO select(ConsoleSettingVO vo)
44: throws Exception {
45: return (ConsoleSettingVO) sqlMap
46: .queryForObject("queryByVO", vo);
47: }
48:
49: public static void delete(String userId) throws Exception {
50:
51: sqlMap.delete("deleteConsoleSetting", userId);
52: }
53:
54: public static int getSystemStatisticsRate() throws Exception {
55: String inteval = (String) sqlMap.queryForObject(
56: "getStatisticsRateById", "0");
57: try {
58: if (inteval == null || inteval.equals("0"))
59: return DEFAULT_INTERVAL;
60: return Integer.parseInt(inteval) * 1000;
61: } catch (Exception e) {
62: log.error("StatisticsRefreshRate retrive error", e);
63: }
64: return DEFAULT_INTERVAL;
65: }
66:
67: }
|