b3db51df49aa23a79306f4ad137e7bb7a0a1772f
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / conf / HibernateSession.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.conf;
22
23 /*
24  * 
25  * 
26  * */
27 import java.util.Properties;
28
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;
35
36 @SuppressWarnings("deprecation")
37 public class HibernateSession{
38
39         private static SessionFactory logSessionFactory;
40         
41         static {
42                 try {
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);
54                 }
55         }
56         public static Session getSession() throws HibernateException {
57                 return logSessionFactory.openSession();
58         }
59
60 }