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;
46 private static final String EXCEPTION = "Exception caught {}";
56 public MarketplaceDaoImpl() {
57 sqlSessionFactory = ConnectionUtil.getSession();
61 * get all package data.
68 public List<PackageData> getAllPackageData() {
69 SqlSession session = sqlSessionFactory.openSession();
70 List<PackageData> csars = null;
72 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
73 csars = mapper.getAllPackageData();
75 } catch(PersistenceException e) {
76 LOGGER.error(EXCEPTION, e);
84 public List<PackageData> getPackageDataSubset(Map<String, String> paramsMap) {
85 SqlSession session = sqlSessionFactory.openSession();
86 List<PackageData> csars = null;
88 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
89 csars = mapper.getPackageDataSubset(paramsMap);
91 } catch(PersistenceException e) {
92 LOGGER.error(EXCEPTION, e);
100 * saving the package data object to the DB using the mybatis.
103 * @param dirverInstance
107 public void savePackageData(PackageData lPackageData) {
108 SqlSession session = sqlSessionFactory.openSession();
110 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
111 mapper.savePackageData(lPackageData);
113 } catch(PersistenceException e) {
114 LOGGER.error(EXCEPTION, e);
122 public List<PackageData> getPackageData(String csarId) {
123 SqlSession session = sqlSessionFactory.openSession();
124 List<PackageData> csars = null;
126 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
127 csars = mapper.getPackageData(csarId);
129 } catch(PersistenceException e) {
130 LOGGER.error(EXCEPTION, e);
138 public void deletePackageData(String csarId) {
139 SqlSession session = sqlSessionFactory.openSession();
141 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
142 mapper.deletePackageData(csarId);
144 } catch(PersistenceException e) {
145 LOGGER.error(EXCEPTION, e);
153 public void updatePackageData(PackageData oPackageData) {
154 SqlSession session = sqlSessionFactory.openSession();
156 IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
157 mapper.updatePackageData(oPackageData);
159 } catch(PersistenceException e) {
160 LOGGER.error(EXCEPTION, e);