return old transactions
This commit is contained in:
@@ -1,2 +1 @@
|
||||
exposed_version=0.23.1
|
||||
test_sqlite_version=3.28.0
|
||||
|
@@ -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<ContentId> {
|
||||
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<out RegisteredContent> {
|
||||
return newSuspendedTransaction(
|
||||
return transaction(
|
||||
db = database
|
||||
) {
|
||||
selectAll().count() to selectAll().paginate(pagination).map { it[idColumn] }
|
||||
|
@@ -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<ContentId> {
|
||||
return newSuspendedTransaction(
|
||||
fun getPostContents(postId: PostId): List<ContentId> {
|
||||
return transaction(
|
||||
db = database
|
||||
) {
|
||||
select { postIdColumn.eq(postId) }.map { it[contentIdColumn] }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getContentPosts(contentId: ContentId): List<PostId> {
|
||||
return newSuspendedTransaction(
|
||||
fun getContentPosts(contentId: ContentId): List<PostId> {
|
||||
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<RegisteredPost> = 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<PostId> {
|
||||
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<RegisteredPost> {
|
||||
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<RegisteredPost> {
|
||||
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<RegisteredPost> {
|
||||
return newSuspendedTransaction(
|
||||
return transaction(
|
||||
db = database
|
||||
) {
|
||||
val posts = selectAll().paginate(pagination).orderBy(creationDateColumn).map {
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user