Backup DB is now closed if backup fails due to exception

This commit is contained in:
Rsl1122 2018-05-25 09:55:08 +03:00
parent 1e75a665b9
commit 4291a94cc6

View File

@ -30,17 +30,23 @@ public class ManageUtils {
* @param copyFromDB Database you want to backup. * @param copyFromDB Database you want to backup.
*/ */
public static void backup(String dbName, Database copyFromDB) throws DBInitException, SQLException { public static void backup(String dbName, Database copyFromDB) throws DBInitException, SQLException {
SQLiteDB backupDB = null;
try {
String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-"); String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-");
String fileName = dbName + "-backup-" + timeStamp; String fileName = dbName + "-backup-" + timeStamp;
SQLiteDB backupDB = new SQLiteDB(fileName); backupDB = new SQLiteDB(fileName);
Collection<UUID> uuids = ManageUtils.getUUIDS(copyFromDB); Collection<UUID> uuids = ManageUtils.getUUIDS(copyFromDB);
if (uuids.isEmpty()) { if (uuids.isEmpty()) {
return; return;
} }
backupDB.init(); backupDB.init();
clearAndCopy(backupDB, copyFromDB); clearAndCopy(backupDB, copyFromDB);
} finally {
if (backupDB != null) {
backupDB.close(); backupDB.close();
} }
}
}
/** /**
* Get the saved UUIDs in a hashset * Get the saved UUIDs in a hashset