1 package org.onap.msb.apiroute.wrapper.dao.service;
3 import com.fasterxml.jackson.core.JsonProcessingException;
5 import java.io.IOException;
6 import java.util.ArrayList;
9 import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper;
10 import org.onap.msb.apiroute.wrapper.dao.service.bean.ServiceInfo;
11 import org.onap.msb.apiroute.wrapper.util.Jackson;
13 public class ServiceDAOImpl implements IServiceDAO{
14 public void saveService(String key, ServiceInfo serviceInfo) throws Exception {
15 String serviceInfoStr = null;
17 serviceInfoStr = Jackson.MAPPER.writeValueAsString(serviceInfo);
18 } catch (JsonProcessingException e) {
19 throw new Exception("error occurred while parsing ServiceInfo to json data",e);
21 RedisAccessWrapper.save(key, serviceInfoStr);
24 public ServiceInfo queryService(String key) throws Exception {
25 ServiceInfo serviceInfo = null;
26 String serviceInfoStr = RedisAccessWrapper.query(key);
27 if (null == serviceInfoStr || "".equals(serviceInfoStr))
30 serviceInfo = Jackson.MAPPER.readValue(serviceInfoStr, ServiceInfo.class);
31 } catch (IOException e) {
32 throw new Exception("error occurred while parsing the redis json data to ServiceInfo",e);
37 public List<ServiceInfo> queryMultiService(String keyPattern) throws Exception {
38 List<String> serviceInfoStrList = RedisAccessWrapper.queryMultiKeys(keyPattern);
39 List<ServiceInfo> routeInfoList = new ArrayList<>();
40 for (String serviceInfoStr : serviceInfoStrList) {
41 ServiceInfo serviceInfo = null;
43 serviceInfo = Jackson.MAPPER.readValue(serviceInfoStr, ServiceInfo.class);
44 routeInfoList.add(serviceInfo);
45 } catch (IOException e) {
46 throw new Exception("error occurred while parsing the redis json data to ServiceInfo",e);
52 public long deleteService(String key) throws Exception {
53 return RedisAccessWrapper.delete(key);
56 public long deleteMultiService(String keyPattern) throws Exception{
57 return RedisAccessWrapper.deleteMultiKeys(keyPattern);