RHSRV-3 - Implement Hibernate PSQL with basic /register API
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
44
src/main/java/wtf/beatrice/releasehive/HibernateManager.java
Normal file
44
src/main/java/wtf/beatrice/releasehive/HibernateManager.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package wtf.beatrice.releasehive;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
public class HibernateManager
|
||||
{
|
||||
private static HibernateManager instance;
|
||||
private static Session session;
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
|
||||
private HibernateManager() {
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
if(session != null && !session.isOpen()) {
|
||||
session.close();
|
||||
}
|
||||
if(sessionFactory != null && sessionFactory.isOpen()) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Session getSession() {
|
||||
if(session != null && (!session.isOpen() || !session.isConnected())) {
|
||||
session.close();
|
||||
}
|
||||
|
||||
session = sessionFactory.openSession();
|
||||
return session;
|
||||
}
|
||||
|
||||
public static Transaction beginTransaction() {
|
||||
return getSession().beginTransaction();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user