2014-03-21 16:00:38 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.db;
|
|
|
|
|
2014-07-30 08:19:35 -07:00
|
|
|
import org.mozilla.gecko.AppConstants.Versions;
|
2014-03-21 16:00:38 -07:00
|
|
|
import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class containing methods needed to make a SQLite-based content
|
|
|
|
* provider with a database helper of type T, where one database helper is
|
|
|
|
* held per profile.
|
|
|
|
*/
|
|
|
|
public abstract class PerProfileDatabaseProvider<T extends SQLiteOpenHelper> extends AbstractPerProfileDatabaseProvider {
|
|
|
|
private PerProfileDatabases<T> databases;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected PerProfileDatabases<T> getDatabases() {
|
|
|
|
return databases;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract String getDatabaseName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an instance of the appropriate DB helper.
|
|
|
|
*
|
|
|
|
* @param context to use to create the database helper
|
|
|
|
* @param databasePath path to the DB file
|
|
|
|
* @return instance of the database helper
|
|
|
|
*/
|
|
|
|
protected abstract T createDatabaseHelper(Context context, String databasePath);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreate() {
|
|
|
|
synchronized (this) {
|
|
|
|
databases = new PerProfileDatabases<T>(
|
|
|
|
getContext(), getDatabaseName(), new DatabaseHelperFactory<T>() {
|
|
|
|
@Override
|
|
|
|
public T makeDatabaseHelper(Context context, String databasePath) {
|
2014-05-28 14:53:59 -07:00
|
|
|
final T helper = createDatabaseHelper(context, databasePath);
|
2014-07-30 08:19:35 -07:00
|
|
|
if (Versions.feature16Plus) {
|
2014-05-28 14:53:59 -07:00
|
|
|
helper.setWriteAheadLoggingEnabled(true);
|
|
|
|
}
|
|
|
|
return helper;
|
2014-03-21 16:00:38 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|