File tree Expand file tree Collapse file tree 8 files changed +22
-58
lines changed
database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao
data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles Expand file tree Collapse file tree 8 files changed +22
-58
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ class TestAuthorDao : AuthorDao {
5757 throw NotImplementedError (" Unused in tests" )
5858 }
5959
60+ override suspend fun upsertAuthors (entities : List <AuthorEntity >) {
61+ entitiesStateFlow.value = entities
62+ }
63+
6064 override suspend fun deleteAuthors (ids : List <String >) {
6165 val idSet = ids.toSet()
6266 entitiesStateFlow.update { entities ->
Original file line number Diff line number Diff line change @@ -85,6 +85,10 @@ class TestNewsResourceDao : NewsResourceDao {
8585 throw NotImplementedError (" Unused in tests" )
8686 }
8787
88+ override suspend fun upsertNewsResources (newsResourceEntities : List <NewsResourceEntity >) {
89+ entitiesStateFlow.value = newsResourceEntities
90+ }
91+
8892 override suspend fun insertOrIgnoreTopicCrossRefEntities (
8993 newsResourceTopicCrossReferences : List <NewsResourceTopicCrossRef >
9094 ) {
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ class TestTopicDao : TopicDao {
6262 throw NotImplementedError (" Unused in tests" )
6363 }
6464
65+ override suspend fun upsertTopics (entities : List <TopicEntity >) {
66+ entitiesStateFlow.value = entities
67+ }
68+
6569 override suspend fun deleteTopics (ids : List <String >) {
6670 val idSet = ids.toSet()
6771 entitiesStateFlow.update { entities ->
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ import androidx.room.Dao
2020import androidx.room.Insert
2121import androidx.room.OnConflictStrategy
2222import androidx.room.Query
23- import androidx.room.Transaction
2423import androidx.room.Update
24+ import androidx.room.Upsert
2525import com.google.samples.apps.nowinandroid.core.database.model.AuthorEntity
2626import kotlinx.coroutines.flow.Flow
2727
@@ -56,12 +56,8 @@ interface AuthorDao {
5656 /* *
5757 * Inserts or updates [entities] in the db under the specified primary keys
5858 */
59- @Transaction
60- suspend fun upsertAuthors (entities : List <AuthorEntity >) = upsert(
61- items = entities,
62- insertMany = ::insertOrIgnoreAuthors,
63- updateMany = ::updateAuthors
64- )
59+ @Upsert
60+ suspend fun upsertAuthors (entities : List <AuthorEntity >)
6561
6662 /* *
6763 * Deletes rows in the db matching the specified [ids]
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import androidx.room.OnConflictStrategy
2222import androidx.room.Query
2323import androidx.room.Transaction
2424import androidx.room.Update
25+ import androidx.room.Upsert
2526import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceAuthorCrossRef
2627import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
2728import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef
@@ -80,12 +81,8 @@ interface NewsResourceDao {
8081 /* *
8182 * Inserts or updates [newsResourceEntities] in the db under the specified primary keys
8283 */
83- @Transaction
84- suspend fun upsertNewsResources (newsResourceEntities : List <NewsResourceEntity >) = upsert(
85- items = newsResourceEntities,
86- insertMany = ::insertOrIgnoreNewsResources,
87- updateMany = ::updateNewsResources
88- )
84+ @Upsert
85+ suspend fun upsertNewsResources (newsResourceEntities : List <NewsResourceEntity >)
8986
9087 @Insert(onConflict = OnConflictStrategy .IGNORE )
9188 suspend fun insertOrIgnoreTopicCrossRefEntities (
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ import androidx.room.Dao
2020import androidx.room.Insert
2121import androidx.room.OnConflictStrategy
2222import androidx.room.Query
23- import androidx.room.Transaction
2423import androidx.room.Update
24+ import androidx.room.Upsert
2525import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
2626import kotlinx.coroutines.flow.Flow
2727
@@ -64,12 +64,8 @@ interface TopicDao {
6464 /* *
6565 * Inserts or updates [entities] in the db under the specified primary keys
6666 */
67- @Transaction
68- suspend fun upsertTopics (entities : List <TopicEntity >) = upsert(
69- items = entities,
70- insertMany = ::insertOrIgnoreTopics,
71- updateMany = ::updateTopics
72- )
67+ @Upsert
68+ suspend fun upsertTopics (entities : List <TopicEntity >)
7369
7470 /* *
7571 * Deletes rows in the db matching the specified [ids]
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ protobuf = "3.21.5"
4646protobufPlugin = " 0.8.19"
4747retrofit = " 2.9.0"
4848retrofitKotlinxSerializationJson = " 0.8.0"
49- room = " 2.4.3 "
49+ room = " 2.5.0-alpha03 "
5050secrets = " 2.0.1"
5151turbine = " 0.8.0"
5252
You can’t perform that action at this time.
0 commit comments