2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.conf;
27 import java.util.Properties;
29 import org.hibernate.Session;
30 import org.hibernate.SessionFactory;
31 import org.hibernate.cfg.Configuration;
32 import org.onap.policy.common.logging.flexlogger.FlexLogger;
33 import org.onap.policy.common.logging.flexlogger.Logger;
34 import org.onap.policy.controller.PolicyController;
35 import org.onap.policy.rest.jpa.SystemLogDB;
37 @SuppressWarnings("deprecation")
38 public class HibernateSession {
40 private static final Logger LOGGER = FlexLogger.getLogger(HibernateSession.class);
42 private static SessionFactory logSessionFactory;
46 Properties prop = new Properties();
47 prop.setProperty("hibernate.connection.url", PolicyController.getLogdbUrl());
48 prop.setProperty("hibernate.connection.username", PolicyController.getLogdbUserName());
49 prop.setProperty("hibernate.connection.password", PolicyController.getLogdbPassword());
50 prop.setProperty("dialect", PolicyController.getLogdbDialect());
51 prop.setProperty("hibernate.connection.driver_class", PolicyController.getLogdbDriver());
52 prop.setProperty("show_sql", "false");
53 logSessionFactory = new Configuration().addPackage("org.onap.policy.*").addProperties(prop)
54 .addAnnotatedClass(SystemLogDB.class).buildSessionFactory();
55 } catch (Exception ex) {
56 LOGGER.error("Exception Occured while creating Log database Hibernate session" + ex);
60 private HibernateSession() {
62 * empty implementation
66 public static Session getSession() {
67 return logSessionFactory.openSession();
70 public static void setSession(SessionFactory logSessionFactory1) {
71 logSessionFactory = logSessionFactory1;