package app.data.entity;
|
|
|
|
import javax.persistence.*;
|
|
import java.util.Collection;
|
|
import java.util.Objects;
|
|
|
|
@Entity
|
|
@Table(name = "match", schema = "public", catalog = "chessleague")
|
|
public class Match {
|
|
private Integer id;
|
|
private Collection<Game> games;
|
|
private Player player1;
|
|
private Player player2;
|
|
private Matchday matchday;
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
@Column(name = "id", nullable = false)
|
|
public Integer getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Integer id) {
|
|
this.id = id;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
Match that = (Match) o;
|
|
return Objects.equals(id, that.id);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(id);
|
|
}
|
|
|
|
@OneToMany(mappedBy = "match", fetch = FetchType.EAGER)
|
|
public Collection<Game> getGames() {
|
|
return games;
|
|
}
|
|
|
|
public void setGames(Collection<Game> games) {
|
|
this.games = games;
|
|
}
|
|
|
|
@ManyToOne(cascade=CascadeType.ALL)
|
|
@JoinColumn(name = "player1", referencedColumnName = "id", nullable = false)
|
|
public Player getPlayer1() {
|
|
return player1;
|
|
}
|
|
|
|
public void setPlayer1(Player player1) {
|
|
this.player1 = player1;
|
|
}
|
|
|
|
@ManyToOne(cascade=CascadeType.ALL)
|
|
@JoinColumn(name = "player2", referencedColumnName = "id", nullable = false)
|
|
public Player getPlayer2() {
|
|
return player2;
|
|
}
|
|
|
|
public void setPlayer2(Player player2) {
|
|
this.player2 = player2;
|
|
}
|
|
|
|
@ManyToOne(cascade=CascadeType.ALL)
|
|
@JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false)
|
|
public Matchday getMatchday() {
|
|
return matchday;
|
|
}
|
|
|
|
public void setMatchday(Matchday matchday) {
|
|
this.matchday = matchday;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return String.format("%s-vs-%s", player1.getNickname().toLowerCase(), player2.getNickname().toLowerCase());
|
|
}
|
|
}
|