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.connection;
19 import java.io.FileNotFoundException;
20 import java.io.IOException;
21 import java.io.InputStream;
23 import org.apache.ibatis.io.Resources;
24 import org.apache.ibatis.session.SqlSessionFactory;
25 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * This class is the session factory for the database to be used in the Driver Manager.
36 public class ConnectionUtil {
38 private static SqlSessionFactory sqlSessionFactory;
40 private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionUtil.class);
43 * Get the DB session for the myBaties.
50 private ConnectionUtil() {
55 InputStream inputStream;
57 inputStream = Resources.getResourceAsStream("mybatis/configuration/configuration.xml");
58 if(null == sqlSessionFactory) {
59 LOGGER.error("begin generate");
60 sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
61 LOGGER.error("end generate = {}" , sqlSessionFactory);
63 } catch(FileNotFoundException ex) {
64 LOGGER.error("File Not Found Exception caught", ex);
66 } catch(IOException ex) {
67 LOGGER.error("IO Exception caught", ex);
68 } catch(Exception ex) {
69 LOGGER.error("some exception", ex);
73 public static SqlSessionFactory getSession() {
74 return sqlSessionFactory;