Bug 1250707 - Create url annotations table. r=sebastian

MozReview-Commit-ID: BHtwkdrpfYi
This commit is contained in:
Michael Comella 2016-02-25 12:49:45 -08:00
parent 64b443d58b
commit 12967d0f11
2 changed files with 55 additions and 2 deletions

View File

@ -485,6 +485,32 @@ public class BrowserContract {
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "suggestedsites");
}
public static final class UrlAnnotations implements CommonColumns, DateSyncColumns {
private UrlAnnotations() {}
public static final String TABLE_NAME = "urlannotations";
public static final String URL = "url";
public static final String KEY = "key";
public static final String VALUE = "value";
public static final String SYNC_STATUS = "sync_status";
public enum SyncStatus {
// We use a parameter, rather than ordinal(), as defensive coding: we can't let the
// ordinal values change because we've already stored values into the DB.
NEW (0);
// Value stored into the database for this column.
private final int dbValue;
SyncStatus(final int dbValue) {
this.dbValue = dbValue;
}
public int getDBValue() { return dbValue; }
}
}
// We refer to the service by name to decouple services from the rest of the code base.
public static final String TAB_RECEIVED_SERVICE_CLASS_NAME = "org.mozilla.gecko.tabqueue.TabReceivedService";

View File

@ -6,7 +6,6 @@
package org.mozilla.gecko.db;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -19,6 +18,7 @@ import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
import org.mozilla.gecko.db.BrowserContract.SearchHistory;
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserContract.UrlAnnotations;
import org.mozilla.gecko.util.FileUtils;
import static org.mozilla.gecko.db.DBUtils.qualifyColumn;
@ -41,7 +41,7 @@ final class BrowserDatabaseHelper extends SQLiteOpenHelper {
// Replace the Bug number below with your Bug that is conducting a DB upgrade, as to force a merge conflict with any
// other patches that require a DB upgrade.
public static final int DATABASE_VERSION = 27; // Bug 826400
public static final int DATABASE_VERSION = 28; // Bug 1250707
public static final String DATABASE_NAME = "browser.db";
final protected Context mContext;
@ -358,6 +358,7 @@ final class BrowserDatabaseHelper extends SQLiteOpenHelper {
createReadingListTable(db, TABLE_READING_LIST);
didCreateCurrentReadingListTable = true; // Mostly correct, in the absence of transactions.
createReadingListIndices(db, TABLE_READING_LIST);
createUrlAnnotationsTable(db);
}
/**
@ -455,6 +456,23 @@ final class BrowserDatabaseHelper extends SQLiteOpenHelper {
+ ReadingListItems.CONTENT_STATUS + ")");
}
private void createUrlAnnotationsTable(final SQLiteDatabase db) {
debug("Creating " + UrlAnnotations.TABLE_NAME + " table");
db.execSQL("CREATE TABLE " + UrlAnnotations.TABLE_NAME + "(" +
UrlAnnotations._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
UrlAnnotations.URL + " TEXT NOT NULL, " +
UrlAnnotations.KEY + " TEXT NOT NULL, " +
UrlAnnotations.VALUE + " TEXT, " +
UrlAnnotations.DATE_CREATED + " INTEGER NOT NULL, " +
UrlAnnotations.DATE_MODIFIED + " INTEGER NOT NULL, " +
UrlAnnotations.SYNC_STATUS + " TINYINT NOT NULL DEFAULT " + UrlAnnotations.SyncStatus.NEW.getDBValue() +
" );");
db.execSQL("CREATE INDEX idx_url_annotations_url_key ON " +
UrlAnnotations.TABLE_NAME + "(" + UrlAnnotations.URL + ", " + UrlAnnotations.KEY + ")");
}
private void createOrUpdateAllSpecialFolders(SQLiteDatabase db) {
createOrUpdateSpecialFolder(db, Bookmarks.MOBILE_FOLDER_GUID,
R.string.bookmarks_folder_mobile, 0);
@ -1032,6 +1050,11 @@ final class BrowserDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("DROP INDEX IF EXISTS favicons_url_index");
}
private void upgradeDatabaseFrom27to28(final SQLiteDatabase db) {
debug("Adding url annotations table");
createUrlAnnotationsTable(db);
}
private void createV19CombinedView(SQLiteDatabase db) {
db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED);
db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED_WITH_FAVICONS);
@ -1115,6 +1138,10 @@ final class BrowserDatabaseHelper extends SQLiteOpenHelper {
case 26:
upgradeDatabaseFrom25to26(db);
break;
case 28:
upgradeDatabaseFrom27to28(db);
break;
}
}