mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 00:10:31 +05:30
Merge pull request #564 from TeamPiped/session-factory
Add shutdown thread to close session factory
This commit is contained in:
commit
0af28bc2d3
@ -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,7 +12,7 @@ public class DatabaseSessionFactory {
|
||||
private static final SessionFactory sessionFactory;
|
||||
|
||||
static {
|
||||
|
||||
try {
|
||||
final Configuration configuration = new Configuration();
|
||||
|
||||
Constants.hibernateProperties.forEach(configuration::setProperty);
|
||||
@ -21,6 +21,9 @@ public class DatabaseSessionFactory {
|
||||
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…
x
Reference in New Issue
Block a user