-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathDatabaseSessionFactory.java
More file actions
41 lines (32 loc) · 1.38 KB
/
DatabaseSessionFactory.java
File metadata and controls
41 lines (32 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package me.kavin.piped.utils;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.obj.db.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.cfg.Configuration;
public class DatabaseSessionFactory {
private static final SessionFactory sessionFactory;
static {
try {
final Configuration configuration = new Configuration();
Constants.hibernateProperties.forEach(configuration::setProperty);
configuration.configure();
sessionFactory = configuration.addAnnotatedClass(User.class).addAnnotatedClass(Channel.class)
.addAnnotatedClass(Video.class).addAnnotatedClass(PubSub.class).addAnnotatedClass(Playlist.class)
.addAnnotatedClass(PlaylistVideo.class).addAnnotatedClass(UnauthenticatedSubscription.class)
.addAnnotatedClass(PlaylistBookmark.class).buildSessionFactory();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Session createSession() {
return sessionFactory.openSession();
}
public static StatelessSession createStatelessSession() {
return sessionFactory.openStatelessSession();
}
public static void close() {
sessionFactory.close();
}
}