Search in sources :

Example 11 with DeleteResult

use of com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationDesignTest method deleteObjectBlocking.

@Test
public void deleteObjectBlocking() {
    User user = newUser();
    DeleteResult deleteResult = storIOSQLite().delete().object(user).withDeleteResolver(UserTableMeta.DELETE_RESOLVER).prepare().executeAsBlocking();
}
Also used : DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) Test(org.junit.Test)

Example 12 with DeleteResult

use of com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult in project storio by pushtorefresh.

the class BaseTest method deleteUserBlocking.

@NonNull
DeleteResult deleteUserBlocking(@NonNull final User user) {
    final DeleteResult deleteResult = storIOSQLite.delete().object(user).prepare().executeAsBlocking();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    return deleteResult;
}
Also used : DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) NonNull(android.support.annotation.NonNull)

Example 13 with DeleteResult

use of com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult 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 14 with DeleteResult

use of com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectExecuteAsBlocking.

@Test
public void deleteObjectExecuteAsBlocking() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(firstDbState).hasCount(1);
    // noinspection ConstantConditions
    assertThat(firstDbState.moveToFirst()).isTrue();
    TestItem testItem = TestItem.fromCursor(firstDbState);
    DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().executeAsBlocking();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(secondDbState).hasCount(0);
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio3.contentresolver.Changes) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Cursor(android.database.Cursor) DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 15 with DeleteResult

use of com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectAsSingle.

@Test
public void deleteObjectAsSingle() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(firstDbState).hasCount(1);
    // noinspection ConstantConditions
    assertThat(firstDbState.moveToFirst()).isTrue();
    TestItem testItem = TestItem.fromCursor(firstDbState);
    DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().asRxSingle().blockingGet();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(secondDbState).hasCount(0);
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio3.contentresolver.Changes) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Cursor(android.database.Cursor) DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)10 NonNull (android.support.annotation.NonNull)7 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)7 TestSubscriber (io.reactivex.subscribers.TestSubscriber)7 Cursor (android.database.Cursor)6 Changes (com.pushtorefresh.storio3.contentresolver.Changes)6 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)6 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)5 DeleteResult (com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult)5 StorIOException (com.pushtorefresh.storio3.StorIOException)3 TestObserver (io.reactivex.observers.TestObserver)2 Uri (android.net.Uri)1 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)1 Changes (com.pushtorefresh.storio3.sqlite.Changes)1 PutResult (com.pushtorefresh.storio3.sqlite.operations.put.PutResult)1