use of com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLiteGetResolver in project storio by pushtorefresh.
the class PersonRelationsGetResolver method mapFromCursor.
@Override
@NonNull
public Person mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
final Person person = super.mapFromCursor(storIOSQLite, cursor);
final List<Car> cars = storIOSQLite.get().listOfObjects(Car.class).withQuery(RawQuery.builder().query("SELECT " + CarTable.NAME + ".*" + " FROM " + CarTable.NAME + " JOIN " + PersonCarRelationTable.TABLE + " ON " + CarTable.ID_COLUMN + " = " + PersonCarRelationTable.COLUMN_CAR_ID + " AND " + PersonCarRelationTable.COLUMN_PERSON_ID + " = ?").args(person.id()).build()).withGetResolver(carStorIOSQLiteGetResolver).prepare().executeAsBlocking();
return new Person(person.id(), person.name(), cars);
}
use of com.pushtorefresh.storio3.sample.many_to_many_sample.entities.CarStorIOSQLiteGetResolver 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();
}
Aggregations