Search in sources :

Example 1 with BriteDatabase

use of com.squareup.sqlbrite3.BriteDatabase in project sqlbrite by square.

the class BriteDatabaseTest method setUp.

@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);
}
Also used : Configuration(android.arch.persistence.db.SupportSQLiteOpenHelper.Configuration) Query(com.squareup.sqlbrite3.SqlBrite.Query) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) Factory(android.arch.persistence.db.SupportSQLiteOpenHelper.Factory) FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) Observable(io.reactivex.Observable) FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) SupportSQLiteOpenHelper(android.arch.persistence.db.SupportSQLiteOpenHelper) ObservableTransformer(io.reactivex.ObservableTransformer) Before(org.junit.Before)

Example 2 with BriteDatabase

use of com.squareup.sqlbrite3.BriteDatabase in project sqlbrite by square.

the class DbModule method provideDatabase.

@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;
}
Also used : FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) SupportSQLiteOpenHelper(android.arch.persistence.db.SupportSQLiteOpenHelper) Configuration(android.arch.persistence.db.SupportSQLiteOpenHelper.Configuration) FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) Factory(android.arch.persistence.db.SupportSQLiteOpenHelper.Factory) BriteDatabase(com.squareup.sqlbrite3.BriteDatabase) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 3 with BriteDatabase

use of com.squareup.sqlbrite3.BriteDatabase in project Shuttle by timusus.

the class InclExclHelper method addToInclExcl.

public static void addToInclExcl(List<InclExclItem> inclExclItems) {
    BriteDatabase db = DataManager.getInstance().getInclExclDatabase();
    BriteDatabase.Transaction transaction = db.newTransaction();
    try {
        Stream.of(inclExclItems).map(inclExclItem -> {
            ContentValues contentValues = new ContentValues(2);
            contentValues.put(InclExclDbOpenHelper.COLUMN_PATH, inclExclItem.path);
            contentValues.put(InclExclDbOpenHelper.COLUMN_TYPE, inclExclItem.type);
            return contentValues;
        }).forEach(contentValues -> db.insert(InclExclDbOpenHelper.TABLE_NAME, contentValues));
        transaction.markSuccessful();
    } finally {
        transaction.end();
    }
}
Also used : Song(com.simplecity.amp_library.model.Song) List(java.util.List) BriteDatabase(com.squareup.sqlbrite2.BriteDatabase) Stream(com.annimon.stream.Stream) DataManager(com.simplecity.amp_library.utils.DataManager) ContentValues(android.content.ContentValues) InclExclItem(com.simplecity.amp_library.model.InclExclItem) ContentValues(android.content.ContentValues) BriteDatabase(com.squareup.sqlbrite2.BriteDatabase)

Aggregations

SupportSQLiteOpenHelper (android.arch.persistence.db.SupportSQLiteOpenHelper)2 Configuration (android.arch.persistence.db.SupportSQLiteOpenHelper.Configuration)2 Factory (android.arch.persistence.db.SupportSQLiteOpenHelper.Factory)2 FrameworkSQLiteOpenHelperFactory (android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory)2 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)1 ContentValues (android.content.ContentValues)1 Stream (com.annimon.stream.Stream)1 InclExclItem (com.simplecity.amp_library.model.InclExclItem)1 Song (com.simplecity.amp_library.model.Song)1 DataManager (com.simplecity.amp_library.utils.DataManager)1 BriteDatabase (com.squareup.sqlbrite2.BriteDatabase)1 BriteDatabase (com.squareup.sqlbrite3.BriteDatabase)1 Query (com.squareup.sqlbrite3.SqlBrite.Query)1 Provides (dagger.Provides)1 Observable (io.reactivex.Observable)1 ObservableTransformer (io.reactivex.ObservableTransformer)1 List (java.util.List)1 Singleton (javax.inject.Singleton)1 Before (org.junit.Before)1