2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.policy.conf;
27 import java.util.Properties;
29 import org.hibernate.HibernateException;
30 import org.hibernate.Session;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.cfg.Configuration;
33 import org.openecomp.policy.controller.PolicyController;
34 import org.openecomp.policy.rest.jpa.SystemLogDB;
36 @SuppressWarnings("deprecation")
37 public class HibernateSession{
39 private static SessionFactory logSessionFactory;
43 Properties prop= new Properties();
44 prop.setProperty("hibernate.connection.url", PolicyController.logdbUrl);
45 prop.setProperty("hibernate.connection.username", PolicyController.logdbUserName);
46 prop.setProperty("hibernate.connection.password", PolicyController.logdbPassword);
47 prop.setProperty("dialect", PolicyController.logdbDialect);
48 prop.setProperty("hibernate.connection.driver_class", PolicyController.logdbDriver);
49 prop.setProperty("show_sql", "false");
50 logSessionFactory = new Configuration().addPackage("org.openecomp.policy.*").addProperties(prop)
51 .addAnnotatedClass(SystemLogDB.class).buildSessionFactory();
52 } catch (Throwable ex) {
53 throw new ExceptionInInitializerError(ex);
56 public static Session getSession() throws HibernateException {
57 return logSessionFactory.openSession();