mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 08:46:15 +00:00
Database is now a singleton.
This commit is contained in:
parent
c5921304ed
commit
a2224b326d
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user