use of com.pushtorefresh.storio3.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method insertObjectAsSingle.
@Test
public void insertObjectAsSingle() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
PutResult insertResult = storIOContentResolver.put().object(testItem).prepare().asRxSingle().blockingGet();
assertThat(insertResult.wasInserted()).isTrue();
Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(cursor).hasCount(1);
cursor.moveToFirst();
assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
cursor.close();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method insertObjectExecuteAsBlocking.
@Test
public void insertObjectExecuteAsBlocking() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
PutResult insertResult = storIOContentResolver.put().object(testItem).prepare().executeAsBlocking();
assertThat(insertResult.wasInserted()).isTrue();
Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(cursor).hasCount(1);
cursor.moveToFirst();
assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
cursor.close();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationDesignTest method putObjectBlocking.
@Test
public void putObjectBlocking() {
Article article = Article.newInstance(null, "test");
PutResult putResult = storIOContentResolver().put().object(article).withPutResolver(ArticleMeta.PUT_RESOLVER).prepare().executeAsBlocking();
}
use of com.pushtorefresh.storio3.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationDesignTest method putContentValuesBlocking.
@Test
public void putContentValuesBlocking() {
ContentValues contentValues = mock(ContentValues.class);
PutResult putResult = storIOContentResolver().put().contentValues(contentValues).withPutResolver(putResolverForContentValues).prepare().executeAsBlocking();
}
use of com.pushtorefresh.storio3.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class DefaultPutResolver method performPut.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public PutResult performPut(@NonNull StorIOContentResolver storIOContentResolver, @NonNull T object) {
final UpdateQuery updateQuery = mapToUpdateQuery(object);
final Query query = Query.builder().uri(updateQuery.uri()).where(nullableString(updateQuery.where())).whereArgs((Object[]) nullableArrayOfStringsFromListOfStrings(updateQuery.whereArgs())).build();
final StorIOContentResolver.LowLevel lowLevel = storIOContentResolver.lowLevel();
final Cursor cursor = lowLevel.query(query);
try {
final ContentValues contentValues = mapToContentValues(object);
if (cursor.getCount() == 0) {
final InsertQuery insertQuery = mapToInsertQuery(object);
final Uri insertedUri = lowLevel.insert(insertQuery, contentValues);
return PutResult.newInsertResult(insertedUri, insertQuery.uri());
} else {
final int numberOfRowsUpdated = lowLevel.update(updateQuery, contentValues);
return PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.uri());
}
} finally {
cursor.close();
}
}
Aggregations