From a683dab358dd4ce81e00958c15de616a3b74660d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 31 Jul 2020 11:28:27 +0600 Subject: [PATCH] return old transactions --- postssystem.core.exposed/gradle.properties | 1 - .../core/exposed/ExposedContentRepo.kt | 17 ++++---- .../core/exposed/ExposedPostsRepo.kt | 41 +++++++++---------- .../content/BinaryContentHolderRepo.kt | 7 ++-- .../content/SpecialContentHolderRepo.kt | 7 ++-- .../exposed/content/TextContentHolderRepo.kt | 7 ++-- .../exposed/ExposedPostsRepoCommonTests.kt | 2 +- .../gradle.properties | 1 - .../exposed/ExposedPublishingKeysRepo.kt | 23 ++++++----- postssystem.exposed.commons/gradle.properties | 2 +- postssystem.utils.repos.exposed/build.gradle | 2 - .../gradle.properties | 1 - .../exposed/AbstractExposedReadCRUDRepo.kt | 11 ++--- .../exposed/AbstractExposedWriteCRUDRepo.kt | 7 ++-- .../utils/repos/exposed/ExposedCRUDRepo.kt | 5 +-- .../exposed/ExposedTableInitialization.kt | 4 +- .../keyvalue/AbstractExposedKeyValueRepo.kt | 5 +-- .../AbstractExposedReadKeyValueRepo.kt | 11 +++-- .../AbstractOneToManyExposedKeyValueRepo.kt | 7 ++-- ...bstractOneToManyExposedReadKeyValueRepo.kt | 13 +++--- 20 files changed, 75 insertions(+), 99 deletions(-) diff --git a/postssystem.core.exposed/gradle.properties b/postssystem.core.exposed/gradle.properties index 1576438d..abc24679 100644 --- a/postssystem.core.exposed/gradle.properties +++ b/postssystem.core.exposed/gradle.properties @@ -1,2 +1 @@ -exposed_version=0.23.1 test_sqlite_version=3.28.0 diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentRepo.kt index fd036447..c7bb844f 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentRepo.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentRepo.kt @@ -4,14 +4,13 @@ import com.insanusmokrassar.postssystem.core.content.* import com.insanusmokrassar.postssystem.core.content.api.ContentRepo import com.insanusmokrassar.postssystem.core.exposed.content.* import com.insanusmokrassar.postssystem.core.generateContentId -import com.insanusmokrassar.postssystem.utils.repos.pagination.* import com.insanusmokrassar.postssystem.exposed.commons.paginate +import com.insanusmokrassar.postssystem.utils.repos.pagination.* import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction private val Content.type @@ -58,14 +57,14 @@ private class ContentRepoDatabaseTable( is SpecialContent -> specialHolder.putContent(id, content) } } - override suspend fun getContent(id: ContentId): Content? = newSuspendedTransaction( + override suspend fun getContent(id: ContentId): Content? = transaction( db = database ) { select { idColumn.eq(id) }.limit(1).firstOrNull() ?.get(typeColumn) } ?.holder ?.getContent(id) override suspend fun removeContent(id: ContentId) { - newSuspendedTransaction( + transaction( db = database ) { select { idColumn.eq(id) }.limit(1).firstOrNull() ?.get(typeColumn) @@ -75,7 +74,7 @@ private class ContentRepoDatabaseTable( override suspend fun registerContent(content: Content): RegisteredContent? { val id = generateContentId() val type = content.type - return newSuspendedTransaction( + return transaction( db = database ) { insert { @@ -96,7 +95,7 @@ private class ContentRepoDatabaseTable( } override suspend fun deleteContent(id: ContentId): Boolean { val content = getContentById(id) ?: return false - return newSuspendedTransaction( + return transaction( db = database ) { deleteWhere { @@ -118,7 +117,7 @@ private class ContentRepoDatabaseTable( } override suspend fun getContentsIds(): Set { - return newSuspendedTransaction( + return transaction( db = database ) { selectAll().map { it[idColumn] } @@ -126,14 +125,14 @@ private class ContentRepoDatabaseTable( } override suspend fun getContentById(id: ContentId): RegisteredContent? { val content = getContent(id) ?: return null - return newSuspendedTransaction( + return transaction( db = database ) { select { idColumn.eq(id) }.limit(1).firstOrNull() ?.asRegisteredContent(content) } } override suspend fun getContentByPagination(pagination: Pagination): PaginationResult { - return newSuspendedTransaction( + return transaction( db = database ) { selectAll().count() to selectAll().paginate(pagination).map { it[idColumn] } diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt index 4b9f8957..8e307663 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt @@ -4,15 +4,14 @@ import com.insanusmokrassar.postssystem.core.content.ContentId import com.insanusmokrassar.postssystem.core.generatePostId import com.insanusmokrassar.postssystem.core.post.* import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo -import com.insanusmokrassar.postssystem.utils.repos.pagination.* import com.insanusmokrassar.postssystem.exposed.commons.paginate +import com.insanusmokrassar.postssystem.utils.repos.pagination.* import com.soywiz.klock.* import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction private class PostsRepoContentRelations( @@ -29,24 +28,24 @@ private class PostsRepoContentRelations( } } - suspend fun getPostContents(postId: PostId): List { - return newSuspendedTransaction( + fun getPostContents(postId: PostId): List { + return transaction( db = database ) { select { postIdColumn.eq(postId) }.map { it[contentIdColumn] } } } - suspend fun getContentPosts(contentId: ContentId): List { - return newSuspendedTransaction( + fun getContentPosts(contentId: ContentId): List { + return transaction( db = database ) { select { contentIdColumn.eq(contentId) }.map { it[postIdColumn] } } } - suspend fun linkPostAndContents(postId: PostId, vararg contentIds: ContentId) { - newSuspendedTransaction( + fun linkPostAndContents(postId: PostId, vararg contentIds: ContentId) { + transaction( db = database ) { val leftToPut = contentIds.toSet() - getPostContents(postId) @@ -58,8 +57,8 @@ private class PostsRepoContentRelations( } } } - suspend fun unlinkPostAndContents(postId: PostId, vararg contentIds: ContentId): Boolean { - return newSuspendedTransaction( + fun unlinkPostAndContents(postId: PostId, vararg contentIds: ContentId): Boolean { + return transaction( db = database ) { deleteWhere { @@ -92,14 +91,12 @@ private class PostsRepoDatabaseTable( override val postUpdatedFlow: Flow = postUpdatedBroadcastChannel.asFlow() init { - transaction ( - db = database - ) { + transaction (db = database) { SchemaUtils.createMissingTablesAndColumns(this@PostsRepoDatabaseTable) } } - private suspend fun ResultRow.toRegisteredPost(): RegisteredPost = get(idColumn).let { id -> + private fun ResultRow.toRegisteredPost(): RegisteredPost = get(idColumn).let { id -> SimpleRegisteredPost( id, contentsTable.getPostContents(id), @@ -109,7 +106,7 @@ private class PostsRepoDatabaseTable( override suspend fun createPost(post: Post): RegisteredPost? { val id = generatePostId() - return newSuspendedTransaction( + return transaction( db = database ) { insert { @@ -124,7 +121,7 @@ private class PostsRepoDatabaseTable( override suspend fun deletePost(id: PostId): Boolean { val post = getPostById(id) ?: return false - return (newSuspendedTransaction( + return (transaction( db = database ) { deleteWhere { idColumn.eq(id) } @@ -137,7 +134,7 @@ private class PostsRepoDatabaseTable( } override suspend fun updatePostContent(postId: PostId, post: Post): Boolean { - return newSuspendedTransaction( + return transaction( db = database ) { val alreadyLinked = contentsTable.getPostContents(postId) @@ -155,7 +152,7 @@ private class PostsRepoDatabaseTable( } } override suspend fun getPostsIds(): Set { - return newSuspendedTransaction( + return transaction( db = database ) { selectAll().map { it[idColumn] }.toSet() @@ -163,7 +160,7 @@ private class PostsRepoDatabaseTable( } override suspend fun getPostById(id: PostId): RegisteredPost? { - return newSuspendedTransaction( + return transaction( db = database ) { select { idColumn.eq(id) }.firstOrNull() ?.toRegisteredPost() @@ -171,7 +168,7 @@ private class PostsRepoDatabaseTable( } override suspend fun getPostsByContent(id: ContentId): List { - return newSuspendedTransaction( + return transaction( db = database ) { val postsIds = contentsTable.getContentPosts(id) @@ -180,7 +177,7 @@ private class PostsRepoDatabaseTable( } override suspend fun getPostsByCreatingDates(from: DateTime, to: DateTime): List { - return newSuspendedTransaction( + return transaction( db = database ) { select { creationDateColumn.between(from, to) }.map { it.toRegisteredPost() } @@ -188,7 +185,7 @@ private class PostsRepoDatabaseTable( } override suspend fun getPostsByPagination(pagination: Pagination): PaginationResult { - return newSuspendedTransaction( + return transaction( db = database ) { val posts = selectAll().paginate(pagination).orderBy(creationDateColumn).map { diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt index 8fff94ea..8c74e05d 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt @@ -4,7 +4,6 @@ import com.insanusmokrassar.postssystem.core.content.BinaryContent import com.insanusmokrassar.postssystem.core.content.ContentId import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.api.ExposedBlob -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction private class BinaryContentHolderRepoTable( @@ -24,7 +23,7 @@ private class BinaryContentHolderRepoTable( } } - override suspend fun getContent(id: ContentId): BinaryContent? = newSuspendedTransaction ( + override suspend fun getContent(id: ContentId): BinaryContent? = transaction ( db = database ) { select { @@ -41,7 +40,7 @@ private class BinaryContentHolderRepoTable( } override suspend fun removeContent(id: ContentId) { - newSuspendedTransaction( + transaction( db = database ) { deleteWhere { idColumn.eq(id) } @@ -49,7 +48,7 @@ private class BinaryContentHolderRepoTable( } override suspend fun putContent(id: ContentId, content: BinaryContent) { - newSuspendedTransaction( + transaction( db = database ) { insert { diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt index f15eeb62..14f89040 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt @@ -3,7 +3,6 @@ package com.insanusmokrassar.postssystem.core.exposed.content import com.insanusmokrassar.postssystem.core.content.ContentId import com.insanusmokrassar.postssystem.core.content.SpecialContent import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction private class SpecialContentHolderRepoTable( @@ -21,7 +20,7 @@ private class SpecialContentHolderRepoTable( } } - override suspend fun getContent(id: ContentId): SpecialContent? = newSuspendedTransaction( + override suspend fun getContent(id: ContentId): SpecialContent? = transaction( db = database ) { select { @@ -32,7 +31,7 @@ private class SpecialContentHolderRepoTable( } override suspend fun removeContent(id: ContentId) { - newSuspendedTransaction( + transaction( db = database ) { deleteWhere { idColumn.eq(id) } @@ -40,7 +39,7 @@ private class SpecialContentHolderRepoTable( } override suspend fun putContent(id: ContentId, content: SpecialContent) { - newSuspendedTransaction( + transaction( db = database ) { insert { diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt index f2d395aa..c0e18123 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt @@ -3,7 +3,6 @@ package com.insanusmokrassar.postssystem.core.exposed.content import com.insanusmokrassar.postssystem.core.content.ContentId import com.insanusmokrassar.postssystem.core.content.TextContent import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction private class TextContentHolderRepoTable( @@ -21,7 +20,7 @@ private class TextContentHolderRepoTable( } } - override suspend fun getContent(id: ContentId): TextContent? = newSuspendedTransaction( + override suspend fun getContent(id: ContentId): TextContent? = transaction( db = database ) { select { @@ -32,7 +31,7 @@ private class TextContentHolderRepoTable( } override suspend fun removeContent(id: ContentId) { - newSuspendedTransaction( + transaction( db = database ) { deleteWhere { idColumn.eq(id) } @@ -40,7 +39,7 @@ private class TextContentHolderRepoTable( } override suspend fun putContent(id: ContentId, content: TextContent) { - newSuspendedTransaction( + transaction( db = database ) { insert { diff --git a/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt index 4765e576..7773949f 100644 --- a/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt +++ b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt @@ -1,7 +1,7 @@ package com.insanusmokrassar.postssystem.core.exposed import com.insanusmokrassar.postssystem.core.post.SimplePost -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.* import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.transactions.transactionManager import java.io.File diff --git a/postssystem.core.publishing.exposed/gradle.properties b/postssystem.core.publishing.exposed/gradle.properties index 1576438d..abc24679 100644 --- a/postssystem.core.publishing.exposed/gradle.properties +++ b/postssystem.core.publishing.exposed/gradle.properties @@ -1,2 +1 @@ -exposed_version=0.23.1 test_sqlite_version=3.28.0 diff --git a/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt b/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt index 8c9fdc98..e028242e 100644 --- a/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt +++ b/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt @@ -4,7 +4,6 @@ import com.insanusmokrassar.postssystem.core.post.PostId import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction class ExposedPublishingKeysRepo( @@ -22,29 +21,31 @@ class ExposedPublishingKeysRepo( } } - override suspend fun getPostIdByTriggerControlKey(key: TriggerControlKey): PostId? = newSuspendedTransaction( + override suspend fun getPostIdByTriggerControlKey(key: TriggerControlKey): PostId? = transaction( db = database ) { select { triggerControlKeyColumn.eq(key) }.limit(1).firstOrNull() ?.getOrNull(postIdColumn) } - override suspend fun getTriggerControlKeyByPostId(postId: PostId): TriggerControlKey? = newSuspendedTransaction( + override suspend fun getTriggerControlKeyByPostId(postId: PostId): TriggerControlKey? = transaction( db = database ) { select { postIdColumn.eq(postId) }.limit(1).firstOrNull() ?.getOrNull(triggerControlKeyColumn) } - override suspend fun setPostTriggerControlKey(postId: PostId, key: TriggerControlKey): Boolean = newSuspendedTransaction( - db = database - ) { + override suspend fun setPostTriggerControlKey(postId: PostId, key: TriggerControlKey): Boolean { unsetPostTriggerControlKey(postId) - insert { - it[postIdColumn] = postId - it[triggerControlKeyColumn] = triggerControlKeyColumn - }.getOrNull(postIdColumn) == postId + return transaction( + db = database + ) { + insert { + it[postIdColumn] = postId + it[triggerControlKeyColumn] = triggerControlKeyColumn + }.getOrNull(postIdColumn) == postId + } } - override suspend fun unsetPostTriggerControlKey(postId: PostId): Boolean = newSuspendedTransaction( + override suspend fun unsetPostTriggerControlKey(postId: PostId): Boolean = transaction( db = database ) { deleteWhere { diff --git a/postssystem.exposed.commons/gradle.properties b/postssystem.exposed.commons/gradle.properties index 1576438d..51e36b3d 100644 --- a/postssystem.exposed.commons/gradle.properties +++ b/postssystem.exposed.commons/gradle.properties @@ -1,2 +1,2 @@ -exposed_version=0.23.1 +exposed_version=0.26.1 test_sqlite_version=3.28.0 diff --git a/postssystem.utils.repos.exposed/build.gradle b/postssystem.utils.repos.exposed/build.gradle index d6ec3967..cd67605a 100644 --- a/postssystem.utils.repos.exposed/build.gradle +++ b/postssystem.utils.repos.exposed/build.gradle @@ -32,8 +32,6 @@ repositories { dependencies { api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - api "org.jetbrains.exposed:exposed-core:$exposed_version" - api "org.jetbrains.exposed:exposed-jdbc:$exposed_version" if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { api "com.insanusmokrassar:postssystem.utils.repos:$core_version" diff --git a/postssystem.utils.repos.exposed/gradle.properties b/postssystem.utils.repos.exposed/gradle.properties index 1576438d..abc24679 100644 --- a/postssystem.utils.repos.exposed/gradle.properties +++ b/postssystem.utils.repos.exposed/gradle.properties @@ -1,2 +1 @@ -exposed_version=0.23.1 test_sqlite_version=3.28.0 diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedReadCRUDRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedReadCRUDRepo.kt index 3ee3f58e..f6cbc2fc 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedReadCRUDRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedReadCRUDRepo.kt @@ -3,10 +3,7 @@ package com.insanusmokrassar.postssystem.utils.repos.exposed import com.insanusmokrassar.postssystem.exposed.commons.paginate import com.insanusmokrassar.postssystem.utils.repos.ReadStandardCRUDRepo import com.insanusmokrassar.postssystem.utils.repos.pagination.* -import org.jetbrains.exposed.sql.Table -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.selectAll -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction +import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction abstract class AbstractExposedReadCRUDRepo( @@ -17,7 +14,7 @@ abstract class AbstractExposedReadCRUDRepo( Table(tableName) { override suspend fun getByPagination(pagination: Pagination): PaginationResult { - return newSuspendedTransaction(db = database) { + return transaction(db = database) { selectAll().paginate(pagination).map { it.asObject }.createPaginationResult( @@ -27,14 +24,14 @@ abstract class AbstractExposedReadCRUDRepo( } } override suspend fun getById(id: IdType): ObjectType? { - return newSuspendedTransaction(db = database) { + return transaction(db = database) { select { selectById(id) }.limit(1).firstOrNull() ?.asObject } } - override suspend fun contains(id: IdType): Boolean = newSuspendedTransaction(db = database) { + override suspend fun contains(id: IdType): Boolean = transaction(db = database) { select { selectById(id) }.limit(1).any() } } diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt index 7f88cea7..a718dfb2 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt @@ -8,7 +8,6 @@ import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.InsertStatement import org.jetbrains.exposed.sql.statements.UpdateStatement -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction abstract class AbstractExposedWriteCRUDRepo( @@ -42,7 +41,7 @@ abstract class AbstractExposedWriteCRUDRepo( override suspend fun create(vararg values: InputValueType): List { onBeforeCreate(*values) - return newSuspendedTransaction(db = database) { + return transaction(db = database) { values.map { value -> createWithoutNotification(value) } }.also { it.forEach { @@ -83,7 +82,7 @@ abstract class AbstractExposedWriteCRUDRepo( override suspend fun update(vararg values: UpdatedValuePair): List { onBeforeUpdate(*values) return ( - newSuspendedTransaction(db = database) { + transaction(db = database) { values.map { (id, value) -> updateWithoutNotification(id, value) } }.filter { it != null @@ -97,7 +96,7 @@ abstract class AbstractExposedWriteCRUDRepo( protected open suspend fun onBeforeDelete(vararg ids: IdType) {} override suspend fun deleteById(vararg ids: IdType) { onBeforeDelete(*ids) - newSuspendedTransaction(db = database) { + transaction(db = database) { deleteWhere(null, null) { selectByIds(ids) } diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedCRUDRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedCRUDRepo.kt index 6f034bb7..243e24c1 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedCRUDRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedCRUDRepo.kt @@ -1,9 +1,6 @@ package com.insanusmokrassar.postssystem.utils.repos.exposed -import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.Op -import org.jetbrains.exposed.sql.ResultRow -import org.jetbrains.exposed.sql.SqlExpressionBuilder +import org.jetbrains.exposed.sql.* interface ExposedCRUDRepo { val database: Database diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedTableInitialization.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedTableInitialization.kt index c8bae5f8..e4ae768a 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedTableInitialization.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/ExposedTableInitialization.kt @@ -1,8 +1,6 @@ package com.insanusmokrassar.postssystem.utils.repos.exposed -import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.SchemaUtils -import org.jetbrains.exposed.sql.Table +import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction fun Table.initTable(database: Database) { diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt index 0cc21407..0ce06a7d 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt @@ -6,7 +6,6 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction abstract class AbstractExposedKeyValueRepo( @@ -25,7 +24,7 @@ abstract class AbstractExposedKeyValueRepo( override val onValueRemoved: Flow = onValueRemovedChannel.asFlow() override suspend fun set(k: Key, v: Value) { - newSuspendedTransaction(db = database) { + transaction(db = database) { if (select { keyColumn.eq(k) }.limit(1).any()) { update({ keyColumn.eq(k) }) { it[valueColumn] = v @@ -41,7 +40,7 @@ abstract class AbstractExposedKeyValueRepo( } override suspend fun unset(k: Key) { - newSuspendedTransaction(db = database) { + transaction(db = database) { deleteWhere { keyColumn.eq(k) } } onValueRemovedChannel.send(k) diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt index 9832d23e..0063aad7 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt @@ -4,7 +4,6 @@ import com.insanusmokrassar.postssystem.exposed.commons.paginate import com.insanusmokrassar.postssystem.utils.repos.StandardReadKeyValueRepo import com.insanusmokrassar.postssystem.utils.repos.pagination.* import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction abstract class AbstractExposedReadKeyValueRepo( @@ -14,23 +13,23 @@ abstract class AbstractExposedReadKeyValueRepo( ) : StandardReadKeyValueRepo, Table() { override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn) - override suspend fun get(k: Key): Value? = newSuspendedTransaction(db = database) { + override suspend fun get(k: Key): Value? = transaction(db = database) { select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn) } - override suspend fun contains(key: Key): Boolean = newSuspendedTransaction(db = database) { + override suspend fun contains(key: Key): Boolean = transaction(db = database) { select { keyColumn.eq(key) }.limit(1).any() } - override suspend fun count(): Long = newSuspendedTransaction(db = database) { selectAll().count() } + override suspend fun count(): Long = transaction(db = database) { selectAll().count() } - override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(db = database) { + override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = transaction(db = database) { selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map { it[keyColumn] } }.createPaginationResult(pagination, count()) - override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(db = database) { + override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult = transaction(db = database) { selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map { it[valueColumn] } diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedKeyValueRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedKeyValueRepo.kt index dfef59e5..63b24b7b 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedKeyValueRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedKeyValueRepo.kt @@ -4,7 +4,6 @@ import com.insanusmokrassar.budgetmanager.core.utils.repo.onetomany.AbstractOneT import com.insanusmokrassar.budgetmanager.core.utils.repo.onetomany.ColumnAllocator import com.insanusmokrassar.postssystem.utils.repos.OneToManyKeyValueRepo import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction abstract class AbstractOneToManyExposedKeyValueRepo( @@ -17,7 +16,7 @@ abstract class AbstractOneToManyExposedKeyValueRepo( database ) { override suspend fun add(k: Key, v: Value) { - newSuspendedTransaction(db = database) { + transaction(db = database) { insert { it[keyColumn] = k it[valueColumn] = v @@ -26,10 +25,10 @@ abstract class AbstractOneToManyExposedKeyValueRepo( } override suspend fun remove(k: Key, v: Value) { - newSuspendedTransaction(db = database) { deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } } + transaction(db = database) { deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } } } override suspend fun clear(k: Key) { - newSuspendedTransaction(db = database) { deleteWhere { keyColumn.eq(k) } } + transaction(db = database) { deleteWhere { keyColumn.eq(k) } } } } diff --git a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedReadKeyValueRepo.kt b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedReadKeyValueRepo.kt index 32255198..10eb5c31 100644 --- a/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedReadKeyValueRepo.kt +++ b/postssystem.utils.repos.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/utils/repos/exposed/onetomany/AbstractOneToManyExposedReadKeyValueRepo.kt @@ -4,7 +4,6 @@ import com.insanusmokrassar.postssystem.exposed.commons.paginate import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo import com.insanusmokrassar.postssystem.utils.repos.pagination.* import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction typealias ColumnAllocator = Table.() -> Column @@ -17,33 +16,33 @@ abstract class AbstractOneToManyExposedReadKeyValueRepo( protected val keyColumn: Column = keyColumnAllocator() protected val valueColumn: Column = valueColumnAllocator() - override suspend fun count(k: Key): Long = newSuspendedTransaction(db = database) { select { keyColumn.eq(k) }.count() } + override suspend fun count(k: Key): Long = transaction(db = database) { select { keyColumn.eq(k) }.count() } - override suspend fun count(): Long = newSuspendedTransaction(db = database) { selectAll().count() } + override suspend fun count(): Long = transaction(db = database) { selectAll().count() } override suspend fun get( k: Key, pagination: Pagination, reversed: Boolean - ): PaginationResult = newSuspendedTransaction(db = database) { + ): PaginationResult = transaction(db = database) { select { keyColumn.eq(k) }.paginate(pagination, keyColumn, reversed).map { it[valueColumn] } }.createPaginationResult( pagination, count(k) ) - override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(db = database) { + override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = transaction(db = database) { selectAll().paginate(pagination, keyColumn, reversed).map { it[keyColumn] } }.createPaginationResult( pagination, count() ) - override suspend fun contains(k: Key): Boolean = newSuspendedTransaction(db = database) { + override suspend fun contains(k: Key): Boolean = transaction(db = database) { select { keyColumn.eq(k) }.limit(1).any() } - override suspend fun contains(k: Key, v: Value): Boolean = newSuspendedTransaction(db = database) { + override suspend fun contains(k: Key, v: Value): Boolean = transaction(db = database) { select { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).any() } }