1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 16:56:16 +00:00

Database connection will now always be closed on VM shutdown.

This commit is contained in:
Fabian Schlenz 2018-04-12 05:55:45 +02:00
parent 4d45c7f1cc
commit f434482cdf
2 changed files with 11 additions and 0 deletions

View File

@ -115,6 +115,10 @@ class CommandLineController(val options: CommandLineOptions) {
// If we reach this point, we can assume that there is an account and a database can be loaded / created. // If we reach this point, we can assume that there is an account and a database can be loaded / created.
database = Database(file_base, user_manager) database = Database(file_base, user_manager)
Runtime.getRuntime().addShutdownHook(Thread() {
database.close()
})
// Load the settings and stuff. // Load the settings and stuff.
settings = Settings(file_base, database, options) settings = Settings(file_base, database, options)

View File

@ -663,6 +663,13 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
return list return list
} }
fun close() {
logger.debug("Closing database.")
try { stmt.close() } catch (e: Throwable) { logger.debug("Exception during stmt.close()", e) }
try { conn.close() } catch (e: Throwable) { logger.debug("Exception during conn.close()", e) }
logger.debug("Database closed.")
}
abstract inner class AbstractChat { abstract inner class AbstractChat {
abstract val query: String abstract val query: String