+++ /dev/null
-/**\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.rulemgt.db;\r
-\r
-import java.util.List;\r
-\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.api.entity.CorrelationRule;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.holmes.common.utils.CorrelationRuleMapper;\r
-import org.skife.jdbi.v2.sqlobject.Bind;\r
-import org.skife.jdbi.v2.sqlobject.BindBean;\r
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;\r
-import org.skife.jdbi.v2.sqlobject.SqlQuery;\r
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;\r
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
-\r
-@Service\r
-@RegisterMapper(CorrelationRuleMapper.class)\r
-public abstract class CorrelationRuleDao {\r
-\r
- @GetGeneratedKeys\r
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")\r
- protected abstract String addRule(@BindBean CorrelationRule correlationRule);\r
-\r
- @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")\r
- protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);\r
-\r
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")\r
- protected abstract int deleteRuleByRid(@Bind("rid") String rid);\r
-\r
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")\r
- protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);\r
-\r
- @SqlQuery("SELECT * FROM APLUS_RULE")\r
- protected abstract List<CorrelationRule> queryAllRules();\r
-\r
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")\r
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);\r
-\r
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")\r
- protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);\r
-\r
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")\r
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);\r
-\r
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")\r
- public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);\r
-\r
- public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {\r
- return queryRuleByEngineInstance(enginetype);\r
- }\r
-\r
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {\r
- return queryRuleByEnable(enable);\r
- }\r
-\r
-\r
- private void deleteRule2DbInner(CorrelationRule correlationRule) {\r
- String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";\r
- String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";\r
- if (!"".equals(name) && !"".equals(rid)) {\r
- deleteRuleByRidAndName(rid, name);\r
- } else if (!"".equals(rid)) {\r
- deleteRuleByRid(rid);\r
- }\r
- }\r
-\r
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {\r
- try {\r
- addRule(correlationRule);\r
- return correlationRule;\r
- } catch (Exception e) {\r
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {\r
- try {\r
- updateRuleByRid(correlationRule);\r
- } catch (Exception e) {\r
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {\r
- try {\r
- deleteRule2DbInner(correlationRule);\r
- } catch (Exception e) {\r
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
-\r
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {\r
- try {\r
- return queryRuleById(rid);\r
- } catch (Exception e) {\r
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {\r
- try {\r
- return queryRuleByName(name);\r
- } catch (Exception e) {\r
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-}\r
-\r