fix table name parameter in keyvalue and onetomany repos

This commit is contained in:
InsanusMokrassar 2020-10-17 18:51:48 +06:00
parent c5a32e2b1b
commit 02ad1a748e
4 changed files with 13 additions and 13 deletions

View File

@ -12,11 +12,13 @@ import org.jetbrains.exposed.sql.transactions.transaction
open class ExposedKeyValueRepo<Key, Value>(
database: Database,
keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>
valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null
) : StandardKeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
database,
keyColumnAllocator,
valueColumnAllocator
valueColumnAllocator,
tableName
) {
private val onNewValueChannel = BroadcastChannel<Pair<Key, Value>>(Channel.BUFFERED)
private val onValueRemovedChannel = BroadcastChannel<Key>(Channel.BUFFERED)
@ -24,8 +26,6 @@ open class ExposedKeyValueRepo<Key, Value>(
override val onNewValue: Flow<Pair<Key, Value>> = onNewValueChannel.asFlow()
override val onValueRemoved: Flow<Key> = onValueRemovedChannel.asFlow()
init { initTable() }
override suspend fun set(k: Key, v: Value) {
transaction(database) {
if (select { keyColumn.eq(k) }.limit(1).any()) {

View File

@ -10,13 +10,12 @@ open class ExposedReadKeyValueRepo<Key, Value>(
override val database: Database,
keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>,
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table() {
tableName: String? = null
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
protected val keyColumn: Column<Key> = keyColumnAllocator()
protected val valueColumn: Column<Value> = valueColumnAllocator()
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
init { initTable() }
override suspend fun get(k: Key): Value? = transaction(database) {
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
}

View File

@ -11,11 +11,13 @@ import org.jetbrains.exposed.sql.transactions.transaction
open class ExposedOneToManyKeyValueRepo<Key, Value>(
database: Database,
keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>
valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null
) : OneToManyKeyValueRepo<Key, Value>, ExposedReadOneToManyKeyValueRepo<Key, Value>(
database,
keyColumnAllocator,
valueColumnAllocator
valueColumnAllocator,
tableName
) {
protected val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
override val onNewValue: Flow<Pair<Key, Value>>
@ -27,8 +29,6 @@ open class ExposedOneToManyKeyValueRepo<Key, Value>(
override val onDataCleared: Flow<Key>
get() = _onDataCleared
init { initTable() }
override suspend fun add(k: Key, v: Value) {
transaction(database) {
insert {

View File

@ -9,8 +9,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
open class ExposedReadOneToManyKeyValueRepo<Key, Value>(
override val database: Database,
keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table() {
valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
protected val keyColumn: Column<Key> = keyColumnAllocator()
protected val valueColumn: Column<Value> = valueColumnAllocator()