* metadata-mapping * Update README.md * add class diagram * update README.md * fix identation * Update pom.xml * fix indentation * fix ci * remove e.printstack * fix ci * update class diagram * fix ci * fix ci * fix sc * fix smells * Update DatabaseUtil.java * fix coverage * Update DatabaseUtil.java * Update DatabaseUtil.java * Update DatabaseUtil.java * Update metadata-mapping/README.md Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com> * fix review * fix review * Update App.java * Update App.java * fix review Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
45 lines
921 B
Java
45 lines
921 B
Java
package com.iluwatar.metamapping.utils;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.cfg.Configuration;
|
|
|
|
/**
|
|
* Manage hibernate.
|
|
*/
|
|
@Slf4j
|
|
public class HibernateUtil {
|
|
|
|
private static final SessionFactory sessionFactory = buildSessionFactory();
|
|
|
|
/**
|
|
* Hide constructor.
|
|
*/
|
|
private HibernateUtil() {}
|
|
|
|
/**
|
|
* Build session factory.
|
|
* @return session factory
|
|
*/
|
|
private static SessionFactory buildSessionFactory() {
|
|
// Create the SessionFactory from hibernate.cfg.xml
|
|
return new Configuration().configure().buildSessionFactory();
|
|
}
|
|
|
|
/**
|
|
* Get session factory.
|
|
* @return session factory
|
|
*/
|
|
public static SessionFactory getSessionFactory() {
|
|
return sessionFactory;
|
|
}
|
|
|
|
/**
|
|
* Close session factory.
|
|
*/
|
|
public static void shutdown() {
|
|
// Close caches and connection pools
|
|
getSessionFactory().close();
|
|
}
|
|
|
|
} |