2 * Copyright 2017 Huawei Technologies Co., Ltd.
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.
17 package org.onap.vnfsdk.marketplace.db.impl;
19 import java.util.List;
22 import javax.persistence.PersistenceException;
24 import org.apache.ibatis.session.SqlSession;
25 import org.apache.ibatis.session.SqlSessionFactory;
26 import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil;
27 import org.onap.vnfsdk.marketplace.db.entity.PackageData;
28 import org.onap.vnfsdk.marketplace.db.inf.IMarketplaceDao;
29 import org.onap.vnfsdk.marketplace.db.mapper.IMarketplaceMapper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * This class is the implementation for the DAO Layer for Driver Manager.
40 public class MarketplaceDaoImpl implements IMarketplaceDao {
42 private static final Logger LOGGER = LoggerFactory.getLogger(MarketplaceDaoImpl.class);
44 private SqlSessionFactory sqlSessionFactory = null;
54 public MarketplaceDaoImpl() {
55 sqlSessionFactory = ConnectionUtil.getSession();
59 * get all package data.
66 public List<PackageData> getAllPackageData() {
67 SqlSession session = sqlSessionFactory.openSession();
68 List<PackageData> csars = null;
70 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
71 csars = mapper.getAllPackageData();
73 } catch(PersistenceException e) {
74 LOGGER.error("Exception caught {}", e);
82 public List<PackageData> getPackageDataSubset(Map<String, String> paramsMap) {
83 SqlSession session = sqlSessionFactory.openSession();
84 List<PackageData> csars = null;
86 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
87 csars = mapper.getPackageDataSubset(paramsMap);
89 } catch(PersistenceException e) {
90 LOGGER.error("Exception caught {}", e);
98 * saving the package data object to the DB using the mybatis.
101 * @param dirverInstance
105 public void savePackageData(PackageData lPackageData) {
106 SqlSession session = sqlSessionFactory.openSession();
108 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
109 mapper.savePackageData(lPackageData);
111 } catch(PersistenceException e) {
112 LOGGER.error("Exception caught {}", e);
120 public List<PackageData> getPackageData(String csarId) {
121 SqlSession session = sqlSessionFactory.openSession();
122 List<PackageData> csars = null;
124 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
125 csars = mapper.getPackageData(csarId);
127 } catch(PersistenceException e) {
128 LOGGER.error("Exception caught {}", e);
136 public void deletePackageData(String csarId) {
137 SqlSession session = sqlSessionFactory.openSession();
139 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
140 mapper.deletePackageData(csarId);
142 } catch(PersistenceException e) {
143 LOGGER.error("Exception caught {}", e);;
151 public void updatePackageData(PackageData oPackageData) {
152 SqlSession session = sqlSessionFactory.openSession();
154 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
155 mapper.updatePackageData(oPackageData);
157 } catch(PersistenceException e) {
158 LOGGER.error("Exception caught {}", e);