Search in sources :

Example 26 with StorIOSQLite

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

the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.

@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).defaultRxScheduler(null).build();
    assertThat(storIOSQLite.defaultRxScheduler()).isNull();
}
Also used : StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 27 with StorIOSQLite

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

the class DefaultStorIOSQLiteTest method getTypeMappingFinder.

@Nullable
private static TypeMappingFinder getTypeMappingFinder(@NonNull DefaultStorIOSQLite storIOSQLite) throws NoSuchFieldException, IllegalAccessException {
    Field field = DefaultStorIOSQLite.LowLevelImpl.class.getDeclaredField("typeMappingFinder");
    field.setAccessible(true);
    return (TypeMappingFinder) field.get(storIOSQLite.lowLevel());
}
Also used : Field(java.lang.reflect.Field) TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) Nullable(android.support.annotation.Nullable)

Example 28 with StorIOSQLite

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

the class DefaultPutResolver method performPut.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public PutResult performPut(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
    final UpdateQuery updateQuery = mapToUpdateQuery(object);
    final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
    // for data consistency in concurrent environment, encapsulate Put Operation into transaction
    lowLevel.beginTransaction();
    try {
        final Cursor cursor = lowLevel.query(Query.builder().table(updateQuery.table()).where(nullableString(updateQuery.where())).whereArgs((Object[]) nullableArrayOfStringsFromListOfStrings(updateQuery.whereArgs())).build());
        final PutResult putResult;
        try {
            final ContentValues contentValues = mapToContentValues(object);
            if (cursor.getCount() == 0) {
                final InsertQuery insertQuery = mapToInsertQuery(object);
                final long insertedId = lowLevel.insert(insertQuery, contentValues);
                putResult = PutResult.newInsertResult(insertedId, insertQuery.table(), insertQuery.affectsTags());
            } else {
                final int numberOfRowsUpdated = lowLevel.update(updateQuery, contentValues);
                putResult = PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table(), updateQuery.affectsTags());
            }
        } finally {
            cursor.close();
        }
        // everything okay
        lowLevel.setTransactionSuccessful();
        return putResult;
    } finally {
        // in case of bad situations, db won't be affected
        lowLevel.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) InsertQuery(com.pushtorefresh.storio3.sqlite.queries.InsertQuery) UpdateQuery(com.pushtorefresh.storio3.sqlite.queries.UpdateQuery) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) NonNull(android.support.annotation.NonNull)

Example 29 with StorIOSQLite

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

the class DefaultDeleteResolver method performDelete.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
    final DeleteQuery deleteQuery = mapToDeleteQuery(object);
    final int numberOfRowsDeleted = storIOSQLite.lowLevel().delete(deleteQuery);
    return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.table(), deleteQuery.affectsTags());
}
Also used : DeleteQuery(com.pushtorefresh.storio3.sqlite.queries.DeleteQuery) NonNull(android.support.annotation.NonNull)

Example 30 with StorIOSQLite

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

the class TweetsSQLiteFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final FragmentActivity activity = getActivity();
    SampleApp.get(activity).appComponent().inject(this);
    tweetsAdapter = new TweetsAdapter(LayoutInflater.from(activity), this);
    new Relations(storIOSQLite).getTweetWithUser();
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) TweetsAdapter(com.pushtorefresh.storio3.sample.ui.adapter.TweetsAdapter) Relations(com.pushtorefresh.storio3.sample.sample_code.Relations)

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