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.ArrayList;
24 import java.util.List;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.hibernate.Criteria;
29 import org.hibernate.Session;
30 import org.hibernate.SessionFactory;
31 import org.hibernate.Transaction;
32 import org.hibernate.criterion.Restrictions;
33 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
34 import org.openecomp.policy.rest.dao.VarbindDictionaryDao;
35 import org.openecomp.policy.rest.jpa.VarbindDictionary;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
39 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
41 @Service("VarbindDictionaryDao")
42 public class VarbindDictionaryDaoImpl implements VarbindDictionaryDao {
43 private static final Log logger = LogFactory.getLog(VarbindDictionaryDaoImpl.class);
45 SessionFactory sessionfactory;
47 public SessionFactory getSessionfactory() {
48 return sessionfactory;
51 public void setSessionfactory(SessionFactory sessionfactory) {
52 this.sessionfactory = sessionfactory;
55 @SuppressWarnings("unchecked")
57 public List<VarbindDictionary> getVarbindDictionaryData() {
58 Session session = HibernateSession.getSessionFactory();
59 Transaction tx = session.beginTransaction();
60 List<VarbindDictionary> varbindDictionaryData = null;
62 Criteria cr = session.createCriteria(VarbindDictionary.class);
63 varbindDictionaryData = cr.list();
65 } catch (Exception e) {
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
71 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
74 return varbindDictionaryData;
79 public void Save(VarbindDictionary varbindDictionary) {
80 Session session = HibernateSession.getSessionFactory();
81 Transaction tx = session.beginTransaction();
83 session.persist(varbindDictionary);
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VarbindDictionary Table"+e);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
98 public void delete(VarbindDictionary varbindDictionary) {
99 Session session = HibernateSession.getSessionFactory();
100 Transaction tx = session.beginTransaction();
102 session.delete(varbindDictionary);
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VarbindDictionary Table"+e);
109 }catch(Exception e1){
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
116 public void update(VarbindDictionary varbindDictionary) {
117 Session session = HibernateSession.getSessionFactory();
118 Transaction tx = session.beginTransaction();
120 session.update(varbindDictionary);
123 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VarbindDictionary Table"+e);
127 }catch(Exception e1){
128 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
134 @SuppressWarnings("unchecked")
136 public List<String> getVarbindDataByName() {
137 Session session = HibernateSession.getSessionFactory();
138 Transaction tx = session.beginTransaction();
139 List<String> data = new ArrayList<String>();
141 Criteria cr = session.createCriteria(VarbindDictionary.class);
142 List<VarbindDictionary> varbindDictionaryData = cr.list();
143 for(int i = 0; i < varbindDictionaryData.size(); i++){
144 data.add(varbindDictionaryData.get(i).getVarbindName());
147 } catch (Exception e) {
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
152 }catch(Exception e1){
153 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
160 public List<VarbindDictionary> getVarbindEntityByName(String value) {
161 Session session = HibernateSession.getSessionFactory();
162 Transaction tx = session.beginTransaction();
163 List<VarbindDictionary> data = null;
165 Criteria cr = session.createCriteria(VarbindDictionary.class);
166 cr.add(Restrictions.eq("varbindName",value));
169 } catch (Exception e) {
170 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
174 }catch(Exception e1){
175 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);