Bug 760956 - Part 2: Introduce numbers table r=rnewman draft
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 26 Feb 2016 10:09:10 -0800
changeset 335010 11af4b9b124808d5eb3710bb4ba6055ba960d482
parent 334765 fa8ab644085e169ee0bc27f6115e1ddd70a987c3
child 335011 799b112ab8854fd917345d19082706137a8c2f13
push id11698
push userahunt@mozilla.com
push dateFri, 26 Feb 2016 18:23:22 +0000
reviewersrnewman
bugs760956
milestone47.0a1
Bug 760956 - Part 2: Introduce numbers table r=rnewman We'll need this to provide a number sequence for the single-query/cursor TopSites implementation. MozReview-Commit-ID: 8m21gNmY50D
mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
@@ -480,15 +480,25 @@ public class BrowserContract {
 
     @RobocopTarget
     public static final class SuggestedSites implements CommonColumns, URLColumns {
         private SuggestedSites() {}
 
         public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "suggestedsites");
     }
 
+    public static final class Numbers {
+        private Numbers() {}
+
+        public static final String TABLE_NAME = "numbers";
+
+        public static final String POSITION = "position";
+
+        public static final int MAX_VALUE = 50;
+    }
+
     // 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";
 
     public static final String SKIP_TAB_QUEUE_FLAG = "skip_tab_queue";
 
     public static final String EXTRA_CLIENT_GUID = "org.mozilla.gecko.extra.CLIENT_ID";
 }
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
@@ -36,17 +36,17 @@ import android.os.Build;
 import android.util.Log;
 
 
 final class BrowserDatabaseHelper extends SQLiteOpenHelper {
     private static final String LOGTAG = "GeckoBrowserDBHelper";
 
     // 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 760956
     public static final String DATABASE_NAME = "browser.db";
 
     final protected Context mContext;
 
     static final String TABLE_BOOKMARKS = Bookmarks.TABLE_NAME;
     static final String TABLE_HISTORY = History.TABLE_NAME;
     static final String TABLE_FAVICONS = Favicons.TABLE_NAME;
     static final String TABLE_THUMBNAILS = Thumbnails.TABLE_NAME;
@@ -353,16 +353,17 @@ final class BrowserDatabaseHelper extend
         createOrUpdateSpecialFolder(db, Bookmarks.PLACES_FOLDER_GUID,
             R.string.bookmarks_folder_places, 0);
 
         createOrUpdateAllSpecialFolders(db);
         createSearchHistoryTable(db);
         createReadingListTable(db, TABLE_READING_LIST);
         didCreateCurrentReadingListTable = true;      // Mostly correct, in the absence of transactions.
         createReadingListIndices(db, TABLE_READING_LIST);
+        createNumbersTable(db);
     }
 
     /**
      * Copies the tabs and clients tables out of the given tabs.db file and into the destinationDB.
      *
      * @param tabsDBFile Path to existing tabs.db.
      * @param destinationDB The destination database.
      */
@@ -500,16 +501,29 @@ final class BrowserDatabaseHelper extend
         if (updated == 0) {
             db.insert(TABLE_BOOKMARKS, Bookmarks.GUID, values);
             debug("Inserted special folder: " + guid);
         } else {
             debug("Updated special folder: " + guid);
         }
     }
 
+    private void createNumbersTable(SQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + BrowserContract.Numbers.TABLE_NAME + " (POSITION INTEGER PRIMARY KEY)");
+
+        final String numbers = "(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)," +
+                "(10),(11),(12),(13),(14),(15),(16),(17),(18),(19)," +
+                "(20),(21),(22),(23),(24),(25),(26),(27),(28),(29)," +
+                "(30),(31),(32),(33),(34),(35),(36),(37),(38),(39)," +
+                "(40),(41),(42),(43),(44),(45),(46),(47),(48),(49)," +
+                "(50)";
+
+        db.execSQL("INSERT INTO " + BrowserContract.Numbers.TABLE_NAME + " VALUES " + numbers);
+    }
+
     private boolean isSpecialFolder(ContentValues values) {
         String guid = values.getAsString(Bookmarks.GUID);
         if (guid == null) {
             return false;
         }
 
         return guid.equals(Bookmarks.MOBILE_FOLDER_GUID) ||
                guid.equals(Bookmarks.MENU_FOLDER_GUID) ||
@@ -1027,16 +1041,20 @@ final class BrowserDatabaseHelper extend
 
     private void upgradeDatabaseFrom25to26(SQLiteDatabase db) {
         debug("Dropping unnecessary indices");
         db.execSQL("DROP INDEX IF EXISTS clients_guid_index");
         db.execSQL("DROP INDEX IF EXISTS thumbnails_url_index");
         db.execSQL("DROP INDEX IF EXISTS favicons_url_index");
     }
 
+    private void upgradeDatabaseFrom27to28(SQLiteDatabase db) {
+        createNumbersTable(db);
+    }
+
     private void createV19CombinedView(SQLiteDatabase db) {
         db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED);
         db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED_WITH_FAVICONS);
 
         createCombinedViewOn19(db);
     }
 
     @Override
@@ -1110,16 +1128,19 @@ final class BrowserDatabaseHelper extend
 
                 case 25:
                     upgradeDatabaseFrom24to25(db);
                     break;
 
                 case 26:
                     upgradeDatabaseFrom25to26(db);
                     break;
+
+                case 28:
+                    upgradeDatabaseFrom27to28(db);
             }
         }
 
         for (Table table : BrowserProvider.sTables) {
             table.onUpgrade(db, oldVersion, newVersion);
         }
 
         // Delete the obsolete favicon database after all other upgrades complete.