Search in sources :

Example 16 with User

use of com.pushtorefresh.storio3.sqlite.integration.User in project storio by pushtorefresh.

the class UserWithTweetsGetResolver method mapFromCursor.

@NonNull
@Override
public UserWithTweets mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
    // Or you can manually parse cursor (it will be sliiightly faster)
    final User user = userGetResolver.mapFromCursor(storIOSQLite, cursor);
    // Yep, you can reuse StorIO here!
    // Or, you can do manual low level requests here
    // BTW, if you profiled your app and found that such queries are not very fast
    // You can always add some optimized version for particular queries to improve the performance
    final List<Tweet> tweetsOfTheUser = storIOSQLite.get().listOfObjects(Tweet.class).withQuery(Query.builder().table(TweetsTable.TABLE).where(TweetsTable.COLUMN_AUTHOR + "=?").whereArgs(user.nick()).build()).prepare().executeAsBlocking();
    return new UserWithTweets(user, tweetsOfTheUser);
}
Also used : User(com.pushtorefresh.storio3.sample.db.entities.User) Tweet(com.pushtorefresh.storio3.sample.db.entities.Tweet) UserWithTweets(com.pushtorefresh.storio3.sample.db.entities.UserWithTweets) NonNull(android.support.annotation.NonNull)

Example 17 with User

use of com.pushtorefresh.storio3.sqlite.integration.User in project storio by pushtorefresh.

the class TweetWithUserGetResolver method mapFromCursor.

// We expect that cursor will contain both Tweet and User: SQL JOIN
@NonNull
@Override
public TweetWithUser mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
    final Tweet tweet = Tweet.newTweet(cursor.getLong(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_ID)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_AUTHOR)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_CONTENT)));
    final User user = User.newUser(cursor.getLong(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_USER_ID)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_USER_NICK)));
    return new TweetWithUser(tweet, user);
}
Also used : TweetWithUser(com.pushtorefresh.storio3.sample.db.entities.TweetWithUser) User(com.pushtorefresh.storio3.sample.db.entities.User) TweetWithUser(com.pushtorefresh.storio3.sample.db.entities.TweetWithUser) Tweet(com.pushtorefresh.storio3.sample.db.entities.Tweet) NonNull(android.support.annotation.NonNull)

Example 18 with User

use of com.pushtorefresh.storio3.sqlite.integration.User in project storio by pushtorefresh.

the class RxJavaUtilsTest method createGetFlowableOptionalCompletedAfterInitialEmissionIfNoTablesAndTags.

@Test
public void createGetFlowableOptionalCompletedAfterInitialEmissionIfNoTablesAndTags() {
    RawQuery queryWithoutTablesAnTags = RawQuery.builder().query("select * from " + UserTableMeta.TABLE + " where " + UserTableMeta.COLUMN_ID + "=?").args(1).build();
    PreparedGetObject<User> preparedGet = storIOSQLite.get().object(User.class).withQuery(queryWithoutTablesAnTags).prepare();
    TestSubscriber<Optional<User>> subscriber = new TestSubscriber<Optional<User>>();
    RxJavaUtils.createGetFlowableOptional(storIOSQLite, preparedGet, null, queryWithoutTablesAnTags, BackpressureStrategy.LATEST).subscribe(subscriber);
    subscriber.assertNoErrors();
    subscriber.assertValues(Optional.<User>empty());
    subscriber.assertComplete();
}
Also used : User(com.pushtorefresh.storio3.sqlite.integration.User) Optional(com.pushtorefresh.storio3.Optional) RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BaseTest(com.pushtorefresh.storio3.sqlite.integration.BaseTest) Test(org.junit.Test)

Example 19 with User

use of com.pushtorefresh.storio3.sqlite.integration.User in project storio by pushtorefresh.

the class RxJavaUtilsTest method createGetFlowableCompletedAfterInitialEmissionIfNoTablesAndTags.

@Test
public void createGetFlowableCompletedAfterInitialEmissionIfNoTablesAndTags() {
    RawQuery queryWithoutTablesAnTags = RawQuery.builder().query("select * from " + UserTableMeta.TABLE).build();
    PreparedGetListOfObjects<User> preparedGet = storIOSQLite.get().listOfObjects(User.class).withQuery(queryWithoutTablesAnTags).prepare();
    TestSubscriber<List<User>> subscriber = new TestSubscriber<List<User>>();
    RxJavaUtils.createGetFlowable(storIOSQLite, preparedGet, null, queryWithoutTablesAnTags, BackpressureStrategy.LATEST).subscribe(subscriber);
    subscriber.assertNoErrors();
    subscriber.assertValues(EMPTY_LIST);
    subscriber.assertComplete();
}
Also used : User(com.pushtorefresh.storio3.sqlite.integration.User) RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) TestSubscriber(io.reactivex.subscribers.TestSubscriber) List(java.util.List) BaseTest(com.pushtorefresh.storio3.sqlite.integration.BaseTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Disposable (io.reactivex.disposables.Disposable)10 AbstractEmissionChecker (com.pushtorefresh.storio3.test.AbstractEmissionChecker)9 LinkedList (java.util.LinkedList)9 Changes (com.pushtorefresh.storio3.sqlite.Changes)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 NonNull (android.support.annotation.NonNull)4 Tweet (com.pushtorefresh.storio3.sample.db.entities.Tweet)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 User (com.pushtorefresh.storio3.sqlite.integration.User)2 DeleteResult (com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult)2 RawQuery (com.pushtorefresh.storio3.sqlite.queries.RawQuery)2 TestSubscriber (io.reactivex.subscribers.TestSubscriber)2 Optional (com.pushtorefresh.storio3.Optional)1 TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)1 UserWithTweets (com.pushtorefresh.storio3.sample.db.entities.UserWithTweets)1