mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Merge pull request #564 from TeamPiped/session-factory
Add shutdown thread to close session factory
This commit is contained in:
commit
0af28bc2d3
2 changed files with 17 additions and 7 deletions
|
@ -74,6 +74,9 @@ public class Main {
|
|||
System.exit(1);
|
||||
}
|
||||
|
||||
// Close the HikariCP connection pool
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DatabaseSessionFactory::close));
|
||||
|
||||
if (Constants.DISABLE_TIMERS)
|
||||
return;
|
||||
|
||||
|
|
|
@ -12,15 +12,18 @@ public class DatabaseSessionFactory {
|
|||
private static final SessionFactory sessionFactory;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Configuration configuration = new Configuration();
|
||||
|
||||
final Configuration configuration = new Configuration();
|
||||
Constants.hibernateProperties.forEach(configuration::setProperty);
|
||||
configuration.configure();
|
||||
|
||||
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).buildSessionFactory();
|
||||
sessionFactory = configuration.addAnnotatedClass(User.class).addAnnotatedClass(Channel.class)
|
||||
.addAnnotatedClass(Video.class).addAnnotatedClass(PubSub.class).addAnnotatedClass(Playlist.class)
|
||||
.addAnnotatedClass(PlaylistVideo.class).addAnnotatedClass(UnauthenticatedSubscription.class).buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Session createSession() {
|
||||
|
@ -30,4 +33,8 @@ public class DatabaseSessionFactory {
|
|||
public static StatelessSession createStatelessSession() {
|
||||
return sessionFactory.openStatelessSession();
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue