DBHelper: don't wrap entire func bodies in ifs

This removes tons of unnecessary indenting. Do it in smaller functions
too for consistency.
This commit is contained in:
Daniel Martí 2016-04-23 15:40:09 +01:00
parent 7f2a811541
commit 6a0eec1262

View File

@ -116,7 +116,9 @@ class DBHelper extends SQLiteOpenHelper {
}
private void populateRepoNames(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 37) {
if (oldVersion >= 37) {
return;
}
Utils.debugLog(TAG, "Populating repo names from the url");
final String[] columns = {"address", "_id"};
Cursor cursor = db.query(TABLE_REPO, columns,
@ -139,10 +141,11 @@ class DBHelper extends SQLiteOpenHelper {
cursor.close();
}
}
}
private void renameRepoId(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 36 && !columnExists(db, TABLE_REPO, "_id")) {
if (oldVersion >= 36 || columnExists(db, TABLE_REPO, "_id")) {
return;
}
Utils.debugLog(TAG, "Renaming " + TABLE_REPO + ".id to _id");
db.beginTransaction();
@ -190,7 +193,6 @@ class DBHelper extends SQLiteOpenHelper {
}
db.endTransaction();
}
}
@Override
public void onCreate(SQLiteDatabase db) {
@ -299,7 +301,9 @@ class DBHelper extends SQLiteOpenHelper {
* key in sqlite - table must be recreated).
*/
private void migrateRepoTable(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 20) {
if (oldVersion >= 20) {
return;
}
List<Repo> oldrepos = new ArrayList<>();
Cursor cursor = db.query(TABLE_REPO,
new String[] {"address", "inuse", "pubkey"},
@ -330,7 +334,6 @@ class DBHelper extends SQLiteOpenHelper {
db.insert(TABLE_REPO, null, values);
}
}
}
private void insertNameAndDescription(SQLiteDatabase db,
int addressResId, int nameResId, int descriptionResId) {
@ -350,7 +353,9 @@ class DBHelper extends SQLiteOpenHelper {
private void addNameAndDescriptionToRepo(SQLiteDatabase db, int oldVersion) {
boolean nameExists = columnExists(db, TABLE_REPO, "name");
boolean descriptionExists = columnExists(db, TABLE_REPO, "description");
if (oldVersion < 21 && !(nameExists && descriptionExists)) {
if (oldVersion >= 21 || (nameExists && descriptionExists)) {
return;
}
if (!nameExists) {
db.execSQL("alter table " + TABLE_REPO + " add column name text");
}
@ -365,7 +370,6 @@ class DBHelper extends SQLiteOpenHelper {
R.string.guardianproject_repo_name, R.string.guardianproject_repo_description);
insertNameAndDescription(db, R.string.guardianproject_archive_address,
R.string.guardianproject_archive_name, R.string.guardianproject_archive_description);
}
}
@ -374,7 +378,9 @@ class DBHelper extends SQLiteOpenHelper {
* calculate its fingerprint and save it to the database.
*/
private void addFingerprintToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 44) {
if (oldVersion >= 44) {
return;
}
if (!columnExists(db, TABLE_REPO, "fingerprint")) {
db.execSQL("alter table " + TABLE_REPO + " add column fingerprint text");
}
@ -401,36 +407,41 @@ class DBHelper extends SQLiteOpenHelper {
db.update(TABLE_REPO, values, "address = ?", new String[] {repo.address});
}
}
}
private void addMaxAgeToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 30 && !columnExists(db, TABLE_REPO, "maxage")) {
db.execSQL("alter table " + TABLE_REPO + " add column maxage integer not null default 0");
if (oldVersion >= 30 || columnExists(db, TABLE_REPO, "maxage")) {
return;
}
db.execSQL("alter table " + TABLE_REPO + " add column maxage integer not null default 0");
}
private void addVersionToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 33 && !columnExists(db, TABLE_REPO, "version")) {
db.execSQL("alter table " + TABLE_REPO + " add column version integer not null default 0");
if (oldVersion >= 33 || columnExists(db, TABLE_REPO, "version")) {
return;
}
db.execSQL("alter table " + TABLE_REPO + " add column version integer not null default 0");
}
private void addLastUpdatedToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 35 && !columnExists(db, TABLE_REPO, "lastUpdated")) {
if (oldVersion >= 35 || columnExists(db, TABLE_REPO, "lastUpdated")) {
return;
}
Utils.debugLog(TAG, "Adding lastUpdated column to " + TABLE_REPO);
db.execSQL("Alter table " + TABLE_REPO + " add column lastUpdated string");
}
}
private void addIsSwapToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 47 && !columnExists(db, TABLE_REPO, "isSwap")) {
if (oldVersion >= 47 || columnExists(db, TABLE_REPO, "isSwap")) {
return;
}
Utils.debugLog(TAG, "Adding isSwap field to " + TABLE_REPO + " table in db.");
db.execSQL("alter table " + TABLE_REPO + " add column isSwap boolean default 0;");
}
}
private void addCredentialsToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 52) {
if (oldVersion >= 52) {
return;
}
if (!columnExists(db, TABLE_REPO, "username")) {
Utils.debugLog(TAG, "Adding username field to " + TABLE_REPO + " table in db.");
db.execSQL("alter table " + TABLE_REPO + " add column username string;");
@ -441,49 +452,55 @@ class DBHelper extends SQLiteOpenHelper {
db.execSQL("alter table " + TABLE_REPO + " add column password string;");
}
}
}
private void addChangelogToApp(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 48 && !columnExists(db, TABLE_APP, "changelogURL")) {
if (oldVersion >= 48 || columnExists(db, TABLE_APP, "changelogURL")) {
return;
}
Utils.debugLog(TAG, "Adding changelogURL column to " + TABLE_APP);
db.execSQL("alter table " + TABLE_APP + " add column changelogURL text");
}
}
private void addIconUrlLargeToApp(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 49 && !columnExists(db, TABLE_APP, "iconUrlLarge")) {
if (oldVersion >= 49 || columnExists(db, TABLE_APP, "iconUrlLarge")) {
return;
}
Utils.debugLog(TAG, "Adding iconUrlLarge columns to " + TABLE_APP);
db.execSQL("alter table " + TABLE_APP + " add column iconUrlLarge text");
}
}
private void updateIconUrlLarge(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 50) {
if (oldVersion >= 50) {
return;
}
Utils.debugLog(TAG, "Recalculating app icon URLs so that the newly added large icons will get updated.");
AppProvider.UpgradeHelper.updateIconUrls(context, db);
clearRepoEtags(db);
}
}
private void addAuthorToApp(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 53 && !columnExists(db, TABLE_APP, "author")) {
if (oldVersion >= 53) {
return;
}
if (!columnExists(db, TABLE_APP, "author")) {
Utils.debugLog(TAG, "Adding author column to " + TABLE_APP);
db.execSQL("alter table " + TABLE_APP + " add column author text");
}
if (oldVersion < 53 && !columnExists(db, TABLE_APP, "email")) {
if (!columnExists(db, TABLE_APP, "email")) {
Utils.debugLog(TAG, "Adding email column to " + TABLE_APP);
db.execSQL("alter table " + TABLE_APP + " add column email text");
}
}
private void useMaxValueInMaxSdkVersion(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 54) {
if (oldVersion >= 54) {
return;
}
Utils.debugLog(TAG, "Converting maxSdkVersion value 0 to " + Byte.MAX_VALUE);
ContentValues values = new ContentValues();
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, Byte.MAX_VALUE);
db.update(TABLE_APK, values, ApkProvider.DataColumns.MAX_SDK_VERSION + " < 1", null);
}
}
/**
* By clearing the etags stored in the repo table, it means that next time the user updates
@ -501,7 +518,9 @@ class DBHelper extends SQLiteOpenHelper {
// was is specified by the user. We don't want to weely-neely nuke that data.
// and the new way to deal with changes to the table structure is to add a
// if (oldVersion < x && !columnExists(...) and then alter the table as required.
if (oldVersion < 42) {
if (oldVersion >= 42) {
return;
}
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit()
.putBoolean("triedEmptyUpdate", false).commit();
db.execSQL("drop table " + TABLE_APP);
@ -509,7 +528,6 @@ class DBHelper extends SQLiteOpenHelper {
clearRepoEtags(db);
createAppApk(db);
}
}
private static void createAppApk(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_APP);
@ -527,11 +545,12 @@ class DBHelper extends SQLiteOpenHelper {
// If any column was added or removed, just drop the table, create it
// again and let the cache be filled from scratch again.
private void recreateInstalledCache(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 51) {
if (oldVersion >= 51) {
return;
}
db.execSQL(DROP_TABLE_INSTALLED_APP);
createInstalledApp(db);
}
}
private static boolean columnExists(SQLiteDatabase db,
String table, String column) {