Java源码示例:android.arch.persistence.db.SupportSQLiteOpenHelper
示例1
@Before public void setUp() throws IOException {
Configuration configuration = Configuration.builder(InstrumentationRegistry.getContext())
.callback(testDb)
.name(dbFolder.newFile().getPath())
.build();
Factory factory = new FrameworkSQLiteOpenHelperFactory();
SupportSQLiteOpenHelper helper = factory.create(configuration);
real = helper.getWritableDatabase();
SqlBrite.Logger logger = new SqlBrite.Logger() {
@Override public void log(String message) {
logs.add(message);
}
};
ObservableTransformer<Query, Query> queryTransformer =
new ObservableTransformer<Query, Query>() {
@Override public ObservableSource<Query> apply(Observable<Query> upstream) {
return upstream.takeUntil(killSwitch);
}
};
db = new BriteDatabase(helper, logger, scheduler, queryTransformer);
}
示例2
BriteDatabase(SupportSQLiteOpenHelper helper, Logger logger, Scheduler scheduler,
ObservableTransformer<Query, Query> queryTransformer) {
this.helper = helper;
this.logger = logger;
this.scheduler = scheduler;
this.queryTransformer = queryTransformer;
}
示例3
@Before public void setUp() {
Configuration configuration = Configuration.builder(InstrumentationRegistry.getContext())
.callback(new TestDb())
.build();
Factory factory = new FrameworkSQLiteOpenHelperFactory();
SupportSQLiteOpenHelper helper = factory.create(configuration);
SqlBrite sqlBrite = new SqlBrite.Builder().build();
db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.trampoline());
}
示例4
@Provides @Singleton BriteDatabase provideDatabase(SqlBrite sqlBrite, Application application) {
Configuration configuration = Configuration.builder(application)
.name("todo.db")
.callback(new DbCallback())
.build();
Factory factory = new FrameworkSQLiteOpenHelperFactory();
SupportSQLiteOpenHelper helper = factory.create(configuration);
BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
db.setLoggingEnabled(true);
return db;
}
示例5
RoomSqliteDataRetriever(SupportSQLiteOpenHelper sqliteHelper) {
mSqliteHelper = sqliteHelper;
}
示例6
/**
* Wrap a {@link SupportSQLiteOpenHelper} for observable queries.
* <p>
* While not strictly required, instances of this class assume that they will be the only ones
* interacting with the underlying {@link SupportSQLiteOpenHelper} and it is required for
* automatic notifications of table changes to work. See {@linkplain BriteDatabase#createQuery the
* <code>query</code> method} for more information on that behavior.
*
* @param scheduler The {@link Scheduler} on which items from {@link BriteDatabase#createQuery}
* will be emitted.
*/
@CheckResult @NonNull public BriteDatabase wrapDatabaseHelper(
@NonNull SupportSQLiteOpenHelper helper,
@NonNull Scheduler scheduler) {
return new BriteDatabase(helper, logger, scheduler, queryTransformer);
}