{"id":333805,"date":"2022-05-30T15:00:50","date_gmt":"2022-05-30T15:00:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=333805"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=333805","title":{"rendered":"<span>\u0421\u0438\u043b\u0430 @RawQuery. \u0421\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u0434 DAO \u043d\u0430 90%<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/aa0\/d0a\/595\/aa0d0a59553aabb5fb428c8c18919ec4.jpg\" width=\"515\" height=\"302\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa0\/d0a\/595\/aa0d0a59553aabb5fb428c8c18919ec4.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h2>1 \u041c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f<\/h2>\n<p>\u042f \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432\u0430\u0448\u0438\u0445 Dao \u0432 50-90%.<\/p>\n<h2>2 \u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 Android \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/developer.android.com\/training\/data-storage\/room\" rel=\"noopener noreferrer nofollow\">Room<\/a>. \u0412 \u0446\u0435\u043b\u043e\u043c \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043d\u0435\u0439 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 3 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u043e \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u0431\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/CRUD\" rel=\"noopener noreferrer nofollow\">CRUD<\/a> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0414\u043b\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0445 Insert, Update \u0438 Delete \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434.<\/p>\n<pre><code class=\"kotlin\">@Dao interface UserDao {   @Insert   fun insert(user: User)      @Update   fun update(user: User) }  @Dao interface CarDao {   @Insert   fun insert(car: Car)      @Update   fun update(car: Car) }<\/code><\/pre>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f Dao, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e <a href=\"https:\/\/gist.github.com\/florina-muntenescu\/1c78858f286d196d545c038a71a3e864\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">interface InsertDao&lt;T> {   @Insert   fun insert(item: T) }  interface UpdateDao&lt;T> {   @Update   fun update(item: T) }  interface SaveDao&lt;T> : InsertDao&lt;T>, UpdateDao&lt;T>  @Dao interface UserDao : SaveDao&lt;User>  @Dao interface CarDao : SaveDao&lt;Car><\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D1%80%D0%B0%D0%B7%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B0\" rel=\"noopener noreferrer nofollow\"><em>Interface Segregation Principle<\/em><\/a>  \u0438\u0437 SOLID. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e dao, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e Insert \u0431\u0435\u0437 Update, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 InsertDao&lt;User>:<\/p>\n<pre><code class=\"kotlin\">class SomeClass&lt;T>(private val insertDao: InsertDao&lt;T>) {      fun saveSomething(item: T) {     insertDao.insert(item)   }    }<\/code><\/pre>\n<p>\u041d\u043e \u0432\u0435\u0441\u044c <em>Interface Segregation Principle<\/em> \u0440\u0443\u0448\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 Query:<\/p>\n<pre><code class=\"kotlin\">@Dao interface UserDao : SaveDao&lt;User> {    @Query(\"SELECT * FROM USER\")   fun getAllUsers(): List&lt;User>    }  @Dao interface CarDao : SaveDao&lt;Car> {    @Query(\"SELECT * FROM CAR\")   fun getAllCars(): List&lt;Car>    }<\/code><\/pre>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c <a href=\"https:\/\/gist.github.com\/florina-muntenescu\/1c78858f286d196d545c038a71a3e864\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043c \u0436\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445<\/a>. \u0418 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @JvmSuppressWildcards   fun getAll(): List&lt;T>    }  @Dao interface UserDao : SaveDao&lt;User>, GetAllDao&lt;User> {    @Query(\"SELECT * FROM USER\")   @JvmSuppressWildcards   override fun getAll(): List&lt;User>    }  @Dao interface CarDao : SaveDao&lt;Car>, GetAllDao&lt;Car> {    @Query(\"SELECT * FROM CAR\")   @JvmSuppressWildcards   override fun getAll(): List&lt;Car>    }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f <em>Interface Segregation Principle<\/em> \u0446\u0435\u043d\u043e\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <strong>JvmSuppressWildcards<\/strong>. \u041d\u043e \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u043c\u044b \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u0438 \u043d\u0435 \u0443\u0448\u043b\u0438, \u0432\u0435\u0434\u044c \u0432\u0441\u0435 Read \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 Dao \u0434\u0430 \u0435\u0449\u0435 \u0438 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0434\u043b\u044f \u043d\u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e. <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>Query<\/strong> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <em>GetAllDao<\/em>. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0438\u043c\u0435\u043d\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f. \u0420\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f \u043d\u0430\u043c \u0442\u0443\u0442 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0432 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @Query(\"SELECT * FROM T::class.java.simpleName)   fun getAll(): List&lt;T>    }<\/code><\/pre>\n<p> \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0434\u0432\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430:<\/p>\n<ul>\n<li>\n<p>An annotation argument must be a compile-time constant<\/p>\n<\/li>\n<li>\n<p>Cannot use &#8216;T&#8217; as reified type parameter. Use a class instead.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h2>3 RawQuery \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438<\/h2>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e RawQuery. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043d\u0435\u0439 \u0432\u0432\u0438\u0434\u0443 0% \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u0438\u0437\u043b\u043e\u0436\u0443 \u0441\u0443\u0442\u044c. <\/p>\n<p><a href=\"https:\/\/developer.android.com\/reference\/androidx\/room\/RawQuery\" rel=\"noopener noreferrer nofollow\">RawQuery<\/a> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u043b\u0430 Dao \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c query \u043a \u0431\u0434 \u043d\u0430 Runtime. <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"kotlin\">interface SomeDao {      @RawQuery   suspend fun getAll(query: SimpleSQLiteQuery): List&lt;SomeEntity>    }<\/code><\/pre>\n<p>\u0413\u0434\u0435 <a href=\"https:\/\/developer.android.com\/reference\/androidx\/sqlite\/db\/SimpleSQLiteQuery\" rel=\"noopener noreferrer nofollow\">SimpleSqliteQuery<\/a> &#8212; \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0434. <\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435, \u0432\u0435\u0434\u044c SimpleSqliteQuery \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041b\u043e\u0433\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430, \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"kotlin\">val sqliteRawQuery = SimpleSqliteQuery(\"SELECT * FROM TABLE_NAME\")<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"kotlin\">val query = \"SELECT * FROM TABLE_NAME WHERE id = ?\" val args = listOf(13) val sqliteRawQuery = SimpleSqliteQuery(query, args)<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SimpleSqliteQuery \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0448\u0438 Dao \u0437\u0430\u043c\u0435\u043d\u0438\u0432 Query \u043d\u0430 RawQuery.<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @RawQuery   fun getAll(): List&lt;T>    }  @Dao interface UserDao : SaveDao&lt;User>, GetAllDao&lt;User>  @Dao interface CarDao : SaveDao&lt;Car>, GetAllDao&lt;Car><\/code><\/pre>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u0432 Dao \u0441\u0442\u0430\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0438 \u044d\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0442\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0432\u0443\u0445 Dao.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Helper \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Dao \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Helper.<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {      protected val table: String     get() = classType.simpleName    protected abstract val query: String    protected val sqliteQuery: SimpleSQLiteQuery     get() = SimpleSQLiteQuery(query, getBindArgs())    protected open fun getBindArgs(): Array&lt;Any> = arrayOf()  }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442).<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c GetAllDaoHelper \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u0434.<\/p>\n<pre><code class=\"kotlin\">class GetAllDaoHelper&lt;T> @Inject constructor(   private val itemDao: GetAllDao&lt;T>,   classType: Class&lt;T>, ) : Helper&lt;T>(classType) {    override val query = \"SELECT * FROM $table\"    suspend fun getAll() : List&lt;T> {     return itemDao.getAll(sqliteQuery)   }  }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f query \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 table.<\/p>\n<pre><code class=\"kotlin\">override val query = \"SELECT * FROM $table\"<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0435 table \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {      \/\/.....    protected val table: String     get() = classType.simpleName      \/\/...... }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c simpleName \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 T, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Car, \u0442\u043e \u0438 \u0435\u0433\u043e simpleName \u0431\u0443\u0434\u0435\u0442 Car. <\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f classType \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a \u043d\u0430\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0442\u043e\u0440, \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>\u0412\u0435\u0440\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u043a GetAllItemsDaoHelper \u043c\u044b \u0435\u0449\u0435 \u0432\u0438\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 getAll()<\/p>\n<pre><code class=\"kotlin\">class GetAllItemsDaoHelper&lt;T> @Inject constructor(   private val itemDao: GetAllDao&lt;T>,   \/\/.. ) : Helper&lt;T>(..) {    \/\/..    suspend fun getAll() : List&lt;T> {     return itemDao.getAll(sqliteQuery)   }  }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 GetAllDao c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c sqliteQuery.<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {    protected abstract val query: String    \/\/..    protected val sqliteQuery: SimpleSQLiteQuery     get() = SimpleSQLiteQuery(query, getBindArgs())    protected open fun getBindArgs(): Array&lt;Any> = arrayOf()  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 SimpleSqliteQuery \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043f\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u043d\u0430\u043c \u0441\u0445\u0435\u043c\u0435, \u0430 \u043c\u0435\u0442\u043e\u0434 getBindArgs \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 query.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 GetAllDaoHelper \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441, \u043e\u0442\u043a\u0443\u0434\u0430 \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e classType.<\/p>\n<pre><code class=\"kotlin\">class GetAllItemsDaoHelper&lt;T> @Inject constructor(   \/\/..   classType: Class&lt;T>, ) : Helper&lt;T>(classType) {<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442: \u0438\u0437 Dependency Injection. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Hilt DI, \u0432\u0432\u0438\u0434\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Generics \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Koin. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u0433\u0440\u0430\u0444 \u0442\u0430\u043a \u0436\u0435 \u0435\u0435 Class&lt;Entity>, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<pre><code class=\"kotlin\">@Module @InstallIn(SingletonComponent::class) object EntityModule {    @Provides   fun provideCarClass(): Class&lt;Car> = Car::class.java    @Provides   fun provideUserClass(): Class&lt;User> = User::class.java    \/\/\u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435  }<\/code><\/pre>\n<p>\u0423\u0436 \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044e \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b GetAllDao&lt;Car> \u0438 GetAllDao&lt;User> \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0433\u0440\u0430\u0444.<\/p>\n<hr\/>\n<h2>4. \u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u043f\u043b\u044e\u0441\u044b \u0442\u0430\u043a \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u043d\u0435 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b.<\/p>\n<blockquote>\n<p>\u00ab\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043a\u0443\u0441\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u0441\u043b\u043e\u0432\u043d\u043e \u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0434\u0440\u043e\u0436\u0430\u0442 \u0440\u0443\u043a\u0438, \u0438 \u043e\u043d \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442.\u00bb &#8212; \u0420\u043e\u0431\u0435\u0440\u0442 \u041c\u0430\u0440\u0442\u0438\u043d.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0445 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043b\u044e\u0441\u043e\u0432.<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 Dao. \u041f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0432\u044b \u0441\u0430\u043c\u0438 \u0437\u043d\u0430\u0435\u0442\u0435. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 Dao \u0441\u0432\u0435\u0434\u0435\u043d\u0430 \u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443 \u0438 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0410 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0435 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c <em>Interface Segregation Principle<\/em> \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Open%E2%80%93closed_principle#:~:text=In%20object%2Doriented%20programming%2C%20the,without%20modifying%20its%20source%20code.\" rel=\"noopener noreferrer nofollow\"><em>Open-Closed Principle<\/em><\/a><em>.<\/em><\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435(\u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u044f \u043c\u043e\u0433\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435).<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438:<\/p>\n<ol>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 runtime. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u044d\u0442\u043e\u0442 \u043c\u0438\u043d\u0443\u0441 \u043d\u0438\u0432\u0435\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Observable \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c Flow, PagingSource \u0438 \u0442.\u0434.) \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0437\u0430 \u043a\u0430\u043a\u0438\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043d\u0430\u0434\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"kotlin\">interface GetPagingSourceDao&lt;T : Any> {    @RawQuery   fun getPagingSource(query: SimpleSQLiteQuery): PagingSource&lt;Int, T>  }  @Dao interface CharacterDao : GetPagingSourceDao&lt;Character> {    @RawQuery(observedEntities = [Character::class])   override fun getPagingSource(     query: SimpleSQLiteQuery   ): PagingSource&lt;Int, Charater>  }<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u041d\u0435\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432 \u0433\u043b\u0430\u0437\u0430\u0445 \u043d\u043e\u0432\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441 RawQuery \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u043c\u0430\u043b\u043e \u043b\u044e\u0434\u0435\u0439, \u043d\u043e\u0432\u044b\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0439\u043c\u0435\u0442 \u043a \u0447\u0435\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 DI Class&lt;Entity> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 RawQuery \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0439 Helper;<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 Dao(\u043a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435);<\/p>\n<\/li>\n<li>\n<p>RawQuery \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c. (\u041e\u0441\u043e\u0431\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u043f\u0440\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c Update \u0438\u043b\u0438 Delete \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u043e\u043d \u0438 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d);<\/p>\n<\/li>\n<li>\n<p>TableName \u0432 Entity \u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439, \u0438\u043d\u0430\u0447\u0435 \u043b\u043e\u0433\u0438\u043a\u0430 simpleName \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c(\u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u043d\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f).<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0439 playground \u0433\u0434\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 <a href=\"https:\/\/github.com\/HalfAPum\/Playground\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/HalfAPum\/Playground<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/668564\/\"> https:\/\/habr.com\/ru\/post\/668564\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>1 \u041c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f<\/h2>\n<p>\u042f \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432\u0430\u0448\u0438\u0445 Dao \u0432 50-90%.<\/p>\n<h2>2 \u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 Android \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/developer.android.com\/training\/data-storage\/room\" rel=\"noopener noreferrer nofollow\">Room<\/a>. \u0412 \u0446\u0435\u043b\u043e\u043c \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043d\u0435\u0439 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 3 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u043e \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u0431\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/CRUD\" rel=\"noopener noreferrer nofollow\">CRUD<\/a> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0414\u043b\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0445 Insert, Update \u0438 Delete \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434.<\/p>\n<pre><code class=\"kotlin\">@Dao interface UserDao {   @Insert   fun insert(user: User)      @Update   fun update(user: User) }  @Dao interface CarDao {   @Insert   fun insert(car: Car)      @Update   fun update(car: Car) }<\/code><\/pre>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f Dao, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e <a href=\"https:\/\/gist.github.com\/florina-muntenescu\/1c78858f286d196d545c038a71a3e864\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">interface InsertDao&lt;T> {   @Insert   fun insert(item: T) }  interface UpdateDao&lt;T> {   @Update   fun update(item: T) }  interface SaveDao&lt;T> : InsertDao&lt;T>, UpdateDao&lt;T>  @Dao interface UserDao : SaveDao&lt;User>  @Dao interface CarDao : SaveDao&lt;Car><\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D1%80%D0%B0%D0%B7%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B0\" rel=\"noopener noreferrer nofollow\"><em>Interface Segregation Principle<\/em><\/a>  \u0438\u0437 SOLID. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e dao, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e Insert \u0431\u0435\u0437 Update, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 InsertDao&lt;User>:<\/p>\n<pre><code class=\"kotlin\">class SomeClass&lt;T>(private val insertDao: InsertDao&lt;T>) {      fun saveSomething(item: T) {     insertDao.insert(item)   }    }<\/code><\/pre>\n<p>\u041d\u043e \u0432\u0435\u0441\u044c <em>Interface Segregation Principle<\/em> \u0440\u0443\u0448\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 Query:<\/p>\n<pre><code class=\"kotlin\">@Dao interface UserDao : SaveDao&lt;User> {    @Query(\"SELECT * FROM USER\")   fun getAllUsers(): List&lt;User>    }  @Dao interface CarDao : SaveDao&lt;Car> {    @Query(\"SELECT * FROM CAR\")   fun getAllCars(): List&lt;Car>    }<\/code><\/pre>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c <a href=\"https:\/\/gist.github.com\/florina-muntenescu\/1c78858f286d196d545c038a71a3e864\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043c \u0436\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445<\/a>. \u0418 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @JvmSuppressWildcards   fun getAll(): List&lt;T>    }  @Dao interface UserDao : SaveDao&lt;User>, GetAllDao&lt;User> {    @Query(\"SELECT * FROM USER\")   @JvmSuppressWildcards   override fun getAll(): List&lt;User>    }  @Dao interface CarDao : SaveDao&lt;Car>, GetAllDao&lt;Car> {    @Query(\"SELECT * FROM CAR\")   @JvmSuppressWildcards   override fun getAll(): List&lt;Car>    }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f <em>Interface Segregation Principle<\/em> \u0446\u0435\u043d\u043e\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <strong>JvmSuppressWildcards<\/strong>. \u041d\u043e \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u043c\u044b \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u0438 \u043d\u0435 \u0443\u0448\u043b\u0438, \u0432\u0435\u0434\u044c \u0432\u0441\u0435 Read \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 Dao \u0434\u0430 \u0435\u0449\u0435 \u0438 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0434\u043b\u044f \u043d\u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e. <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>Query<\/strong> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <em>GetAllDao<\/em>. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0438\u043c\u0435\u043d\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f. \u0420\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f \u043d\u0430\u043c \u0442\u0443\u0442 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0432 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @Query(\"SELECT * FROM T::class.java.simpleName)   fun getAll(): List&lt;T>    }<\/code><\/pre>\n<p> \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0434\u0432\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430:<\/p>\n<ul>\n<li>\n<p>An annotation argument must be a compile-time constant<\/p>\n<\/li>\n<li>\n<p>Cannot use &#8216;T&#8217; as reified type parameter. Use a class instead.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h2>3 RawQuery \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438<\/h2>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e RawQuery. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043d\u0435\u0439 \u0432\u0432\u0438\u0434\u0443 0% \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u0438\u0437\u043b\u043e\u0436\u0443 \u0441\u0443\u0442\u044c. <\/p>\n<p><a href=\"https:\/\/developer.android.com\/reference\/androidx\/room\/RawQuery\" rel=\"noopener noreferrer nofollow\">RawQuery<\/a> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u043b\u0430 Dao \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c query \u043a \u0431\u0434 \u043d\u0430 Runtime. <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"kotlin\">interface SomeDao {      @RawQuery   suspend fun getAll(query: SimpleSQLiteQuery): List&lt;SomeEntity>    }<\/code><\/pre>\n<p>\u0413\u0434\u0435 <a href=\"https:\/\/developer.android.com\/reference\/androidx\/sqlite\/db\/SimpleSQLiteQuery\" rel=\"noopener noreferrer nofollow\">SimpleSqliteQuery<\/a> &#8212; \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0434. <\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435, \u0432\u0435\u0434\u044c SimpleSqliteQuery \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041b\u043e\u0433\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430, \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"kotlin\">val sqliteRawQuery = SimpleSqliteQuery(\"SELECT * FROM TABLE_NAME\")<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"kotlin\">val query = \"SELECT * FROM TABLE_NAME WHERE id = ?\" val args = listOf(13) val sqliteRawQuery = SimpleSqliteQuery(query, args)<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SimpleSqliteQuery \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0448\u0438 Dao \u0437\u0430\u043c\u0435\u043d\u0438\u0432 Query \u043d\u0430 RawQuery.<\/p>\n<pre><code class=\"kotlin\">interface GetAllDao&lt;T> {      @RawQuery   fun getAll(): List&lt;T>    }  @Dao interface UserDao : SaveDao&lt;User>, GetAllDao&lt;User>  @Dao interface CarDao : SaveDao&lt;Car>, GetAllDao&lt;Car><\/code><\/pre>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u0432 Dao \u0441\u0442\u0430\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0438 \u044d\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0442\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0432\u0443\u0445 Dao.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Helper \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Dao \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Helper.<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {      protected val table: String     get() = classType.simpleName    protected abstract val query: String    protected val sqliteQuery: SimpleSQLiteQuery     get() = SimpleSQLiteQuery(query, getBindArgs())    protected open fun getBindArgs(): Array&lt;Any> = arrayOf()  }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442).<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c GetAllDaoHelper \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u0434.<\/p>\n<pre><code class=\"kotlin\">class GetAllDaoHelper&lt;T> @Inject constructor(   private val itemDao: GetAllDao&lt;T>,   classType: Class&lt;T>, ) : Helper&lt;T>(classType) {    override val query = \"SELECT * FROM $table\"    suspend fun getAll() : List&lt;T> {     return itemDao.getAll(sqliteQuery)   }  }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f query \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 table.<\/p>\n<pre><code class=\"kotlin\">override val query = \"SELECT * FROM $table\"<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0435 table \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {      \/\/.....    protected val table: String     get() = classType.simpleName      \/\/...... }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c simpleName \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 T, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Car, \u0442\u043e \u0438 \u0435\u0433\u043e simpleName \u0431\u0443\u0434\u0435\u0442 Car. <\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f classType \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a \u043d\u0430\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0442\u043e\u0440, \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>\u0412\u0435\u0440\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u043a GetAllItemsDaoHelper \u043c\u044b \u0435\u0449\u0435 \u0432\u0438\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 getAll()<\/p>\n<pre><code class=\"kotlin\">class GetAllItemsDaoHelper&lt;T> @Inject constructor(   private val itemDao: GetAllDao&lt;T>,   \/\/.. ) : Helper&lt;T>(..) {    \/\/..    suspend fun getAll() : List&lt;T> {     return itemDao.getAll(sqliteQuery)   }  }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 GetAllDao c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c sqliteQuery.<\/p>\n<pre><code class=\"kotlin\">abstract class Helper&lt;T>(private val classType: Class&lt;T>) {    protected abstract val query: String    \/\/..    protected val sqliteQuery: SimpleSQLiteQuery     get() = SimpleSQLiteQuery(query, getBindArgs())    protected open fun getBindArgs(): Array&lt;Any> = arrayOf()  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 SimpleSqliteQuery \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043f\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u043d\u0430\u043c \u0441\u0445\u0435\u043c\u0435, \u0430 \u043c\u0435\u0442\u043e\u0434 getBindArgs \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 query.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 GetAllDaoHelper \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441, \u043e\u0442\u043a\u0443\u0434\u0430 \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e classType.<\/p>\n<pre><code class=\"kotlin\">class GetAllItemsDaoHelper&lt;T> @Inject constructor(   \/\/..   classType: Class&lt;T>, ) : Helper&lt;T>(classType) {<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442: \u0438\u0437 Dependency Injection. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Hilt DI, \u0432\u0432\u0438\u0434\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Generics \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Koin. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u0433\u0440\u0430\u0444 \u0442\u0430\u043a \u0436\u0435 \u0435\u0435 Class&lt;Entity>, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<pre><code class=\"kotlin\">@Module @InstallIn(SingletonComponent::class) object EntityModule {    @Provides   fun provideCarClass(): Class&lt;Car> = Car::class.java    @Provides   fun provideUserClass(): Class&lt;User> = User::class.java    \/\/\u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435  }<\/code><\/pre>\n<p>\u0423\u0436 \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044e \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b GetAllDao&lt;Car> \u0438 GetAllDao&lt;User> \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0433\u0440\u0430\u0444.<\/p>\n<hr\/>\n<h2>4. \u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u043f\u043b\u044e\u0441\u044b \u0442\u0430\u043a \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u043d\u0435 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b.<\/p>\n<blockquote>\n<p>\u00ab\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043a\u0443\u0441\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u0441\u043b\u043e\u0432\u043d\u043e \u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0434\u0440\u043e\u0436\u0430\u0442 \u0440\u0443\u043a\u0438, \u0438 \u043e\u043d \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442.\u00bb &#8212; \u0420\u043e\u0431\u0435\u0440\u0442 \u041c\u0430\u0440\u0442\u0438\u043d.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0445 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043b\u044e\u0441\u043e\u0432.<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 Dao. \u041f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0432\u044b \u0441\u0430\u043c\u0438 \u0437\u043d\u0430\u0435\u0442\u0435. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 Dao \u0441\u0432\u0435\u0434\u0435\u043d\u0430 \u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443 \u0438 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0410 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0435 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c <em>Interface Segregation Principle<\/em> \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Open%E2%80%93closed_principle#:~:text=In%20object%2Doriented%20programming%2C%20the,without%20modifying%20its%20source%20code.\" rel=\"noopener noreferrer nofollow\"><em>Open-Closed Principle<\/em><\/a><em>.<\/em><\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435(\u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u044f \u043c\u043e\u0433\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435).<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438:<\/p>\n<ol>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 runtime. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u044d\u0442\u043e\u0442 \u043c\u0438\u043d\u0443\u0441 \u043d\u0438\u0432\u0435\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Observable \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c Flow, PagingSource \u0438 \u0442.\u0434.) \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0437\u0430 \u043a\u0430\u043a\u0438\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043d\u0430\u0434\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"kotlin\">interface GetPagingSourceDao&lt;T : Any> {    @RawQuery   fun getPagingSource(query: SimpleSQLiteQuery): PagingSource&lt;Int, T>  }  @Dao interface CharacterDao : GetPagingSourceDao&lt;Character> {    @RawQuery(observedEntities = [Character::class])   override fun getPagingSource(     query: SimpleSQLiteQuery   ): PagingSource&lt;Int, Charater>  }<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u041d\u0435\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432 \u0433\u043b\u0430\u0437\u0430\u0445 \u043d\u043e\u0432\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441 RawQuery \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u043c\u0430\u043b\u043e \u043b\u044e\u0434\u0435\u0439, \u043d\u043e\u0432\u044b\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0439\u043c\u0435\u0442 \u043a \u0447\u0435\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 DI Class&lt;Entity> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 RawQuery \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0439 Helper;<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 Dao(\u043a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435);<\/p>\n<\/li>\n<li>\n<p>RawQuery \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c. (\u041e\u0441\u043e\u0431\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u043f\u0440\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c Update \u0438\u043b\u0438 Delete \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u043e\u043d \u0438 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d);<\/p>\n<\/li>\n<li>\n<p>TableName \u0432 Entity \u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439, \u0438\u043d\u0430\u0447\u0435 \u043b\u043e\u0433\u0438\u043a\u0430 simpleName \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c(\u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u043d\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f).<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0439 playground \u0433\u0434\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 <a href=\"https:\/\/github.com\/HalfAPum\/Playground\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/HalfAPum\/Playground<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/668564\/\"> https:\/\/habr.com\/ru\/post\/668564\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-333805","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333805"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333805\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}