Search in sources :

Example 1 with TweetWithUser

use of com.pushtorefresh.storio3.sample.db.entities.TweetWithUser 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)

Example 2 with TweetWithUser

use of com.pushtorefresh.storio3.sample.db.entities.TweetWithUser in project storio by pushtorefresh.

the class DbModule method provideStorIOSQLite.

// We suggest to keep one instance of StorIO (SQLite or ContentResolver)
// It's thread safe and so on, so just share it.
// But if you need you can have multiple instances of StorIO
// (SQLite or ContentResolver) with different settings such as type mapping, logging and so on.
// But keep in mind that different instances of StorIOSQLite won't share notifications!
@Provides
@NonNull
@Singleton
public StorIOSQLite provideStorIOSQLite(@NonNull SQLiteOpenHelper sqLiteOpenHelper) {
    final CarStorIOSQLitePutResolver carStorIOSQLitePutResolver = new CarStorIOSQLitePutResolver();
    final CarStorIOSQLiteGetResolver carStorIOSQLiteGetResolver = new CarStorIOSQLiteGetResolver();
    final PersonStorIOSQLitePutResolver personStorIOSQLitePutResolver = new PersonStorIOSQLitePutResolver();
    final PersonStorIOSQLiteGetResolver personStorIOSQLiteGetResolver = new PersonStorIOSQLiteGetResolver();
    final CarPersonRelationPutResolver carPersonRelationPutResolver = new CarPersonRelationPutResolver();
    return DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).addTypeMapping(Tweet.class, new TweetSQLiteTypeMapping()).addTypeMapping(User.class, new UserSQLiteTypeMapping()).addTypeMapping(TweetWithUser.class, SQLiteTypeMapping.<TweetWithUser>builder().putResolver(new TweetWithUserPutResolver()).getResolver(new TweetWithUserGetResolver()).deleteResolver(new TweetWithUserDeleteResolver()).build()).addTypeMapping(Person.class, SQLiteTypeMapping.<Person>builder().putResolver(new PersonRelationsPutResolver(carStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new PersonRelationsGetResolver(carStorIOSQLiteGetResolver)).deleteResolver(new PersonRelationsDeleteResolver()).build()).addTypeMapping(Car.class, SQLiteTypeMapping.<Car>builder().putResolver(new CarRelationsPutResolver(personStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new CarRelationsGetResolver(personStorIOSQLiteGetResolver)).deleteResolver(new CarRelationsDeleteResolver()).build()).build();
}
Also used : TweetWithUserDeleteResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserDeleteResolver) PersonStorIOSQLitePutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLitePutResolver) CarPersonRelationPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarPersonRelationPutResolver) Tweet(com.pushtorefresh.storio3.sample.db.entities.Tweet) TweetSQLiteTypeMapping(com.pushtorefresh.storio3.sample.db.entities.TweetSQLiteTypeMapping) CarStorIOSQLitePutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLitePutResolver) CarRelationsDeleteResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsDeleteResolver) CarStorIOSQLiteGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLiteGetResolver) TweetWithUser(com.pushtorefresh.storio3.sample.db.entities.TweetWithUser) TweetWithUserGetResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserGetResolver) PersonRelationsPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsPutResolver) Car(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car) PersonStorIOSQLiteGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLiteGetResolver) PersonRelationsDeleteResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsDeleteResolver) CarRelationsPutResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsPutResolver) CarRelationsGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsGetResolver) TweetWithUserPutResolver(com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserPutResolver) PersonRelationsGetResolver(com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsGetResolver) UserSQLiteTypeMapping(com.pushtorefresh.storio3.sample.db.entities.UserSQLiteTypeMapping) Singleton(javax.inject.Singleton) NonNull(android.support.annotation.NonNull) Provides(dagger.Provides)

Example 3 with TweetWithUser

use of com.pushtorefresh.storio3.sample.db.entities.TweetWithUser 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)

Aggregations

TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)3 NonNull (android.support.annotation.NonNull)2 Tweet (com.pushtorefresh.storio3.sample.db.entities.Tweet)2 SampleApp (com.pushtorefresh.storio3.sample.SampleApp)1 TweetSQLiteTypeMapping (com.pushtorefresh.storio3.sample.db.entities.TweetSQLiteTypeMapping)1 User (com.pushtorefresh.storio3.sample.db.entities.User)1 UserSQLiteTypeMapping (com.pushtorefresh.storio3.sample.db.entities.UserSQLiteTypeMapping)1 TweetWithUserDeleteResolver (com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserDeleteResolver)1 TweetWithUserGetResolver (com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserGetResolver)1 TweetWithUserPutResolver (com.pushtorefresh.storio3.sample.db.resolvers.TweetWithUserPutResolver)1 Car (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car)1 CarStorIOSQLiteGetResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLiteGetResolver)1 CarStorIOSQLitePutResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLitePutResolver)1 PersonStorIOSQLiteGetResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLiteGetResolver)1 PersonStorIOSQLitePutResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.PersonStorIOSQLitePutResolver)1 CarPersonRelationPutResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarPersonRelationPutResolver)1 CarRelationsDeleteResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsDeleteResolver)1 CarRelationsGetResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsGetResolver)1 CarRelationsPutResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.CarRelationsPutResolver)1 PersonRelationsDeleteResolver (com.pushtorefresh.storio3.sample.many_to_many_sample.resolvers.PersonRelationsDeleteResolver)1