summaryrefslogtreecommitdiffstats
path: root/engine-d/src/main/java/org/onap/holmes/engine/db
diff options
context:
space:
mode:
Diffstat (limited to 'engine-d/src/main/java/org/onap/holmes/engine/db')
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java (renamed from engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java)132
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java35
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java37
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java43
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java (renamed from engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java)29
5 files changed, 189 insertions, 87 deletions
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java
index 83fa3f6..5c3444e 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java
@@ -1,70 +1,62 @@
-/**
- * Copyright 2017 ZTE Corporation.
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.engine.db;
-
-import org.onap.holmes.common.api.entity.AlarmInfo;
-import org.onap.holmes.common.exception.AlarmInfoException;
-import org.onap.holmes.common.utils.AlarmInfoMapper;
-import org.skife.jdbi.v2.sqlobject.*;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-import java.util.List;
-
-@RegisterMapper(AlarmInfoMapper.class)
-public abstract class AlarmInfoDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,SEQUENCE,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:sequence,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")
- protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);
-
- @SqlQuery("SELECT * FROM ALARM_INFO")
- protected abstract List<AlarmInfo> queryAlarm();
-
- @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")
- protected abstract int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,
- @Bind("sourceId") String sourceId,
- @Bind("sourceName") String sourceName);
-
- public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
- try {
- addAlarm(alarmInfo);
- return alarmInfo;
- } catch (Exception e) {
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
- try {
- return queryAlarm();
- } catch (Exception e) {
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteAlarm(AlarmInfo alarmInfo) {
- if (alarmInfo.getAlarmIsCleared() != 1) {
- return;
- }
-
- String sourceId = alarmInfo.getSourceId();
- String sourceName = alarmInfo.getSourceName();
- String eventName = alarmInfo.getEventName();
- eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
-
- deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);
- }
-}
+/**
+ * Copyright 2021-2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.engine.db;
+
+import org.onap.holmes.common.api.entity.AlarmInfo;
+import org.onap.holmes.common.exception.AlarmInfoException;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+
+public class AlarmInfoDaoService {
+
+ @Autowired
+ private AlarmInfoDao alarmInfoDao;
+
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
+ try {
+ alarmInfoDao.addAlarm(alarmInfo);
+ return alarmInfo;
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
+ try {
+ return alarmInfoDao.queryAlarm();
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void deleteAlarm(AlarmInfo alarmInfo) {
+ if (alarmInfo.getAlarmIsCleared() != 1) {
+ return;
+ }
+
+ String sourceId = alarmInfo.getSourceId();
+ String sourceName = alarmInfo.getSourceName();
+ String eventName = alarmInfo.getEventName();
+ eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
+
+ alarmInfoDao.deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java b/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java
new file mode 100644
index 0000000..a80a255
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2021 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.engine.db;
+
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.engine.db.jdbi.CorrelationRuleDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CorrelationRuleDaoService {
+
+ @Autowired
+ private CorrelationRuleDao correlationRuleDao;
+
+ public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
+ return correlationRuleDao.queryRuleByEnable(enable);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java b/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java
new file mode 100644
index 0000000..3a52fd0
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.engine.db;
+
+import org.jdbi.v3.core.Jdbi;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
+import org.onap.holmes.engine.db.jdbi.CorrelationRuleDao;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class DaoProvider {
+
+ @Bean
+ public AlarmInfoDao alarmInfoDao(Jdbi jdbi) {
+ return jdbi.onDemand(AlarmInfoDao.class);
+ }
+
+ @Bean
+ public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) {
+ return jdbi.onDemand(CorrelationRuleDao.class);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java
new file mode 100644
index 0000000..e4b2f1a
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2017-2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.engine.db.jdbi;
+
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.customizer.BindBean;
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;
+import org.onap.holmes.common.api.entity.AlarmInfo;
+import org.onap.holmes.common.utils.AlarmInfoMapper;
+
+import java.util.List;
+
+@RegisterRowMapper(AlarmInfoMapper.class)
+public interface AlarmInfoDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,SEQUENCE,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:sequence,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")
+ String addAlarm(@BindBean AlarmInfo alarmInfo);
+
+ @SqlQuery("SELECT * FROM ALARM_INFO")
+ List<AlarmInfo> queryAlarm();
+
+ @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")
+ int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,
+ @Bind("sourceId") String sourceId,
+ @Bind("sourceName") String sourceName);
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java
index 8cd61ef..bb0f128 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java
@@ -1,37 +1,32 @@
/**
* Copyright 2017 ZTE Corporation.
- *
+ * <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onap.holmes.engine.db;
+package org.onap.holmes.engine.db.jdbi;
-import java.util.List;
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
+import java.util.List;
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
@SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
+ public List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
}