Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.db; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory; |
michael@0 | 8 | |
michael@0 | 9 | import android.content.Context; |
michael@0 | 10 | import android.database.sqlite.SQLiteOpenHelper; |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * Abstract class containing methods needed to make a SQLite-based content |
michael@0 | 14 | * provider with a database helper of type T, where one database helper is |
michael@0 | 15 | * held per profile. |
michael@0 | 16 | */ |
michael@0 | 17 | public abstract class PerProfileDatabaseProvider<T extends SQLiteOpenHelper> extends AbstractPerProfileDatabaseProvider { |
michael@0 | 18 | private PerProfileDatabases<T> databases; |
michael@0 | 19 | |
michael@0 | 20 | @Override |
michael@0 | 21 | protected PerProfileDatabases<T> getDatabases() { |
michael@0 | 22 | return databases; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | protected abstract String getDatabaseName(); |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Creates and returns an instance of the appropriate DB helper. |
michael@0 | 29 | * |
michael@0 | 30 | * @param context to use to create the database helper |
michael@0 | 31 | * @param databasePath path to the DB file |
michael@0 | 32 | * @return instance of the database helper |
michael@0 | 33 | */ |
michael@0 | 34 | protected abstract T createDatabaseHelper(Context context, String databasePath); |
michael@0 | 35 | |
michael@0 | 36 | @Override |
michael@0 | 37 | public boolean onCreate() { |
michael@0 | 38 | synchronized (this) { |
michael@0 | 39 | databases = new PerProfileDatabases<T>( |
michael@0 | 40 | getContext(), getDatabaseName(), new DatabaseHelperFactory<T>() { |
michael@0 | 41 | @Override |
michael@0 | 42 | public T makeDatabaseHelper(Context context, String databasePath) { |
michael@0 | 43 | return createDatabaseHelper(context, databasePath); |
michael@0 | 44 | } |
michael@0 | 45 | }); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | return true; |
michael@0 | 49 | } |
michael@0 | 50 | } |