Search in sources :

Example 36 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method shouldUseSpecifiedTypeMappingFinder.

@Test
public void shouldUseSpecifiedTypeMappingFinder() throws NoSuchFieldException, IllegalAccessException {
    TypeMappingFinder typeMappingFinder = mock(TypeMappingFinder.class);
    DefaultStorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).typeMappingFinder(typeMappingFinder).build();
    assertThat(getTypeMappingFinder(storIOSQLite)).isEqualTo(typeMappingFinder);
}
Also used : TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) Test(org.junit.Test)

Example 37 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method deprecatedInternalImplShouldReturnSentToConstructorTypeMapping.

@Test
public void deprecatedInternalImplShouldReturnSentToConstructorTypeMapping() throws NoSuchFieldException, IllegalAccessException {
    TypeMappingFinder typeMappingFinder = mock(TypeMappingFinder.class);
    TestDefaultStorIOSQLite storIOSQLite = new TestDefaultStorIOSQLite(sqLiteOpenHelper, typeMappingFinder);
    assertThat(storIOSQLite.typeMappingFinder()).isSameAs(typeMappingFinder);
}
Also used : TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) Test(org.junit.Test)

Example 38 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class RxJavaUtils method createCompletable.

@CheckResult
@NonNull
public static <T, Data> Completable createCompletable(@NonNull StorIOSQLite storIOSQLite, @NonNull PreparedCompletableOperation<T, Data> operation) {
    throwExceptionIfRxJava2IsNotAvailable("asRxCompletable()");
    final Completable completable = Completable.create(new CompletableOnSubscribeExecuteAsBlocking(operation));
    return subscribeOn(storIOSQLite, completable);
}
Also used : Completable(io.reactivex.Completable) CompletableOnSubscribeExecuteAsBlocking(com.pushtorefresh.storio3.operations.internal.CompletableOnSubscribeExecuteAsBlocking) CheckResult(android.support.annotation.CheckResult) NonNull(android.support.annotation.NonNull)

Example 39 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class DbModule method provideStorIOSQLite.

// We suggest to keep one instance of StorIO (SQLite or ContentResolver)
// It's thread safe and so on, so just share it.
// But if you need you can have multiple instances of StorIO
// (SQLite or ContentResolver) with different settings such as type mapping, logging and so on.
// But keep in mind that different instances of StorIOSQLite won't share notifications!
@Provides
@NonNull
@Singleton
public StorIOSQLite provideStorIOSQLite(@NonNull SQLiteOpenHelper sqLiteOpenHelper) {
    final CarStorIOSQLitePutResolver carStorIOSQLitePutResolver = new CarStorIOSQLitePutResolver();
    final CarStorIOSQLiteGetResolver carStorIOSQLiteGetResolver = new CarStorIOSQLiteGetResolver();
    final PersonStorIOSQLitePutResolver personStorIOSQLitePutResolver = new PersonStorIOSQLitePutResolver();
    final PersonStorIOSQLiteGetResolver personStorIOSQLiteGetResolver = new PersonStorIOSQLiteGetResolver();
    final CarPersonRelationPutResolver carPersonRelationPutResolver = new CarPersonRelationPutResolver();
    return DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).addTypeMapping(Tweet.class, new TweetSQLiteTypeMapping()).addTypeMapping(User.class, new UserSQLiteTypeMapping()).addTypeMapping(TweetWithUser.class, SQLiteTypeMapping.<TweetWithUser>builder().putResolver(new TweetWithUserPutResolver()).getResolver(new TweetWithUserGetResolver()).deleteResolver(new TweetWithUserDeleteResolver()).build()).addTypeMapping(Person.class, SQLiteTypeMapping.<Person>builder().putResolver(new PersonRelationsPutResolver(carStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new PersonRelationsGetResolver(carStorIOSQLiteGetResolver)).deleteResolver(new PersonRelationsDeleteResolver()).build()).addTypeMapping(Car.class, SQLiteTypeMapping.<Car>builder().putResolver(new CarRelationsPutResolver(personStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new CarRelationsGetResolver(personStorIOSQLiteGetResolver)).deleteResolver(new CarRelationsDeleteResolver()).build()).build();
}
Also used : TweetWithUserDeleteResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserDeleteResolver) PersonStorIOSQLitePutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLitePutResolver) CarPersonRelationPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarPersonRelationPutResolver) Tweet(com.pushtorefresh.storio3.sample.db.entities.Tweet) TweetSQLiteTypeMapping(com.pushtorefresh.storio3.sample.db.entities.TweetSQLiteTypeMapping) CarStorIOSQLitePutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLitePutResolver) CarRelationsDeleteResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsDeleteResolver) CarStorIOSQLiteGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLiteGetResolver) TweetWithUser(com.pushtorefresh.storio3.sample.db.entities.TweetWithUser) TweetWithUserGetResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserGetResolver) PersonRelationsPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsPutResolver) Car(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car) PersonStorIOSQLiteGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLiteGetResolver) PersonRelationsDeleteResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsDeleteResolver) CarRelationsPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsPutResolver) CarRelationsGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsGetResolver) TweetWithUserPutResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserPutResolver) PersonRelationsGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsGetResolver) UserSQLiteTypeMapping(com.pushtorefresh.storio3.sample.db.entities.UserSQLiteTypeMapping) Singleton(javax.inject.Singleton) NonNull(android.support.annotation.NonNull) Provides(dagger.Provides)

Example 40 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class PersonRelationsDeleteResolver method performDelete.

@Override
@NonNull
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull Person object) {
    final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
    lowLevel.beginTransaction();
    try {
        final DeleteResult deleteResult = super.performDelete(storIOSQLite, object);
        storIOSQLite.delete().byQuery(DeleteQuery.builder().table(PersonCarRelationTable.TABLE).where(COLUMN_PERSON_ID + " = ?").whereArgs(object.id()).build()).prepare().executeAsBlocking();
        lowLevel.setTransactionSuccessful();
        return deleteResult;
    } finally {
        lowLevel.endTransaction();
    }
}
Also used : StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) NonNull(android.support.annotation.NonNull)

Aggregations

Test (org.junit.Test)34 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)32 NonNull (android.support.annotation.NonNull)18 StorIOException (com.pushtorefresh.storio3.StorIOException)18 ContentValues (android.content.ContentValues)13 Query (com.pushtorefresh.storio3.sqlite.queries.Query)9 Cursor (android.database.Cursor)8 TestObserver (io.reactivex.observers.TestObserver)8 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)7 TestSubscriber (io.reactivex.subscribers.TestSubscriber)7 TypeMappingFinder (com.pushtorefresh.storio3.TypeMappingFinder)4 Car (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car)4 InsertQuery (com.pushtorefresh.storio3.sqlite.queries.InsertQuery)4 RawQuery (com.pushtorefresh.storio3.sqlite.queries.RawQuery)4 Tweet (com.pushtorefresh.storio3.sample.db.entities.Tweet)3 TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)3 Person (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Person)3 PutResult (com.pushtorefresh.storio3.sqlite.operations.put.PutResult)3 User (com.pushtorefresh.storio3.sample.db.entities.User)2 BaseTest (com.pushtorefresh.storio3.sqlite.integration.BaseTest)2