From 7d984dcf6372a17270007d8fb05850dbeb86ea74 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Thu, 25 Feb 2016 12:49:45 -0800 Subject: [PATCH] Bug 1250707 - Create url annotations table. r=sebastian MozReview-Commit-ID: BHtwkdrpfYi --HG-- extra : rebase_source : f191d3687be00b6546b2fefa5b4f16b1f771ce32 --- .../org/mozilla/gecko/db/BrowserContract.java | 26 ++++++++++++++++ .../gecko/db/BrowserDatabaseHelper.java | 31 +++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java index f174c81bddb0..e6ae597b55e1 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java @@ -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"; diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java index 85004224455b..8167ef800ce8 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java @@ -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; } }