55import android .arch .persistence .db .SupportSQLiteOpenHelper .Configuration ;
66import android .content .Context ;
77
8+ import java .util .Collections ;
9+
810import io .requery .android .database .DatabaseErrorHandler ;
911
1012/**
1315 */
1416@ SuppressWarnings ("unused" )
1517public final class RequerySQLiteOpenHelperFactory implements SupportSQLiteOpenHelper .Factory {
18+ private final Iterable <ConfigurationOptions > configurationOptions ;
19+
20+ @ SuppressWarnings ("WeakerAccess" )
21+ public RequerySQLiteOpenHelperFactory (Iterable <ConfigurationOptions > configurationOptions ) {
22+ this .configurationOptions = configurationOptions ;
23+ }
24+
25+ public RequerySQLiteOpenHelperFactory () {
26+ this (Collections .<ConfigurationOptions >emptyList ());
27+ }
1628
1729 @ Override
1830 public SupportSQLiteOpenHelper create (Configuration config ) {
19- return new CallbackSQLiteOpenHelper (config .context , config .name , config .callback );
31+ return new CallbackSQLiteOpenHelper (config .context , config .name , config .callback , configurationOptions );
2032 }
2133
2234 private static final class CallbackSQLiteOpenHelper extends SQLiteOpenHelper {
2335
2436 private final Callback callback ;
37+ private final Iterable <ConfigurationOptions > configurationOptions ;
2538
26- CallbackSQLiteOpenHelper (Context context , String name , Callback cb ) {
39+ CallbackSQLiteOpenHelper (Context context , String name , Callback cb , Iterable < ConfigurationOptions > ops ) {
2740 super (context , name , null , cb .version , new CallbackDatabaseErrorHandler (cb ));
2841 this .callback = cb ;
42+ this .configurationOptions = ops ;
2943 }
3044
3145 @ Override
@@ -52,6 +66,16 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
5266 public void onOpen (SQLiteDatabase db ) {
5367 callback .onOpen (db );
5468 }
69+
70+ @ Override protected SQLiteDatabaseConfiguration createConfiguration (String path , int openFlags ) {
71+ SQLiteDatabaseConfiguration config = super .createConfiguration (path , openFlags );
72+
73+ for (ConfigurationOptions option : configurationOptions ) {
74+ config = option .apply (config );
75+ }
76+
77+ return config ;
78+ }
5579 }
5680
5781 private static final class CallbackDatabaseErrorHandler implements DatabaseErrorHandler {
@@ -67,4 +91,8 @@ public void onCorruption(SQLiteDatabase db) {
6791 callback .onCorruption (db );
6892 }
6993 }
94+
95+ public interface ConfigurationOptions {
96+ SQLiteDatabaseConfiguration apply (SQLiteDatabaseConfiguration configuration );
97+ }
7098}
0 commit comments