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.openecomp.policy.pap.xacml.rest.HibernateSession;
33 import org.openecomp.policy.rest.dao.EcompNameDao;
34 import org.openecomp.policy.rest.jpa.EcompName;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
40 @Service("EcompNameDao")
41 public class EcompNameDaoImpl implements EcompNameDao {
42 private static final Log logger = LogFactory.getLog(EcompNameDaoImpl.class);
44 SessionFactory sessionfactory;
46 public SessionFactory getSessionfactory() {
47 return sessionfactory;
50 public void setSessionfactory(SessionFactory sessionfactory) {
51 this.sessionfactory = sessionfactory;
54 @SuppressWarnings("unchecked")
56 public List<EcompName> getEcompName() {
57 System.out.println("EcompNameDaoImpl: getEcompName() is called");
58 logger.debug("EcompNameDaoImpl: getEcompName() is called");
59 Session session = HibernateSession.getSessionFactory();
60 Transaction tx = session.beginTransaction();
61 List<EcompName> ecompNameData = null;
63 Criteria cr = session.createCriteria(EcompName.class);
64 ecompNameData = cr.list();
65 System.out.println("Data returned from ecompname table"+ecompNameData.toString());
66 logger.debug("Data returned from ecompname table: " + ecompNameData.toString());
68 } catch (Exception e) {
69 System.out.println("Exception Occured while Querying ecompname"+e);
70 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e);
75 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
82 public void Save(EcompName ecompName) {
83 System.out.println("EcompNameDaoImpl: Save() is called");
84 logger.debug("EcompNameDaoImpl: Save() is called");
85 Session session = HibernateSession.getSessionFactory();
86 Transaction tx = session.beginTransaction();
88 session.persist(ecompName);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EcompName Table"+e);
96 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
103 public void delete(EcompName ecompName) {
104 Session session = HibernateSession.getSessionFactory();
105 Transaction tx = session.beginTransaction();
107 session.delete(ecompName);
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EcompName Table"+e);
114 }catch(Exception e1){
115 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
122 public void update(EcompName ecompName) {
123 Session session = HibernateSession.getSessionFactory();
124 Transaction tx = session.beginTransaction();
126 session.update(ecompName);
129 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EcompName Table"+e);
133 }catch(Exception e1){
134 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
140 @SuppressWarnings("unchecked")
142 public List<String> getEcompNameDataByName() {
143 logger.info("getEcompNameDataByName is call from the DAO implementation class.");
144 Session session = HibernateSession.getSessionFactory();
145 Transaction tx = session.beginTransaction();
146 List<String> data = new ArrayList<String>();
148 Criteria cr = session.createCriteria(EcompName.class);
149 List<EcompName> ecompNameData = cr.list();
150 for(int i = 0; i < ecompNameData.size(); i++){
151 data.add(ecompNameData.get(i).getEcompName());
153 logger.info("data retrieved: " + data.toString());
155 } catch (Exception e) {
156 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e);
160 }catch(Exception e1){
161 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);