1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-25 14:25:35 +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.
database = Database(file_base, user_manager)
Runtime.getRuntime().addShutdownHook(Thread() {
database.close()
})
// Load the settings and stuff.
settings = Settings(file_base, database, options)

View File

@ -662,6 +662,13 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
rs.close()
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 {