2 * Copyright 2017 ZTE Corporation.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
16 package org.openo.holmes.common.db;
\r
18 import java.util.ArrayList;
\r
19 import java.util.List;
\r
20 import java.util.Map;
\r
22 import javax.inject.Inject;
\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
28 import org.openo.holmes.common.db.mapper.AlarmsCorrelationMapper;
\r
29 import org.openo.holmes.common.utils.DbDaoUtil;
\r
31 import lombok.extern.slf4j.Slf4j;
\r
35 public class AlarmCorrelationQueryDao {
\r
38 private DbDaoUtil dbDaoUtil;
\r
41 private AlarmsCorrelationMapper mapper;
\r
43 private final static String SELECT_TABLE_SQL = "SELECT * FROM APLUS_CORRELATION ";
\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
54 log.info("Success to query alarm correlation table! total count:[" + dbDataMaps.size() + "].");
\r
55 return alarmsCorrelations;
\r