From 3109d019df243d856902751f74047cd137bf6cdc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Oct 2021 18:00:45 +0200 Subject: [PATCH 1/3] Add TeamTeilnahme --- .../src/de/steamwar/sql/TeamTeilnahme.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java new file mode 100644 index 0000000..28fe999 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java @@ -0,0 +1,63 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; + +public class TeamTeilnahme { + private TeamTeilnahme(){} + + public static boolean nimmtTeil(int teamID, int eventID){ + try { + return SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?", teamID, eventID).next(); + } catch (SQLException e) { + throw new SecurityException("Could not perform select", e); + } + } + + public static Set getTeams(int eventID){ + try { + ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", eventID); + Set teams = new HashSet<>(); + while (resultSet.next()) { + teams.add(Team.get(resultSet.getInt("TeamID"))); + } + return teams; + } catch (SQLException e) { + throw new SecurityException("Could not perform select", e); + } + } + + public static Set getEvents(int teamID){ + try { + ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", teamID); + Set events = new HashSet<>(); + while (resultSet.next()) { + events.add(Event.get(resultSet.getInt("EventID"))); + } + return events; + } catch (SQLException e) { + throw new SecurityException("Could not perform select", e); + } + } +} From 553f951cb5937f814666d1652e9e62e2da90ea0e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Oct 2021 18:03:19 +0200 Subject: [PATCH 2/3] Add TeamTeilnahme --- .../src/de/steamwar/sql/TeamTeilnahme.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java index 28fe999..ff31f94 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java +++ b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java @@ -20,44 +20,35 @@ package de.steamwar.sql; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.HashSet; import java.util.Set; public class TeamTeilnahme { private TeamTeilnahme(){} + private static final SQL.Statement byEventTeam = new SQL.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?"); + private static final SQL.Statement byEvent = new SQL.Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?"); + private static final SQL.Statement byTeam = new SQL.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?"); + public static boolean nimmtTeil(int teamID, int eventID){ - try { - return SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?", teamID, eventID).next(); - } catch (SQLException e) { - throw new SecurityException("Could not perform select", e); - } + return byEvent.select(ResultSet::next, teamID, eventID); } public static Set getTeams(int eventID){ - try { - ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", eventID); + return byEvent.select(rs -> { Set teams = new HashSet<>(); - while (resultSet.next()) { - teams.add(Team.get(resultSet.getInt("TeamID"))); - } + while(rs.next()) + teams.add(Team.get(rs.getInt("TeamID"))); return teams; - } catch (SQLException e) { - throw new SecurityException("Could not perform select", e); - } + }, eventID); } public static Set getEvents(int teamID){ - try { - ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", teamID); + return byTeam.select(rs -> { Set events = new HashSet<>(); - while (resultSet.next()) { - events.add(Event.get(resultSet.getInt("EventID"))); - } + while(rs.next()) + events.add(Event.get(rs.getInt("EventID"))); return events; - } catch (SQLException e) { - throw new SecurityException("Could not perform select", e); - } + }, teamID); } } From a2057ea4586522bfbc8b02d83040c6a8225f6d69 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Oct 2021 18:03:34 +0200 Subject: [PATCH 3/3] Add TeamTeilnahme --- SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java index ff31f94..cd350d0 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java +++ b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java @@ -31,7 +31,7 @@ public class TeamTeilnahme { private static final SQL.Statement byTeam = new SQL.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?"); public static boolean nimmtTeil(int teamID, int eventID){ - return byEvent.select(ResultSet::next, teamID, eventID); + return byEventTeam.select(ResultSet::next, teamID, eventID); } public static Set getTeams(int eventID){