2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.daoImp;
24 import java.util.List;
26 import org.hibernate.Criteria;
27 import org.hibernate.Query;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31 import org.hibernate.criterion.Restrictions;
32 import org.openecomp.policy.dao.WatchPolicyNotificationDao;
33 import org.openecomp.policy.rest.jpa.WatchPolicyNotificationTable;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Service;
37 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
39 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
40 import org.openecomp.policy.common.logging.flexlogger.Logger;
42 @Service("WatchPolicyNotificationDao")
43 public class WatchPolicyNotificationDaoImpl implements WatchPolicyNotificationDao{
45 private static final Logger logger = FlexLogger.getLogger(WatchPolicyNotificationDaoImpl.class);
48 SessionFactory sessionfactory;
50 @SuppressWarnings("unchecked")
52 public List<WatchPolicyNotificationTable> getListData() {
53 Session session = sessionfactory.openSession();
54 Transaction tx = session.beginTransaction();
55 List<WatchPolicyNotificationTable> attributeData =null;
57 Criteria cr = session.createCriteria(WatchPolicyNotificationTable.class);
58 attributeData = cr.list();
60 } catch (Exception e) {
61 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e);
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
73 public void save(WatchPolicyNotificationTable attribute) {
74 Session session = sessionfactory.openSession();
75 Transaction tx = session.beginTransaction();
77 session.persist(attribute);
80 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving WatchPolicyNotificationTable Table"+e);
85 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
92 public void delete(WatchPolicyNotificationTable attribute) {
93 Session session = sessionfactory.openSession();
94 Transaction tx = session.beginTransaction();
96 session.delete(attribute);
99 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting WatchPolicyNotificationTable Table"+e);
103 }catch(Exception e1){
104 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
110 public void update(WatchPolicyNotificationTable attribute) {
111 Session session = sessionfactory.openSession();
112 Transaction tx = session.beginTransaction();
114 session.update(attribute);
117 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating WatchPolicyNotificationTable Table"+e);
121 }catch(Exception e1){
122 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
128 @SuppressWarnings("unchecked")
130 public List<WatchPolicyNotificationTable> getListDataByPolicyName(String policyName) {
131 Session session = sessionfactory.openSession();
132 Transaction tx = session.beginTransaction();
133 List<WatchPolicyNotificationTable> data = null;
135 Criteria cr = session.createCriteria(WatchPolicyNotificationTable.class);
136 cr.add(Restrictions.eq("policyName",policyName));
139 } catch (Exception e) {
140 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e);
144 }catch(Exception e1){
145 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
151 @SuppressWarnings("unchecked")
153 public List<WatchPolicyNotificationTable> watchListQuery(String query) {
154 Session session = sessionfactory.openSession();
155 Transaction tx = session.beginTransaction();
156 List<WatchPolicyNotificationTable> data = null;
158 Query hbquery = session.createQuery(query);
159 data = hbquery.list();
161 } catch (Exception e) {
162 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e);
166 }catch(Exception e1){
167 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);