Add TeamTeilnahme #118
@ -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<Team> getTeams(int eventID){
|
||||
try {
|
||||
ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", eventID);
|
||||
return byEvent.select(rs -> {
|
||||
Set<Team> 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<Event> getEvents(int teamID){
|
||||
try {
|
||||
ResultSet resultSet = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", teamID);
|
||||
return byTeam.select(rs -> {
|
||||
Set<Event> 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);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren