+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.holmes.engine.db;\r
+\r
+import org.onap.holmes.common.api.entity.AlarmInfo;\r
+import org.onap.holmes.common.exception.AlarmInfoException;\r
+import org.onap.holmes.common.utils.AlarmInfoMapper;\r
+import org.skife.jdbi.v2.sqlobject.*;\r
+import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
+\r
+import java.util.List;\r
+\r
+@RegisterMapper(AlarmInfoMapper.class)\r
+public abstract class AlarmInfoDao {\r
+\r
+ @GetGeneratedKeys\r
+ @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")\r
+ protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);\r
+\r
+ @SqlQuery("SELECT * FROM ALARM_INFO")\r
+ protected abstract List<AlarmInfo> queryAlarm();\r
+\r
+ @SqlUpdate("DELETE FROM ALARM_INFO WHERE ALARMISCLEARED=:alarmiscleared")\r
+ protected abstract int deleteAlarmByAlarmIsCleared(@Bind("alarmiscleared") int alarmIsCleared);\r
+\r
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {\r
+ try {\r
+ addAlarm(alarmInfo);\r
+ return alarmInfo;\r
+ } catch(Exception e) {\r
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
+ }\r
+ }\r
+\r
+ public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {\r
+ try {\r
+ return queryAlarm();\r
+ } catch(Exception e) {\r
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
+ }\r
+ }\r
+\r
+ public void deleteClearedAlarm(AlarmInfo alarmInfo) {\r
+ int alarmIsCleared = alarmInfo.getAlarmIsCleared();\r
+ if(alarmIsCleared == 1) {\r
+ deleteAlarmByAlarmIsCleared(alarmIsCleared);\r
+ }\r
+ }\r
+}\r