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.openecomp.policy.rest.dao.AddressGroupDao;
34 import org.openecomp.policy.rest.jpa.AddressGroup;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
40 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
41 import org.openecomp.policy.common.logging.flexlogger.Logger;
43 @Service("AddressGroupDao")
44 public class AddressGroupDaoImpl implements AddressGroupDao{
45 private static final Logger logger = FlexLogger.getLogger(AddressGroupDaoImpl.class);
47 SessionFactory sessionfactory;
49 @SuppressWarnings("unchecked")
51 public List<AddressGroup> getAddressGroupData() {
52 Session session = sessionfactory.openSession();
53 Transaction tx = session.beginTransaction();
54 List<AddressGroup> attributeData = null;
56 Criteria cr = session.createCriteria(AddressGroup.class);
57 attributeData = cr.list();
59 } catch (Exception e) {
60 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e);
65 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
73 public void Save(AddressGroup 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 AddressGroup Table"+e);
85 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
92 public void delete(AddressGroup 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 AddressGroup Table"+e);
103 }catch(Exception e1){
104 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
110 public void update(AddressGroup 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 AddressGroup 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<String> getAddressGroupDataByName() {
131 Session session = sessionfactory.openSession();
132 Transaction tx = session.beginTransaction();
133 List<String> data = new ArrayList<String>();
135 Criteria cr = session.createCriteria(AddressGroup.class);
136 List<AddressGroup> attributeData = cr.list();
137 for(int i = 0; i < attributeData.size(); i++){
138 data.add(attributeData.get(i).getGroupName());
141 } catch (Exception e) {
142 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e);
146 }catch(Exception e1){
147 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);