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.pap.xacml.rest.daoimpl;
23 import java.util.List;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.hibernate.Criteria;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
32 import org.openecomp.policy.rest.dao.EnforcerPolicyDao;
33 import org.openecomp.policy.rest.jpa.EnforcingType;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Service;
37 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
39 @Service("EnforcerPolicyDao")
40 public class EnforcerPolicyDaoImpl implements EnforcerPolicyDao {
41 private static final Log logger = LogFactory.getLog(EnforcerPolicyDaoImpl.class);
43 SessionFactory sessionfactory;
45 public SessionFactory getSessionfactory() {
46 return sessionfactory;
49 public void setSessionfactory(SessionFactory sessionfactory) {
50 this.sessionfactory = sessionfactory;
53 @SuppressWarnings("unchecked")
55 public List<EnforcingType> getEnforcingTypeData() {
56 Session session = HibernateSession.getSessionFactory();
57 Transaction tx = session.beginTransaction();
58 List<EnforcingType> enforcingTypeData = null;
60 Criteria cr = session.createCriteria(EnforcingType.class);
61 enforcingTypeData = cr.list();
63 } catch (Exception e) {
64 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EnforcingType Table"+e);
69 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
72 return enforcingTypeData;
77 public void Save(EnforcingType enforcingType) {
78 Session session = HibernateSession.getSessionFactory();
79 Transaction tx = session.beginTransaction();
81 session.persist(enforcingType);
84 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EnforcingType Table"+e);
89 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
96 public void delete(EnforcingType enforcingType) {
97 Session session = HibernateSession.getSessionFactory();
98 Transaction tx = session.beginTransaction();
100 session.delete(enforcingType);
103 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EnforcingType Table"+e);
107 }catch(Exception e1){
108 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
114 public void update(EnforcingType enforcingType) {
115 Session session = HibernateSession.getSessionFactory();
116 Transaction tx = session.beginTransaction();
118 session.update(enforcingType);
121 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EnforcingType Table"+e);
125 }catch(Exception e1){
126 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);