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.rulemgt.db;
\r
18 import java.util.List;
\r
19 import org.onap.holmes.common.api.entity.CorrelationRule;
\r
20 import org.onap.holmes.common.exception.CorrelationException;
\r
21 import org.onap.holmes.common.utils.CorrelationRuleMapper;
\r
22 import org.skife.jdbi.v2.sqlobject.Bind;
\r
23 import org.skife.jdbi.v2.sqlobject.BindBean;
\r
24 import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
\r
25 import org.skife.jdbi.v2.sqlobject.SqlQuery;
\r
26 import org.skife.jdbi.v2.sqlobject.SqlUpdate;
\r
27 import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
\r
29 @RegisterMapper(CorrelationRuleMapper.class)
\r
30 public abstract class CorrelationRuleDao {
\r
33 @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid)")
\r
34 protected abstract String addRule(@BindBean CorrelationRule correlationRule);
\r
36 @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName WHERE RID=:rid")
\r
37 protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
\r
39 @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
\r
40 protected abstract int deleteRuleByRid(@Bind("rid") String rid);
\r
42 @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
\r
43 protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
\r
45 @SqlQuery("SELECT * FROM APLUS_RULE")
\r
46 protected abstract List<CorrelationRule> queryAllRules();
\r
48 @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
\r
49 protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
\r
51 @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
\r
52 protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);
\r
54 private void deleteRule2DbInner(CorrelationRule correlationRule) {
\r
55 String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
\r
56 String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
\r
57 if (!"".equals(name) && !"".equals(rid)) {
\r
58 deleteRuleByRidAndName(rid, name);
\r
59 } else if (!"".equals(rid)) {
\r
60 deleteRuleByRid(rid);
\r
64 public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
\r
66 addRule(correlationRule);
\r
67 return correlationRule;
\r
68 } catch (Exception e) {
\r
69 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
\r
73 public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
\r
75 updateRuleByRid(correlationRule);
\r
76 } catch (Exception e) {
\r
77 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
\r
81 public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
\r
83 deleteRule2DbInner(correlationRule);
\r
84 } catch (Exception e) {
\r
85 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
\r
90 public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
\r
92 return queryRuleById(rid);
\r
93 } catch (Exception e) {
\r
94 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
\r
98 public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
\r
100 return queryRuleByName(name);
\r
101 } catch (Exception e) {
\r
102 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
\r