From 553f951cb5937f814666d1652e9e62e2da90ea0e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Oct 2021 18:03:19 +0200 Subject: [PATCH] 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); } }