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.onap.holmes.engine.db;
\r
18 import org.onap.holmes.common.api.entity.AlarmInfo;
\r
19 import org.onap.holmes.common.exception.AlarmInfoException;
\r
20 import org.onap.holmes.common.utils.AlarmInfoMapper;
\r
21 import org.skife.jdbi.v2.sqlobject.*;
\r
22 import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
\r
24 import java.util.List;
\r
26 @RegisterMapper(AlarmInfoMapper.class)
\r
27 public abstract class AlarmInfoDao {
\r
30 @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")
\r
31 protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);
\r
33 @SqlQuery("SELECT * FROM ALARM_INFO")
\r
34 protected abstract List<AlarmInfo> queryAlarm();
\r
36 @SqlUpdate("DELETE FROM ALARM_INFO WHERE ALARMISCLEARED=:alarmiscleared")
\r
37 protected abstract int deleteAlarmByAlarmIsCleared(@Bind("alarmiscleared") int alarmIsCleared);
\r
39 public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
\r
41 addAlarm(alarmInfo);
\r
43 } catch(Exception e) {
\r
44 throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
\r
48 public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
\r
50 return queryAlarm();
\r
51 } catch(Exception e) {
\r
52 throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
\r
56 public void deleteClearedAlarm(AlarmInfo alarmInfo) {
\r
57 int alarmIsCleared = alarmInfo.getAlarmIsCleared();
\r
58 if(alarmIsCleared == 1) {
\r
59 deleteAlarmByAlarmIsCleared(alarmIsCleared);
\r