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 ca12fb1f..3ee3f58e 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 @@ -6,6 +6,7 @@ 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.transactions.transaction abstract class AbstractExposedReadCRUDRepo( @@ -16,7 +17,7 @@ abstract class AbstractExposedReadCRUDRepo( Table(tableName) { override suspend fun getByPagination(pagination: Pagination): PaginationResult { - return transaction(database) { + return newSuspendedTransaction(db = database) { selectAll().paginate(pagination).map { it.asObject }.createPaginationResult( @@ -26,14 +27,14 @@ abstract class AbstractExposedReadCRUDRepo( } } override suspend fun getById(id: IdType): ObjectType? { - return transaction(database) { + return newSuspendedTransaction(db = database) { select { selectById(id) }.limit(1).firstOrNull() ?.asObject } } - override suspend fun contains(id: IdType): Boolean = transaction(database) { + override suspend fun contains(id: IdType): Boolean = newSuspendedTransaction(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 f8faed4a..7f88cea7 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,6 +8,7 @@ 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( @@ -41,7 +42,7 @@ abstract class AbstractExposedWriteCRUDRepo( override suspend fun create(vararg values: InputValueType): List { onBeforeCreate(*values) - return transaction(database) { + return newSuspendedTransaction(db = database) { values.map { value -> createWithoutNotification(value) } }.also { it.forEach { @@ -52,7 +53,7 @@ abstract class AbstractExposedWriteCRUDRepo( protected open suspend fun onBeforeUpdate(vararg value: UpdatedValuePair) {} private fun updateWithoutNotification(id: IdType, value: InputValueType): ObjectType? { - return transaction(database) { + return transaction(db = database) { update( { selectById(this, id) @@ -82,7 +83,7 @@ abstract class AbstractExposedWriteCRUDRepo( override suspend fun update(vararg values: UpdatedValuePair): List { onBeforeUpdate(*values) return ( - transaction(database) { + newSuspendedTransaction(db = database) { values.map { (id, value) -> updateWithoutNotification(id, value) } }.filter { it != null @@ -96,7 +97,7 @@ abstract class AbstractExposedWriteCRUDRepo( protected open suspend fun onBeforeDelete(vararg ids: IdType) {} override suspend fun deleteById(vararg ids: IdType) { onBeforeDelete(*ids) - transaction(database) { + newSuspendedTransaction(db = database) { deleteWhere(null, null) { selectByIds(ids) } 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 b43a23da..0cc21407 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,6 +6,7 @@ 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( @@ -24,7 +25,7 @@ abstract class AbstractExposedKeyValueRepo( override val onValueRemoved: Flow = onValueRemovedChannel.asFlow() override suspend fun set(k: Key, v: Value) { - transaction(database) { + newSuspendedTransaction(db = database) { if (select { keyColumn.eq(k) }.limit(1).any()) { update({ keyColumn.eq(k) }) { it[valueColumn] = v @@ -40,7 +41,7 @@ abstract class AbstractExposedKeyValueRepo( } override suspend fun unset(k: Key) { - transaction(database) { + newSuspendedTransaction(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 bf33901c..9832d23e 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,6 +4,7 @@ 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( @@ -13,23 +14,23 @@ abstract class AbstractExposedReadKeyValueRepo( ) : StandardReadKeyValueRepo, Table() { override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn) - override suspend fun get(k: Key): Value? = transaction(database) { + override suspend fun get(k: Key): Value? = newSuspendedTransaction(db = database) { select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn) } - override suspend fun contains(key: Key): Boolean = transaction(database) { + override suspend fun contains(key: Key): Boolean = newSuspendedTransaction(db = database) { select { keyColumn.eq(key) }.limit(1).any() } - override suspend fun count(): Long = transaction(database) { selectAll().count() } + override suspend fun count(): Long = newSuspendedTransaction(db = database) { selectAll().count() } - override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = transaction(database) { + override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(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 = transaction(database) { + override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(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 4a587073..dfef59e5 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,6 +4,7 @@ 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( @@ -16,7 +17,7 @@ abstract class AbstractOneToManyExposedKeyValueRepo( database ) { override suspend fun add(k: Key, v: Value) { - transaction(database) { + newSuspendedTransaction(db = database) { insert { it[keyColumn] = k it[valueColumn] = v @@ -25,10 +26,10 @@ abstract class AbstractOneToManyExposedKeyValueRepo( } override suspend fun remove(k: Key, v: Value) { - transaction(database) { deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } } + newSuspendedTransaction(db = database) { deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } } } override suspend fun clear(k: Key) { - transaction(database) { deleteWhere { keyColumn.eq(k) } } + newSuspendedTransaction(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 65161b46..32255198 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,6 +4,7 @@ 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 @@ -16,33 +17,33 @@ abstract class AbstractOneToManyExposedReadKeyValueRepo( protected val keyColumn: Column = keyColumnAllocator() protected val valueColumn: Column = valueColumnAllocator() - override suspend fun count(k: Key): Long = transaction(database) { select { keyColumn.eq(k) }.count() } + override suspend fun count(k: Key): Long = newSuspendedTransaction(db = database) { select { keyColumn.eq(k) }.count() } - override suspend fun count(): Long = transaction(database) { selectAll().count() } + override suspend fun count(): Long = newSuspendedTransaction(db = database) { selectAll().count() } override suspend fun get( k: Key, pagination: Pagination, reversed: Boolean - ): PaginationResult = transaction(database) { + ): PaginationResult = newSuspendedTransaction(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 = transaction(database) { + override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult = newSuspendedTransaction(db = database) { selectAll().paginate(pagination, keyColumn, reversed).map { it[keyColumn] } }.createPaginationResult( pagination, count() ) - override suspend fun contains(k: Key): Boolean = transaction(database) { + override suspend fun contains(k: Key): Boolean = newSuspendedTransaction(db = database) { select { keyColumn.eq(k) }.limit(1).any() } - override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) { + override suspend fun contains(k: Key, v: Value): Boolean = newSuspendedTransaction(db = database) { select { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).any() } }