Добавлен Hybernate и реализован прототип БД
This commit is contained in:
33
src/main/java/com/rosetta/im/database/HibernateUtil.java
Normal file
33
src/main/java/com/rosetta/im/database/HibernateUtil.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.rosetta.im.database;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
public class HibernateUtil {
|
||||
private static final SessionFactory sessionFactory;
|
||||
|
||||
static {
|
||||
try {
|
||||
sessionFactory = new Configuration().configure().buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
throw new ExceptionInInitializerError("Error initializing Hibernate: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public static Session getCurrentSession() {
|
||||
return sessionFactory.getCurrentSession();
|
||||
}
|
||||
|
||||
public static Session openSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user