From 6d579b69818a2c4278e7f86544c20f6fda7d82ab Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 23 Dec 2022 23:14:52 +0100 Subject: [PATCH 1/5] Initial Commit --- src/de/steamwar/sql/Event.java | 71 ++++++++++++++++++++++++--- src/de/steamwar/sql/EventFight.java | 44 +++++++++++++++-- src/de/steamwar/sql/SteamwarUser.java | 6 +++ src/de/steamwar/sql/Team.java | 5 ++ 4 files changed, 113 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/sql/Event.java b/src/de/steamwar/sql/Event.java index a4c30e6..b51ee34 100644 --- a/src/de/steamwar/sql/Event.java +++ b/src/de/steamwar/sql/Event.java @@ -21,46 +21,65 @@ package de.steamwar.sql; import de.steamwar.sql.internal.Field; import de.steamwar.sql.internal.SelectStatement; +import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; import java.sql.Timestamp; +import java.util.List; @AllArgsConstructor public class Event { private static final Table table = new Table<>(Event.class); private static final SelectStatement byId = table.select(Table.PRIMARY); + private static final SelectStatement allShort = new SelectStatement<>(table, "SELECT * FROM Event"); + private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly", "spectateSystem"); + private static final Statement update = table.update(Table.PRIMARY, "eventName", "deadline", "start", "end", "schemType", "maximumTeamMembers", "publicSchemsOnly", "spectateSystem"); + private static final Statement delete = table.delete(Table.PRIMARY); + public static Event get(int eventID){ return byId.select(eventID); } + public static List getAllShort(){ + return allShort.listSelect(); + } + + public static Event create(String eventName, Timestamp start, Timestamp end){ + return get(create.insertGetKey(eventName, start, start, end, 5, false, false)); + } + + public static void delete(int eventID){ + delete.update(eventID); + } + @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int eventID; @Getter @Field(keys = {"eventName"}) - private final String eventName; + private String eventName; @Getter @Field - private final Timestamp deadline; + private Timestamp deadline; @Getter @Field - private final Timestamp start; + private Timestamp start; @Getter @Field - private final Timestamp end; + private Timestamp end; @Getter @Field - private final int maximumTeamMembers; + private int maximumTeamMembers; @Field(nullable = true) - private final SchematicType schemType; + private SchematicType schemType; @Field - private final boolean publicSchemsOnly; + private boolean publicSchemsOnly; @Field - private final boolean spectateSystem; + private boolean spectateSystem; public boolean publicSchemsOnly() { return publicSchemsOnly; @@ -72,4 +91,40 @@ public class Event { public SchematicType getSchematicType() { return schemType; } + + public void setEventName(String eventName) { + this.eventName = eventName; + } + + public void setDeadline(Timestamp deadline) { + this.deadline = deadline; + } + + public void setStart(Timestamp start) { + this.start = start; + } + + public void setEnd(Timestamp end) { + this.end = end; + } + + public void setMaximumTeamMembers(int maximumTeamMembers) { + this.maximumTeamMembers = maximumTeamMembers; + } + + public void setPublicSchemsOnly(boolean publicSchemsOnly) { + this.publicSchemsOnly = publicSchemsOnly; + } + + public void setSpectateSystem(boolean spectateSystem) { + this.spectateSystem = spectateSystem; + } + + public void setSchemType(SchematicType schemType) { + this.schemType = schemType; + } + + public void update(){ + update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, spectateSystem, eventID); + } } diff --git a/src/de/steamwar/sql/EventFight.java b/src/de/steamwar/sql/EventFight.java index 60e4831..4dd8cb1 100644 --- a/src/de/steamwar/sql/EventFight.java +++ b/src/de/steamwar/sql/EventFight.java @@ -25,6 +25,10 @@ import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; + +import java.sql.Timestamp; +import java.util.List; @AllArgsConstructor public class EventFight { @@ -33,26 +37,52 @@ public class EventFight { private static final SelectStatement byId = table.select(Table.PRIMARY); private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis"); private static final Statement setFight = table.update(Table.PRIMARY, "Fight"); + private static final SelectStatement byEvent = table.selectFields("eventID"); + private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter"); + private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter"); public static EventFight get(int fightID) { return byId.select(fightID); } + public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed) { + return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, 0)); + } + + public static List getFromEvent(int eventID) { + return byEvent.listSelect(eventID); + } + @Getter @Field - private final int eventID; + private int eventID; @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) - private final int fightID; + private int fightID; @Getter + @Setter @Field - private final int teamBlue; + private Timestamp startTime; @Getter + @Setter @Field - private final int teamRed; + private String spielModus; @Getter + @Setter @Field - private final int kampfleiter; + private String map; + @Getter + @Setter + @Field + private int teamBlue; + @Getter + @Setter + @Field + private int teamRed; + @Getter + @Setter + @Field + private int kampfleiter; @Getter @Field(def = "0") private int ergebnis; @@ -69,4 +99,8 @@ public class EventFight { this.fight = fight; setFight.update(fight, fightID); } + + public void update() { + update.update(startTime, spielModus, map, teamBlue, teamRed, kampfleiter, fightID); + } } diff --git a/src/de/steamwar/sql/SteamwarUser.java b/src/de/steamwar/sql/SteamwarUser.java index 874643f..e36504e 100644 --- a/src/de/steamwar/sql/SteamwarUser.java +++ b/src/de/steamwar/sql/SteamwarUser.java @@ -44,6 +44,8 @@ public class SteamwarUser { private static final SelectStatement byDiscord = table.selectFields("DiscordId"); private static final SelectStatement byTeam = table.selectFields("Team"); private static final SelectStatement getServerTeam = new SelectStatement<>(table, "SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'"); + + private static final SelectStatement getAll = new SelectStatement<>(table, "SELECT * FROM UserData"); private static final Statement updateName = table.update(Table.PRIMARY, "UserName"); private static final Statement updateLocale = table.update(Table.PRIMARY, "Locale", "ManualLocale"); private static final Statement updateTeam = table.update(Table.PRIMARY, "Team"); @@ -157,6 +159,10 @@ public class SteamwarUser { return byDiscord.select(discordId); } + public static List getAll() { + return getAll.listSelect(); + } + public static void createOrUpdateUsername(UUID uuid, String userName) { insert.update(uuid, userName); } diff --git a/src/de/steamwar/sql/Team.java b/src/de/steamwar/sql/Team.java index 10e6892..a5af6d8 100644 --- a/src/de/steamwar/sql/Team.java +++ b/src/de/steamwar/sql/Team.java @@ -33,6 +33,7 @@ public class Team { private static final Table table = new Table<>(Team.class); private static final SelectStatement select = table.select(Table.PRIMARY); + private static final SelectStatement all = new SelectStatement(table, "SELECT * FROM Team"); @Field(keys = {Table.PRIMARY}) @Getter @@ -55,6 +56,10 @@ public class Team { return select.select(id); } + public static List getAll() { + return all.listSelect(); + } + public List getMembers(){ return SteamwarUser.getTeam(teamId).stream().map(SteamwarUser::getId).collect(Collectors.toList()); } From bf480f6e6fc212362da34620385d4dee84250698 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 23 Dec 2022 23:17:13 +0100 Subject: [PATCH 2/5] Revert "Initial Commit" This reverts commit 6d579b69818a2c4278e7f86544c20f6fda7d82ab. --- src/de/steamwar/sql/Event.java | 71 +++------------------------ src/de/steamwar/sql/EventFight.java | 44 ++--------------- src/de/steamwar/sql/SteamwarUser.java | 6 --- src/de/steamwar/sql/Team.java | 5 -- 4 files changed, 13 insertions(+), 113 deletions(-) diff --git a/src/de/steamwar/sql/Event.java b/src/de/steamwar/sql/Event.java index b51ee34..a4c30e6 100644 --- a/src/de/steamwar/sql/Event.java +++ b/src/de/steamwar/sql/Event.java @@ -21,65 +21,46 @@ package de.steamwar.sql; import de.steamwar.sql.internal.Field; import de.steamwar.sql.internal.SelectStatement; -import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; import java.sql.Timestamp; -import java.util.List; @AllArgsConstructor public class Event { private static final Table table = new Table<>(Event.class); private static final SelectStatement byId = table.select(Table.PRIMARY); - private static final SelectStatement allShort = new SelectStatement<>(table, "SELECT * FROM Event"); - private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly", "spectateSystem"); - private static final Statement update = table.update(Table.PRIMARY, "eventName", "deadline", "start", "end", "schemType", "maximumTeamMembers", "publicSchemsOnly", "spectateSystem"); - private static final Statement delete = table.delete(Table.PRIMARY); - public static Event get(int eventID){ return byId.select(eventID); } - public static List getAllShort(){ - return allShort.listSelect(); - } - - public static Event create(String eventName, Timestamp start, Timestamp end){ - return get(create.insertGetKey(eventName, start, start, end, 5, false, false)); - } - - public static void delete(int eventID){ - delete.update(eventID); - } - @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int eventID; @Getter @Field(keys = {"eventName"}) - private String eventName; + private final String eventName; @Getter @Field - private Timestamp deadline; + private final Timestamp deadline; @Getter @Field - private Timestamp start; + private final Timestamp start; @Getter @Field - private Timestamp end; + private final Timestamp end; @Getter @Field - private int maximumTeamMembers; + private final int maximumTeamMembers; @Field(nullable = true) - private SchematicType schemType; + private final SchematicType schemType; @Field - private boolean publicSchemsOnly; + private final boolean publicSchemsOnly; @Field - private boolean spectateSystem; + private final boolean spectateSystem; public boolean publicSchemsOnly() { return publicSchemsOnly; @@ -91,40 +72,4 @@ public class Event { public SchematicType getSchematicType() { return schemType; } - - public void setEventName(String eventName) { - this.eventName = eventName; - } - - public void setDeadline(Timestamp deadline) { - this.deadline = deadline; - } - - public void setStart(Timestamp start) { - this.start = start; - } - - public void setEnd(Timestamp end) { - this.end = end; - } - - public void setMaximumTeamMembers(int maximumTeamMembers) { - this.maximumTeamMembers = maximumTeamMembers; - } - - public void setPublicSchemsOnly(boolean publicSchemsOnly) { - this.publicSchemsOnly = publicSchemsOnly; - } - - public void setSpectateSystem(boolean spectateSystem) { - this.spectateSystem = spectateSystem; - } - - public void setSchemType(SchematicType schemType) { - this.schemType = schemType; - } - - public void update(){ - update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, spectateSystem, eventID); - } } diff --git a/src/de/steamwar/sql/EventFight.java b/src/de/steamwar/sql/EventFight.java index 4dd8cb1..60e4831 100644 --- a/src/de/steamwar/sql/EventFight.java +++ b/src/de/steamwar/sql/EventFight.java @@ -25,10 +25,6 @@ import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; - -import java.sql.Timestamp; -import java.util.List; @AllArgsConstructor public class EventFight { @@ -37,52 +33,26 @@ public class EventFight { private static final SelectStatement byId = table.select(Table.PRIMARY); private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis"); private static final Statement setFight = table.update(Table.PRIMARY, "Fight"); - private static final SelectStatement byEvent = table.selectFields("eventID"); - private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter"); - private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter"); public static EventFight get(int fightID) { return byId.select(fightID); } - public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed) { - return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, 0)); - } - - public static List getFromEvent(int eventID) { - return byEvent.listSelect(eventID); - } - @Getter @Field - private int eventID; + private final int eventID; @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) - private int fightID; + private final int fightID; @Getter - @Setter @Field - private Timestamp startTime; + private final int teamBlue; @Getter - @Setter @Field - private String spielModus; + private final int teamRed; @Getter - @Setter @Field - private String map; - @Getter - @Setter - @Field - private int teamBlue; - @Getter - @Setter - @Field - private int teamRed; - @Getter - @Setter - @Field - private int kampfleiter; + private final int kampfleiter; @Getter @Field(def = "0") private int ergebnis; @@ -99,8 +69,4 @@ public class EventFight { this.fight = fight; setFight.update(fight, fightID); } - - public void update() { - update.update(startTime, spielModus, map, teamBlue, teamRed, kampfleiter, fightID); - } } diff --git a/src/de/steamwar/sql/SteamwarUser.java b/src/de/steamwar/sql/SteamwarUser.java index e36504e..874643f 100644 --- a/src/de/steamwar/sql/SteamwarUser.java +++ b/src/de/steamwar/sql/SteamwarUser.java @@ -44,8 +44,6 @@ public class SteamwarUser { private static final SelectStatement byDiscord = table.selectFields("DiscordId"); private static final SelectStatement byTeam = table.selectFields("Team"); private static final SelectStatement getServerTeam = new SelectStatement<>(table, "SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'"); - - private static final SelectStatement getAll = new SelectStatement<>(table, "SELECT * FROM UserData"); private static final Statement updateName = table.update(Table.PRIMARY, "UserName"); private static final Statement updateLocale = table.update(Table.PRIMARY, "Locale", "ManualLocale"); private static final Statement updateTeam = table.update(Table.PRIMARY, "Team"); @@ -159,10 +157,6 @@ public class SteamwarUser { return byDiscord.select(discordId); } - public static List getAll() { - return getAll.listSelect(); - } - public static void createOrUpdateUsername(UUID uuid, String userName) { insert.update(uuid, userName); } diff --git a/src/de/steamwar/sql/Team.java b/src/de/steamwar/sql/Team.java index a5af6d8..10e6892 100644 --- a/src/de/steamwar/sql/Team.java +++ b/src/de/steamwar/sql/Team.java @@ -33,7 +33,6 @@ public class Team { private static final Table table = new Table<>(Team.class); private static final SelectStatement select = table.select(Table.PRIMARY); - private static final SelectStatement all = new SelectStatement(table, "SELECT * FROM Team"); @Field(keys = {Table.PRIMARY}) @Getter @@ -56,10 +55,6 @@ public class Team { return select.select(id); } - public static List getAll() { - return all.listSelect(); - } - public List getMembers(){ return SteamwarUser.getTeam(teamId).stream().map(SteamwarUser::getId).collect(Collectors.toList()); } From d62dd7614a352cc58fa4030b5d244349aa375a4a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Jan 2023 12:30:38 +0100 Subject: [PATCH 3/5] Adjust CI config to new CI --- steamwarci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/steamwarci.yml b/steamwarci.yml index 73f8039..47930f4 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,5 +1,6 @@ -build: +setup: - "ln -s /home/gitea/lib" - - "cp ~/gradle.properties ." - - "chmod u+x build.gradle" + +build: - "./gradlew buildProject" + - "./gradlew --stop" From bf1dde08c2294a8877c908f0b8cc74dc7886434f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Jan 2023 12:30:57 +0100 Subject: [PATCH 4/5] Fix build.gradle --- build.gradle | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build.gradle diff --git a/build.gradle b/build.gradle old mode 100644 new mode 100755 From dbd91bf41a95d138679112b18ebb3582be2606c8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Jan 2023 12:34:18 +0100 Subject: [PATCH 5/5] Fix closing connection on invalid connection --- src/de/steamwar/sql/internal/Statement.java | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/de/steamwar/sql/internal/Statement.java b/src/de/steamwar/sql/internal/Statement.java index 6c44332..ded799c 100644 --- a/src/de/steamwar/sql/internal/Statement.java +++ b/src/de/steamwar/sql/internal/Statement.java @@ -157,32 +157,36 @@ public class Statement implements AutoCloseable { private T withConnection(SQLRunnable runnable, Object... objects) { Connection connection = aquireConnection(); + T result; try { - try { - return tryWithConnection(connection, runnable, objects); - } finally { - if(connectionInvalid(connection)) { - closeConnection(connection); - } else { - synchronized (connections) { - connections.push(connection); - connections.notify(); - } - } - } - } catch (SQLException e) { + result = tryWithConnection(connection, runnable, objects); + } catch (Throwable e) { if(connectionInvalid(connection)) { + closeConnection(connection); + return withConnection(runnable, objects); } else { + synchronized (connections) { + connections.push(connection); + connections.notify(); + } + throw new SecurityException("Failing sql statement", e); } } + + synchronized (connections) { + connections.push(connection); + connections.notify(); + } + + return result; } private boolean connectionInvalid(Connection connection) { try { - return connection.isClosed(); + return connection.isClosed() || !connection.isValid(1); } catch (SQLException e) { logger.log(Level.INFO, "Could not check SQL connection status", e); // No database logging possible at this state return true;