diff --git a/src/main/java/de/fabianonline/telegram_backup/Database.java b/src/main/java/de/fabianonline/telegram_backup/Database.java index 9641ffa..9b945b6 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Database.java +++ b/src/main/java/de/fabianonline/telegram_backup/Database.java @@ -53,6 +53,7 @@ public class Database { public UserManager user_manager; public TelegramClient client; private final static Logger logger = LoggerFactory.getLogger(Database.class); + private static Database instance = null; public Database(UserManager user_manager, TelegramClient client) { this(user_manager, client, true); @@ -80,6 +81,7 @@ public class Database { } this.init(update_db); + instance = this; System.out.println("Database is ready."); } @@ -89,6 +91,11 @@ public class Database { updates.doUpdates(); } + public static Database getInstance() { + if (instance == null) throw new RuntimeException("Database is not initialized but getInstance() was called."); + return instance; + } + public void backupDatabase(int currentVersion) { String filename = String.format(Config.FILE_NAME_DB_BACKUP, currentVersion); System.out.println(" Creating a backup of your database as " + filename);