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;
21 import javax.persistence.PersistenceException;
23 import org.apache.ibatis.session.SqlSession;
24 import org.apache.ibatis.session.SqlSessionFactory;
25 import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil;
26 import org.onap.vnfsdk.marketplace.db.entity.PackageData;
27 import org.onap.vnfsdk.marketplace.db.inf.IMarketplaceDao;
28 import org.onap.vnfsdk.marketplace.db.mapper.IMarketplaceMapper;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * This class is the implementation for the DAO Layer for Driver Manager.
39 public class MarketplaceDaoImpl implements IMarketplaceDao {
41 private static final Logger LOGGER = LoggerFactory.getLogger(MarketplaceDaoImpl.class);
43 private SqlSessionFactory sqlSessionFactory = null;
53 public MarketplaceDaoImpl() {
54 sqlSessionFactory = ConnectionUtil.getSession();
58 * get all package data.
65 public List<PackageData> getAllPackageData() {
66 SqlSession session = sqlSessionFactory.openSession();
67 List<PackageData> csars = null;
69 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
70 csars = mapper.getAllPackageData();
72 } catch(PersistenceException e) {
73 LOGGER.error("Exception caught {}", e);
81 * saving the package data object to the DB using the mybatis.
84 * @param dirverInstance
88 public void savePackageData(PackageData lPackageData) {
89 SqlSession session = sqlSessionFactory.openSession();
91 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
92 mapper.savePackageData(lPackageData);
94 } catch(PersistenceException e) {
95 LOGGER.error("Exception caught {}", e);
103 public List<PackageData> getPackageData(String csarId) {
104 SqlSession session = sqlSessionFactory.openSession();
105 List<PackageData> csars = null;
107 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
108 csars = mapper.getPackageData(csarId);
110 } catch(PersistenceException e) {
111 LOGGER.error("Exception caught {}", e);
119 public void deletePackageData(String csarId) {
120 SqlSession session = sqlSessionFactory.openSession();
122 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
123 mapper.deletePackageData(csarId);
125 } catch(PersistenceException e) {
126 LOGGER.error("Exception caught {}", e);;
134 public void updatePackageData(PackageData oPackageData) {
135 SqlSession session = sqlSessionFactory.openSession();
137 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
138 mapper.updatePackageData(oPackageData);
140 } catch(PersistenceException e) {
141 LOGGER.error("Exception caught {}", e);