use try-with-resources

This commit is contained in:
Unpublished
2019-02-22 16:59:23 +01:00
parent 72dcc50ea1
commit 0edc7a8629
16 changed files with 117 additions and 316 deletions

View File

@@ -112,16 +112,11 @@ public abstract class DB extends RoomDatabase {
}
private static String exec(DB db, String command) {
Cursor cursor = null;
try {
cursor = db.query(command, new Object[0]);
try (Cursor cursor = db.query(command, new Object[0])) {
if (cursor != null && cursor.moveToNext())
return cursor.getString(0);
else
return null;
} finally {
if (cursor != null)
cursor.close();
}
}
@@ -358,9 +353,7 @@ public abstract class DB extends RoomDatabase {
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
Cursor cursor = null;
try {
cursor = db.query("SELECT `id`, `from` FROM message");
try (Cursor cursor = db.query("SELECT `id`, `from` FROM message")) {
while (cursor.moveToNext())
try {
long id = cursor.getLong(0);
@@ -374,9 +367,6 @@ public abstract class DB extends RoomDatabase {
Log.e(ex);
}
} finally {
if (cursor != null)
cursor.close();
}
}
})