From d30650bad30d53b5fb6c4e5c9499b71c577cf849 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Jan 2023 16:33:17 +0100 Subject: [PATCH] Fixes "0 wird nicht benutzt" --- src/de/steamwar/sql/NodeMember.java | 2 +- src/de/steamwar/sql/SchematicNode.java | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/sql/NodeMember.java b/src/de/steamwar/sql/NodeMember.java index a952028..e25764e 100644 --- a/src/de/steamwar/sql/NodeMember.java +++ b/src/de/steamwar/sql/NodeMember.java @@ -85,7 +85,7 @@ public class NodeMember { } public void setParentId(Integer parentId) { - this.parentId = parentId == null || parentId == 0 ? null : parentId; + this.parentId = parentId; updateParent.update(this.parentId, nodeId, userId); } } diff --git a/src/de/steamwar/sql/SchematicNode.java b/src/de/steamwar/sql/SchematicNode.java index b0064c6..ca03c0a 100644 --- a/src/de/steamwar/sql/SchematicNode.java +++ b/src/de/steamwar/sql/SchematicNode.java @@ -48,7 +48,7 @@ public class SchematicNode { private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem", "NodeType", "NodeRank", "ReplaceColor", "AllowReplay", "NodeFormat"); private static final Statement delete = table.delete(Table.PRIMARY); - private static final SelectStatement byId = table.select(Table.PRIMARY); + private static final SelectStatement byId = new SelectStatement<>(table, nodeSelector + "WHERE NodeId = ?"); private static final SelectStatement byOwnerNameParent = table.select("OwnerNameParent"); private static final SelectStatement byParent = new SelectStatement<>(table, nodeSelector + "WHERE ParentNode" + Statement.NULL_SAFE_EQUALS + "? ORDER BY NodeName"); private static final SelectStatement dirsByParent = new SelectStatement<>(table, nodeSelector + "WHERE ParentNode" + Statement.NULL_SAFE_EQUALS + "? AND NodeType is NULL ORDER BY NodeName"); @@ -58,10 +58,10 @@ public class SchematicNode { private static final SelectStatement list = new SelectStatement<>(table, "SELECT * FROM EffectiveSchematicNode WHERE EffectiveOwner = ? AND ParentNode" + Statement.NULL_SAFE_EQUALS + "? ORDER BY NodeName"); private static final SelectStatement byParentName = new SelectStatement<>(table, "SELECT * FROM EffectiveSchematicNode WHERE EffectiveOwner = ? AND ParentNode" + Statement.NULL_SAFE_EQUALS + "? AND NodeName = ? ORDER BY NodeName"); private static final SelectStatement schematicAccessibleForUser = new SelectStatement<>(table, "SELECT COUNT(DISTINCT NodeId) FROM EffectiveSchematicNode WHERE EffectiveOwner = ? AND NodeId = ?"); - private static final SelectStatement accessibleByUserTypeInParent = new SelectStatement<>(table, "WITH RECURSIVE RSN AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeType = ? AND EffectiveOwner = ? UNION SELECT SN.NodeId, SN.ParentNode FROM RSN, EffectiveSchematicNode SN WHERE SN.NodeId = RSN.ParentNode AND EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, RSN.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE RSN.ParentNode" + Statement.NULL_SAFE_EQUALS + "?"); + private static final SelectStatement accessibleByUserTypeInParent = new SelectStatement<>(table, "WITH RECURSIVE RSN AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeType = ? AND EffectiveOwner = ? UNION SELECT SN.NodeId, SN.ParentNode FROM RSN, EffectiveSchematicNode SN WHERE SN.NodeId = RSN.ParentNode AND EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, RSN.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank, SN.ReplaceColor, SN.AllowReplay, SN.NodeFormat FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE RSN.ParentNode" + Statement.NULL_SAFE_EQUALS + "?"); private static final SelectStatement accessibleByUserType = new SelectStatement<>(table, "SELECT * FROM EffectiveSchematicNode WHERE EffectiveOwner = ? AND NodeType = ?"); private static final SelectStatement byIdAndUser = new SelectStatement<>(table, "SELECT * FROM EffectiveSchematicNode WHERE EffectiveOwner = ? AND NodeId = ?"); - private static final SelectStatement allParentsOfNode = new SelectStatement<>(table, "WITH RECURSIVE R AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeId = ? AND EffectiveOwner = ? UNION SELECT E.NodeId, E.ParentNode FROM R, EffectiveSchematicNode E WHERE R.ParentNode = E.NodeId AND E.EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, R.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank FROM R INNER JOIN SchematicNode SN ON SN.NodeId = R.NodeId"); + private static final SelectStatement allParentsOfNode = new SelectStatement<>(table, "WITH RECURSIVE R AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeId = ? AND EffectiveOwner = ? UNION SELECT E.NodeId, E.ParentNode FROM R, EffectiveSchematicNode E WHERE R.ParentNode = E.NodeId AND E.EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, R.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank, SN.ReplaceColor, SN.AllowReplay, SN.NodeFormat FROM R INNER JOIN SchematicNode SN ON SN.NodeId = R.NodeId"); static { NodeMember.init(); @@ -71,7 +71,7 @@ public class SchematicNode { private final int nodeId; @Field(keys = {"OwnerNameParent"}) private final int nodeOwner; - @Field + @Field(def = "0") @Getter private final int effectiveOwner; @Field(keys = {"OwnerNameParent"}) @@ -161,7 +161,7 @@ public class SchematicNode { } public static List parentsOfNode(SteamwarUser user, Integer id) { - return allParentsOfNode.listSelect(id, user, user, user).stream().filter(n -> n.getId() != id).collect(Collectors.toList()); + return allParentsOfNode.listSelect(id, user, user, user); } private static Map> map(List in) { @@ -290,7 +290,7 @@ public class SchematicNode { } if (s.contains("/")) { String[] layers = s.split("/"); - Optional currentNode = Optional.ofNullable(SchematicNode.byParentName(user, 0, layers[0])); + Optional currentNode = Optional.ofNullable(SchematicNode.byParentName(user, null, layers[0])); for (int i = 1; i < layers.length; i++) { int finalI = i; Optional node = currentNode.map(effectiveSchematicNode -> SchematicNode.byParentName(user, effectiveSchematicNode.getId(), layers[finalI])); @@ -305,7 +305,7 @@ public class SchematicNode { } return currentNode.orElse(null); } else { - return SchematicNode.byParentName(user, 0, s); + return SchematicNode.byParentName(user, null, s); } } @@ -484,14 +484,12 @@ public class SchematicNode { return ((SchematicNode) obj).getId() == nodeId; } - @Deprecated public String generateBreadcrumbs(SteamwarUser user) { - return generateBreadcrumbs(); + return byIdAndUser(user, nodeId).generateBreadcrumbs(); } - @Deprecated public String generateBreadcrumbs(String split, SteamwarUser user) { - return generateBreadcrumbs(split); + return byIdAndUser(user, nodeId).generateBreadcrumbs(split); } public String generateBreadcrumbs() { @@ -556,7 +554,7 @@ public class SchematicNode { List nodes = SchematicNode.list(user, pa.getId()); nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs())); } else { - List nodes = SchematicNode.list(user, 0); + List nodes = SchematicNode.list(user, null); nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : ""))); } list.remove("//copy");