Search in sources :

Example 1 with Relations

use of com.pushtorefresh.storio3.sample.sample_code.Relations in project storio by pushtorefresh.

the class CarRelationsGetResolver method mapFromCursor.

@Override
@NonNull
public Car mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
    final Car car = super.mapFromCursor(storIOSQLite, cursor);
    final List<Person> persons = storIOSQLite.get().listOfObjects(Person.class).withQuery(RawQuery.builder().query("SELECT " + PersonTable.NAME + ".*" + " FROM " + PersonTable.NAME + " JOIN " + PersonCarRelationTable.TABLE + " ON " + PersonTable.ID_COLUMN + " = " + PersonCarRelationTable.COLUMN_PERSON_ID + " AND " + PersonCarRelationTable.COLUMN_CAR_ID + " = ?").args(car.id()).build()).withGetResolver(// without relations to prevent cycling
    personStorIOSQLiteGetResolver).prepare().executeAsBlocking();
    return new Car(car.id(), car.mark(), persons);
}
Also used : Car(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car) Person(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Person) NonNull(android.support.annotation.NonNull)

Example 2 with Relations

use of com.pushtorefresh.storio3.sample.sample_code.Relations 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)

Example 3 with Relations

use of com.pushtorefresh.storio3.sample.sample_code.Relations in project storio by pushtorefresh.

the class RelationsTest method name.

@Test
public void name() {
    SampleApp sampleApp = (SampleApp) RuntimeEnvironment.application;
    sampleApp.appComponent().storIOSQLite().put().objects(asList(Tweet.newTweet(1L, "artem_zin", "test tweet 1"), Tweet.newTweet(2L, "artem_zin", "test tweet 2"), Tweet.newTweet(3L, "nikitin-da", "test tweet 3"), User.newUser(1L, "artem_zin"), User.newUser(2L, "nikitin-da"))).prepare().executeAsBlocking();
    Relations relations = new Relations(sampleApp.appComponent().storIOSQLite());
    List<TweetWithUser> tweetsWithUsers = relations.getTweetWithUser();
    // Same as count of tweets, not users.
    assertThat(tweetsWithUsers).hasSize(3);
    assertThat(tweetsWithUsers.get(0)).isEqualTo(new TweetWithUser(Tweet.newTweet(1L, "artem_zin", "test tweet 1"), User.newUser(1L, "artem_zin")));
    assertThat(tweetsWithUsers.get(1)).isEqualTo(new TweetWithUser(Tweet.newTweet(2L, "artem_zin", "test tweet 2"), User.newUser(1L, "artem_zin")));
    assertThat(tweetsWithUsers.get(2)).isEqualTo(new TweetWithUser(Tweet.newTweet(3L, "nikitin-da", "test tweet 3"), User.newUser(2L, "nikitin-da")));
}
Also used : TweetWithUser(com.pushtorefresh.storio3.sample.db.entities.TweetWithUser) SampleApp(com.pushtorefresh.storio3.sample.SampleApp) Test(org.junit.Test)

Aggregations

NonNull (android.support.annotation.NonNull)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 SampleApp (com.pushtorefresh.storio3.sample.SampleApp)1 TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)1 Car (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car)1 Person (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Person)1 Relations (com.pushtorefresh.storio3.sample.sample_code.Relations)1 TweetsAdapter (com.pushtorefresh.storio3.sample.ui.adapter.TweetsAdapter)1 Test (org.junit.Test)1