2 * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.server.service.impl;
19 import java.util.Date;
20 import java.util.List;
22 import javax.transaction.Transactional;
24 import org.hibernate.Query;
25 import org.hibernate.Session;
26 import org.hibernate.SessionFactory;
27 import org.hibernate.Transaction;
28 import org.onap.usecaseui.server.bean.PerformanceInformation;
29 import org.onap.usecaseui.server.service.PerformanceInformationService;
30 import org.onap.usecaseui.server.util.Page;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.stereotype.Service;
38 @Service("PerformanceInformationService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
42 public class PerformanceInformationServiceImpl implements PerformanceInformationService {
43 private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class);
46 private SessionFactory sessionFactory;
50 public String savePerformanceInformation(PerformanceInformation performanceInformation) {
52 if (null == performanceInformation) {
53 logger.error("performanceInformation PerformanceInformation performanceInformation is null!");
55 logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation);
56 Session session = sessionFactory.openSession();
57 Transaction tx = session.beginTransaction();
58 session.save(performanceInformation);
63 } catch (Exception e) {
64 logger.error("Exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage());
72 public String updatePerformanceInformation(PerformanceInformation performanceInformation) {
74 if (null == performanceInformation) {
75 logger.error("performanceInformation PerformanceInformation performanceInformation is null!");
77 logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation);
78 Session session = sessionFactory.openSession();
79 Transaction tx = session.beginTransaction();
80 session.update(performanceInformation);
85 } catch (Exception e) {
86 logger.error("Exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage());
92 public int getAllCount() {
94 Session session = sessionFactory.openSession();
95 Transaction tx = session.beginTransaction();
96 long q=(long)session.createQuery("select count(*) from PerformanceInformation").uniqueResult();
101 } catch (Exception e) {
102 logger.error("Exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());
107 @SuppressWarnings("unchecked")
109 public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,
110 int currentPage, int pageSize) {
111 Page<PerformanceInformation> page = new Page<PerformanceInformation>();
112 int allRow =this.getAllCount();
113 int offset = page.countOffset(currentPage, pageSize);
116 StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1");
117 if (null == performanceInformation) {
118 logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");
119 }else if(null!=performanceInformation.getName()) {
120 String ver=performanceInformation.getName();
121 hql.append(" and a.name like '%"+ver+"%'");
122 }else if(null!=performanceInformation.getValue()) {
123 String ver=performanceInformation.getValue();
124 hql.append(" and a.value like '%"+ver+"%'");
125 }else if(null!=performanceInformation.getEventId()) {
126 String ver=performanceInformation.getEventId();
127 hql.append(" and a.eventId like '%"+ver+"%'");
128 }else if(null!=performanceInformation.getCreateTime()) {
129 Date ver =performanceInformation.getCreateTime();
130 hql.append(" and a.createTime like '%"+ver+"%'");
131 }else if(null!=performanceInformation.getUpdateTime()) {
132 Date ver =performanceInformation.getUpdateTime();
133 hql.append(" and a.updateTime like '%"+ver+"%'");
135 logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation);
136 Session session = sessionFactory.openSession();
137 Transaction tx = session.beginTransaction();
138 Query query = session.createQuery(hql.toString());
139 query.setFirstResult(offset);
140 query.setMaxResults(pageSize);
141 List<PerformanceInformation> list= query.list();
142 page.setPageNo(currentPage);
143 page.setPageSize(pageSize);
144 page.setTotalRecords(allRow);
150 } catch (Exception e) {
151 logger.error("Exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());