Package net.bjmsw.hda.vs.model.db
Class Spiel
java.lang.Object
net.bjmsw.hda.vs.model.db.Spiel
The Spiel class represents a game between two teams in the database.
Works like a simple mini ORM.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSpiel(long id, String team1name, String team2name, int winningTeam, double team0chance, double team1chance, double team2chance) Represents a Spiel (game) with unique ID, two team names, winning team, and chances for each team.Spiel(String team1name, String team2name, double team0chance, double team1chance, double team2chance) Represents a Spiel (game) with two team names and chances for each team. -
Method Summary
Modifier and TypeMethodDescriptionvoidendGame(int winningTeam) Updates the winning team of the game and saves it to the database.static SpielfromDB(long id) Retrieves a Spiel (game) object from the database based on its unique ID.getAll()Retrieves all Spiel (game) objects from the database.longgetId()Gets the unique ID of the Spiel (game).doubleGets the chance of a draw.doubleGets the chance of team 1 winning.Gets the name of team 1.doubleGets the chance of team 2 winning.Gets the name of team 2.intGets the winning team of the game.booleaninsert()Inserts the Spiel (game) object into the database.booleanisEnded()Checks if the game has ended.booleanisInDb()Checks if the Spiel (game) object is already in the database.
-
Field Details
-
id
private long id -
team1name
-
team2name
-
winningTeam
private int winningTeam -
team0chance
private double team0chance -
team1chance
private double team1chance -
team2chance
private double team2chance
-
-
Constructor Details
-
Spiel
private Spiel(long id, String team1name, String team2name, int winningTeam, double team0chance, double team1chance, double team2chance) Represents a Spiel (game) with unique ID, two team names, winning team, and chances for each team.This is a private constructor that initializes the Spiel object with the given parameters from the database.
- Parameters:
id- The unique ID of the Spiel.team1name- The name of team 1.team2name- The name of team 2.winningTeam- The winning team (team 1, team 2, or draw).team0chance- The chance of a draw.team1chance- The chance of team 1 winning.team2chance- The chance of team 2 winning.
-
Spiel
public Spiel(String team1name, String team2name, double team0chance, double team1chance, double team2chance) Represents a Spiel (game) with two team names and chances for each team.This is the public constructor that initializes the Spiel object with the given parameters. It will not be automatically inserted into the database. To insert the Spiel object into the database, call the insert() method.
- Parameters:
team1name- The name of team 1.team2name- The name of team 2.team0chance- The chance of a draw.team1chance- The chance of team 1 winning.team2chance- The chance of team 2 winning.
-
-
Method Details
-
fromDB
Retrieves a Spiel (game) object from the database based on its unique ID.- Parameters:
id- The unique ID of the Spiel to retrieve from the database.- Returns:
- The Spiel object with the given ID if found, otherwise null.
-
getAll
Retrieves all Spiel (game) objects from the database.- Returns:
- A map of Spiel objects, where the key is the unique ID of each Spiel and the value is the corresponding Spiel object. Returns null if there was an error fetching Spiele from the database.
-
insert
public boolean insert()Inserts the Spiel (game) object into the database.- Returns:
- true if the Spiel was successfully inserted into the database, false otherwise.
-
endGame
Updates the winning team of the game and saves it to the database.- Parameters:
winningTeam- The winning team of the game (0 for draw, 1 for team 1, 2 for team 2).- Throws:
SQLException- If there is an error executing the database query.IllegalArgumentException- If the winningTeam parameter is not 0, 1, or 2.
-
getTeam1name
Gets the name of team 1.- Returns:
- The name of team 1.
-
getTeam2name
Gets the name of team 2.- Returns:
- The name of team 2.
-
isInDb
public boolean isInDb()Checks if the Spiel (game) object is already in the database.- Returns:
- true if the Spiel is in the database, false otherwise.
-
getId
public long getId()Gets the unique ID of the Spiel (game).- Returns:
- The unique ID of the Spiel.
-
getWinningTeam
public int getWinningTeam()Gets the winning team of the game.- Returns:
- The winning team of the game (0 for draw, 1 for team 1, 2 for team 2).
-
isEnded
public boolean isEnded()Checks if the game has ended.- Returns:
- true if the game has ended, false otherwise.
-
getTeam0chance
public double getTeam0chance()Gets the chance of a draw.- Returns:
- The chance of a draw.
-
getTeam1chance
public double getTeam1chance()Gets the chance of team 1 winning.- Returns:
- The chance of team 1 winning.
-
getTeam2chance
public double getTeam2chance()Gets the chance of team 2 winning.- Returns:
- The chance of team 2 winning.
-