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.ArrayList;
25 import java.util.List;
27 //import org.apache.commons.logging.Log;
28 //import org.apache.commons.logging.LogFactory;
29 import org.hibernate.Criteria;
30 import org.hibernate.Session;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.Transaction;
33 import org.hibernate.criterion.Restrictions;
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 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
42 import org.openecomp.policy.common.logging.flexlogger.Logger;
44 @Service("VarbindDictionaryDao")
45 public class VarbindDictionaryDaoImpl implements VarbindDictionaryDao {
46 private static final Logger logger = FlexLogger.getLogger(VarbindDictionaryDaoImpl.class);
48 SessionFactory sessionfactory;
50 @SuppressWarnings("unchecked")
52 public List<VarbindDictionary> getVarbindDictionaryData() {
53 Session session = sessionfactory.openSession();
54 Transaction tx = session.beginTransaction();
55 List<VarbindDictionary> varbindDictionaryData = null;
57 Criteria cr = session.createCriteria(VarbindDictionary.class);
58 varbindDictionaryData = cr.list();
60 } catch (Exception e) {
61 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
69 return varbindDictionaryData;
74 public void Save(VarbindDictionary varbindDictionary) {
75 Session session = sessionfactory.openSession();
76 Transaction tx = session.beginTransaction();
78 session.persist(varbindDictionary);
81 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VarbindDictionary Table"+e);
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
93 public void delete(VarbindDictionary varbindDictionary) {
94 Session session = sessionfactory.openSession();
95 Transaction tx = session.beginTransaction();
97 session.delete(varbindDictionary);
100 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VarbindDictionary Table"+e);
104 }catch(Exception e1){
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
111 public void update(VarbindDictionary varbindDictionary) {
112 Session session = sessionfactory.openSession();
113 Transaction tx = session.beginTransaction();
115 session.update(varbindDictionary);
118 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VarbindDictionary Table"+e);
122 }catch(Exception e1){
123 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
129 @SuppressWarnings("unchecked")
131 public List<String> getVarbindDataByName() {
132 Session session = sessionfactory.openSession();
133 Transaction tx = session.beginTransaction();
134 List<String> data = new ArrayList<String>();
136 Criteria cr = session.createCriteria(VarbindDictionary.class);
137 List<VarbindDictionary> varbindDictionaryData = cr.list();
138 for(int i = 0; i < varbindDictionaryData.size(); i++){
139 data.add(varbindDictionaryData.get(i).getVarbindName());
142 } catch (Exception e) {
143 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
147 }catch(Exception e1){
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
154 @SuppressWarnings("unchecked")
156 public List<VarbindDictionary> getVarbindEntityByName(String value) {
157 Session session = sessionfactory.openSession();
158 Transaction tx = session.beginTransaction();
159 List<VarbindDictionary> data = null;
161 Criteria cr = session.createCriteria(VarbindDictionary.class);
162 cr.add(Restrictions.eq("varbindName",value));
165 } catch (Exception e) {
166 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e);
170 }catch(Exception e1){
171 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);