-
Notifications
You must be signed in to change notification settings - Fork 14
Fix/xiao long #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/xiao long #73
Changes from all commits
4890aae
dc6f0a0
8be15c3
08b8d3e
1a14d3e
ca7c8d2
71038e6
19e49b2
678083a
15c352b
e8bc4ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,88 +9,97 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.OneToMany; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.Table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.validation.constraints.Size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import lombok.EqualsAndHashCode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import lombok.NoArgsConstructor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import lombok.Setter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Entity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Table(name = "competition_tables") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Setter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @NoArgsConstructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class CompetitionTable extends UriEntity<String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @EqualsAndHashCode.Include | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private String id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OneToMany(mappedBy = "competitionTable", cascade = CascadeType.ALL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OneToMany(mappedBy = "competitionTable", cascade = {CascadeType.PERSIST, CascadeType.MERGE}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @JsonManagedReference("table-matches") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Setter(lombok.AccessLevel.NONE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<Match> matches = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OneToMany(mappedBy = "supervisesTable") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Size(max = 3, message = "A table can have a maximum of 3 referees") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @JsonManagedReference("table-referees") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Setter(lombok.AccessLevel.NONE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<Referee> referees = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String getId() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void setId(String id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.id = id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public List<Match> getMatches() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void setMatches(List<Match> matches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new ArrayList<>(this.matches).forEach(this::removeMatch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (matches != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches.forEach(this::addMatch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public List<Referee> getReferees() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return referees; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void setReferees(List<Referee> referees) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new ArrayList<>(this.referees).forEach(this::removeReferee); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (referees != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| referees.forEach(this::addReferee); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void addMatch(Match match) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (match == null || matches.contains(match)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void addMatch(Match match) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CompetitionTable previousTable = match.getCompetitionTable(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (previousTable != null && previousTable != this) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| previousTable.removeMatch(match); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!matches.contains(match)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches.add(match); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches.add(match); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match.setCompetitionTable(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void removeMatch(Match match) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches.remove(match); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match.setCompetitionTable(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (match == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (matches.remove(match)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match.setCompetitionTable(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void addReferee(Referee referee) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CompetitionTable previousTable = referee.getSupervisesTable(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (previousTable != null && previousTable != this) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| previousTable.removeReferee(referee); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void setReferees(List<Referee> referees) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new ArrayList<>(this.referees).forEach(this::removeReferee); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (referees != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| referees.forEach(this::addReferee); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (referees.contains(referee)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void addReferee(Referee referee) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (referee == null || referees.contains(referee)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+79
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void addReferee(Referee referee) { | |
| if (referee == null || referees.contains(referee)) { | |
| private boolean isRefereeAlreadyAssigned(Referee referee) { | |
| if (referee == null) { | |
| return false; | |
| } | |
| Object refereeId = referee.getId(); | |
| if (refereeId == null) { | |
| for (Referee existingReferee : referees) { | |
| if (existingReferee == referee) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| for (Referee existingReferee : referees) { | |
| if (refereeId.equals(existingReferee.getId())) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public void addReferee(Referee referee) { | |
| if (referee == null || isRefereeAlreadyAssigned(referee)) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,69 +10,34 @@ | |
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "matches") | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) | ||
| public class Match extends UriEntity<Long> { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @EqualsAndHashCode.Include | ||
| private Long id; | ||
|
Comment on lines
+20
to
29
|
||
|
|
||
| private LocalTime startTime; | ||
|
|
||
| private LocalTime endTime; | ||
|
|
||
| @JsonBackReference("round-matches") | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "round_id") | ||
| @JsonBackReference("round-matches") | ||
| private Round round; | ||
|
|
||
| @JsonBackReference("table-matches") | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "table_id") | ||
| @JsonBackReference("table-matches") | ||
| private CompetitionTable competitionTable; | ||
|
|
||
| public Match() {} | ||
|
|
||
| @Override | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public LocalTime getStartTime() { | ||
| return startTime; | ||
| } | ||
|
|
||
| public void setStartTime(LocalTime startTime) { | ||
| this.startTime = startTime; | ||
| } | ||
|
|
||
| public LocalTime getEndTime() { | ||
| return endTime; | ||
| } | ||
|
|
||
| public void setEndTime(LocalTime endTime) { | ||
| this.endTime = endTime; | ||
| } | ||
|
|
||
| public Round getRound() { | ||
| return round; | ||
| } | ||
|
|
||
| public void setRound(Round round) { | ||
| this.round = round; | ||
| } | ||
|
|
||
| public CompetitionTable getCompetitionTable() { | ||
| return competitionTable; | ||
| } | ||
|
|
||
| public void setCompetitionTable(CompetitionTable competitionTable) { | ||
| this.competitionTable = competitionTable; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,45 +11,32 @@ | |
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.Table; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "rounds") | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) | ||
| public class Round extends UriEntity<Long> { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @EqualsAndHashCode.Include | ||
| private Long id; | ||
|
|
||
| @Column(unique = true) | ||
| private int number; | ||
|
|
||
| @OneToMany(mappedBy = "round", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| @JsonManagedReference("round-matches") | ||
| @Setter(lombok.AccessLevel.NONE) | ||
| private List<Match> matches = new ArrayList<>(); | ||
|
|
||
| public Round() {} | ||
|
|
||
| @Override | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public void setNumber(int number) { | ||
| this.number = number; | ||
| } | ||
|
|
||
| public List<Match> getMatches() { | ||
| return matches; | ||
| } | ||
|
|
||
| public void setMatches(List<Match> matches) { | ||
| this.matches.clear(); | ||
| if (matches != null) { | ||
|
|
@@ -58,12 +45,30 @@ public void setMatches(List<Match> matches) { | |
| } | ||
|
Comment on lines
40
to
45
|
||
|
|
||
| public void addMatch(Match match) { | ||
| if (match == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (matches.contains(match)) { | ||
| return; | ||
| } | ||
|
Comment on lines
47
to
+54
|
||
|
|
||
| Round previousRound = match.getRound(); | ||
| if (previousRound != null && previousRound != this) { | ||
| previousRound.removeMatch(match); | ||
| } | ||
|
|
||
| matches.add(match); | ||
| match.setRound(this); | ||
| } | ||
|
|
||
| public void removeMatch(Match match) { | ||
| matches.remove(match); | ||
| match.setRound(null); | ||
| if (match == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (matches.remove(match)) { | ||
| match.setRound(null); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addMatchrelies onmatches.contains(match)for de-duplication, butMatch.equals/hashCodeis based solely on a generatedid. This makes all transient matches (id == null) appear equal, so adding multiple new matches to a table can be silently skipped andremoveMatchmay remove an unintended instance. Use an identity-based duplicate check for transient entities or adjustMatch.equals/hashCodeto avoidnull-id equality.