Modify pom
[holmes/common.git] / holmes-actions / src / main / java / org / openo / holmes / common / db / AlarmCorrelationQueryDao.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.openo.holmes.common.db;\r
17 \r
18 import java.util.ArrayList;\r
19 import java.util.List;\r
20 import java.util.Map;\r
21 \r
22 import javax.inject.Inject;\r
23 \r
24 import org.jvnet.hk2.annotations.Service;\r
25 import org.openo.holmes.common.api.entity.AlarmsCorrelation;\r
26 import org.skife.jdbi.v2.Query;\r
27 \r
28 import org.openo.holmes.common.db.mapper.AlarmsCorrelationMapper;\r
29 import org.openo.holmes.common.utils.DbDaoUtil;\r
30 \r
31 import lombok.extern.slf4j.Slf4j;\r
32 \r
33 @Service\r
34 @Slf4j\r
35 public class AlarmCorrelationQueryDao {\r
36 \r
37   @Inject\r
38   private DbDaoUtil dbDaoUtil;\r
39 \r
40   @Inject\r
41   private AlarmsCorrelationMapper mapper;\r
42 \r
43   private final static String SELECT_TABLE_SQL = "SELECT * FROM APLUS_CORRELATION ";\r
44 \r
45   public List<AlarmsCorrelation> queryByFilter(String where) {\r
46     List<AlarmsCorrelation> alarmsCorrelations = new ArrayList<AlarmsCorrelation>();\r
47     StringBuilder querySql = new StringBuilder(SELECT_TABLE_SQL).append(where);\r
48     log.info("Query alarm correlation table! Sql:[" + querySql + "].");\r
49     Query<Map<String, Object>> query = dbDaoUtil.getHandle().createQuery(querySql.toString());\r
50     List<Map<String, Object>> dbDataMaps = query.list();\r
51     for (Map<String, Object> map : dbDataMaps) {\r
52       alarmsCorrelations.add(mapper.getAlarmCorrelationByMap(map));\r
53     }\r
54     log.info("Success to query alarm correlation table! total count:[" + dbDataMaps.size() + "].");\r
55     return alarmsCorrelations;\r
56   }\r
57 }\r