feature: Metadata Mapping pattern (#1932)
* 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>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user