From a8eaf3daa71f1dedee1b560168e435a93d88898c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 28 Oct 2025 21:31:57 +0100 Subject: [PATCH] Fixes Signed-off-by: Chaoscaot --- .../SQL/src/de/steamwar/sql/SchematicNode.kt | 24 +++++++++---------- .../SQL/src/de/steamwar/sql/SteamwarUser.kt | 4 ++-- .../SQL/src/de/steamwar/sql/UserConfig.kt | 16 ++++++------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.kt b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.kt index c058df2b..d1495b46 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.kt @@ -59,7 +59,7 @@ class SchematicNode(id: EntityID) : IntEntity(id) { @JvmStatic fun getAll(user: SteamwarUser) = fromSql( - "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ?} UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.* FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId", + "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.* FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId", listOf( IntegerColumnType() to user.getId(), IntegerColumnType() to user.getId() @@ -72,11 +72,10 @@ class SchematicNode(id: EntityID) : IntEntity(id) { @JvmStatic fun list(user: SteamwarUser, schematicId: Int?) = fromSql( - "SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName", + "SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName", listOf( IntegerColumnType() to schematicId, IntegerColumnType() to user.getId(), - IntegerColumnType() to user.getId(), IntegerColumnType() to schematicId, IntegerColumnType() to user.getId(), IntegerColumnType() to schematicId, @@ -86,12 +85,11 @@ class SchematicNode(id: EntityID) : IntEntity(id) { @JvmStatic fun byParentName(user: SteamwarUser, schematicId: Int?, name: String) = fromSql( - "SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?", + "SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?", listOf( IntegerColumnType() to schematicId, IntegerColumnType() to user.getId(), VarCharColumnType() to name, - IntegerColumnType() to user.getId(), IntegerColumnType() to schematicId, IntegerColumnType() to user.getId(), IntegerColumnType() to schematicId, @@ -342,8 +340,8 @@ class SchematicNode(id: EntityID) : IntEntity(id) { fun isDir() = nodeType == null private fun checkDir(block: () -> T): T { - if (!isDir()) { - throw IllegalStateException("Node is not a directory") + if (isDir()) { + throw IllegalStateException("Node is a directory") } return block() @@ -387,12 +385,12 @@ class SchematicNode(id: EntityID) : IntEntity(id) { return breadcrumbs } - fun generateBreadcrumbs(split: String, user: SteamwarUser): String { + fun generateBreadcrumbs(split: String, user: SteamwarUser): String = useDb { val builder: StringBuilder = StringBuilder(name) if (isDir()) { builder.append(split) } - var currentNode: SchematicNode? = this + var currentNode: SchematicNode? = this@SchematicNode while (currentNode != null) { currentNode = currentNode .let { @@ -404,12 +402,12 @@ class SchematicNode(id: EntityID) : IntEntity(id) { builder.insert(0, split).insert(0, it.name) } } - return builder.toString() + return@useDb builder.toString() } - fun generateBreadcrumbsMap(user: SteamwarUser): List> { + fun generateBreadcrumbsMap(user: SteamwarUser): List> = useDb { val map = mutableListOf>() - var currentNode: SchematicNode? = this + var currentNode: SchematicNode? = this@SchematicNode while (currentNode != null) { currentNode = currentNode .also { @@ -421,7 +419,7 @@ class SchematicNode(id: EntityID) : IntEntity(id) { } ?.let { findById(it) } } - return map + return@useDb map } fun accessibleByUser(user: SteamwarUser) = schematicAccessibleForUser(user, nodeId) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt index c48351bc..3ea8aa6e 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt @@ -42,7 +42,7 @@ object SteamwarUserTable : IntIdTable("UserData", "id") { val team = integer("Team") val leader = bool("Leader") val locale = varchar("Locale", 16).nullable() - val manualeLocale = bool("ManualeLocale") + val manualLocale = bool("ManualLocale") val bedrock = bool("Bedrock") val password = text("Password").nullable() val discordId = long("DiscordId").nullable() @@ -171,7 +171,7 @@ class SteamwarUser(id: EntityID): IntEntity(id) { var locale: Locale by SteamwarUserTable.locale .transform({ it.toLanguageTag() }, { it?.let { Locale.forLanguageTag(it) } ?: Locale.getDefault()}) - var manualLocale by SteamwarUserTable.manualeLocale + var manualLocale by SteamwarUserTable.manualLocale var bedrock by SteamwarUserTable.bedrock private var passwordInternal by SteamwarUserTable.password var password: String? diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserConfig.kt b/CommonCore/SQL/src/de/steamwar/sql/UserConfig.kt index 7d8b4ff4..11bc2e4d 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserConfig.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/UserConfig.kt @@ -31,22 +31,22 @@ import org.jetbrains.exposed.v1.jdbc.upsert import java.util.UUID object UserConfigTable: CompositeIdTable("UserConfig") { - val userId = reference("userId", SteamwarUserTable) - val key = varchar("Key", 32) - val value = text("Value") + val userId = reference("User", SteamwarUserTable) + val config = varchar("Config", 32) + val value = text("Value", eagerLoading = true) - override val primaryKey = PrimaryKey(userId, key) + override val primaryKey = PrimaryKey(userId, config) } class UserConfig(id: EntityID): CompositeEntity(id) { val userId by UserConfigTable.userId - val key by UserConfigTable.key + val config by UserConfigTable.config var value by UserConfigTable.value companion object: CompositeEntityClass(UserConfigTable) { @JvmStatic fun getConfig(userId: Int, config: String) = useDb { - find { (UserConfigTable.userId eq userId) and (UserConfigTable.key eq config) }.firstOrNull()?.value + find { (UserConfigTable.userId eq userId) and (UserConfigTable.config eq config) }.firstOrNull()?.value } @JvmStatic @@ -59,7 +59,7 @@ class UserConfig(id: EntityID): CompositeEntity(id) { } else { UserConfigTable.upsert { it[UserConfigTable.userId] = id - it[UserConfigTable.key] = config + it[UserConfigTable.config] = config it[UserConfigTable.value] = value } } @@ -70,7 +70,7 @@ class UserConfig(id: EntityID): CompositeEntity(id) { @JvmStatic fun removePlayerConfig(id: Int, config: String) = useDb { - find { (UserConfigTable.userId eq id) and (UserConfigTable.key eq config) }.firstOrNull()?.delete() + find { (UserConfigTable.userId eq id) and (UserConfigTable.config eq config) }.firstOrNull()?.delete() } @JvmStatic