Browse Source

proper cascading

master
GAM 4 years ago
parent
commit
32bf2838c2
10 changed files with 25 additions and 17 deletions
  1. +1
    -1
      src/main/java/app/data/entity/Game.java
  2. +1
    -1
      src/main/java/app/data/entity/GameInfo.java
  3. +4
    -4
      src/main/java/app/data/entity/Match.java
  4. +2
    -2
      src/main/java/app/data/entity/Matchday.java
  5. +3
    -3
      src/main/java/app/data/entity/Player.java
  6. +1
    -1
      src/main/java/app/data/entity/PlayerInfo.java
  7. +1
    -1
      src/main/java/app/data/entity/Season.java
  8. +0
    -2
      src/main/java/app/views/main/MainView.java
  9. +1
    -1
      src/main/java/app/views/match/MatchView.java
  10. +11
    -1
      src/main/java/app/views/match/components/MatchComponent.java

+ 1
- 1
src/main/java/app/data/entity/Game.java View File

@ -66,7 +66,7 @@ public class Game {
this.match = match; this.match = match;
} }
@OneToOne
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "info", referencedColumnName = "id") @JoinColumn(name = "info", referencedColumnName = "id")
public GameInfo getGameInfo() { public GameInfo getGameInfo() {
return gameInfo; return gameInfo;


+ 1
- 1
src/main/java/app/data/entity/GameInfo.java View File

@ -67,7 +67,7 @@ public class GameInfo {
return Objects.hash(id, chessComId, timeControl); return Objects.hash(id, chessComId, timeControl);
} }
@OneToOne(mappedBy = "gameInfo", cascade = CascadeType.ALL)
@OneToOne(mappedBy = "gameInfo", cascade = CascadeType.DETACH)
public Game getGame() { public Game getGame() {
return game; return game;
} }


+ 4
- 4
src/main/java/app/data/entity/Match.java View File

@ -37,7 +37,7 @@ public class Match {
return Objects.hash(id); return Objects.hash(id);
} }
@OneToMany(mappedBy = "match", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "match", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public Collection<Game> getGames() { public Collection<Game> getGames() {
return games; return games;
} }
@ -46,7 +46,7 @@ public class Match {
this.games = games; this.games = games;
} }
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "player1", referencedColumnName = "id", nullable = false) @JoinColumn(name = "player1", referencedColumnName = "id", nullable = false)
public Player getPlayer1() { public Player getPlayer1() {
return player1; return player1;
@ -56,7 +56,7 @@ public class Match {
this.player1 = player1; this.player1 = player1;
} }
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "player2", referencedColumnName = "id", nullable = false) @JoinColumn(name = "player2", referencedColumnName = "id", nullable = false)
public Player getPlayer2() { public Player getPlayer2() {
return player2; return player2;
@ -66,7 +66,7 @@ public class Match {
this.player2 = player2; this.player2 = player2;
} }
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false) @JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false)
public Matchday getMatchday() { public Matchday getMatchday() {
return matchday; return matchday;


+ 2
- 2
src/main/java/app/data/entity/Matchday.java View File

@ -46,7 +46,7 @@ public class Matchday {
return Objects.hash(id, number); return Objects.hash(id, number);
} }
@OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public Collection<Match> getMatches() { public Collection<Match> getMatches() {
return matches; return matches;
} }
@ -55,7 +55,7 @@ public class Matchday {
this.matches = matches; this.matches = matches;
} }
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "season", referencedColumnName = "id", nullable = false) @JoinColumn(name = "season", referencedColumnName = "id", nullable = false)
public Season getSeason() { public Season getSeason() {
return season; return season;


+ 3
- 3
src/main/java/app/data/entity/Player.java View File

@ -58,7 +58,7 @@ public class Player {
return Objects.hash(id, name, nickname); return Objects.hash(id, name, nickname);
} }
@OneToMany(mappedBy = "player1")
@OneToMany(mappedBy = "player1", cascade = CascadeType.DETACH)
public Collection<Match> getMatchesAsPlayer1() { public Collection<Match> getMatchesAsPlayer1() {
return matchesAsPlayer1; return matchesAsPlayer1;
} }
@ -67,7 +67,7 @@ public class Player {
this.matchesAsPlayer1 = matchesAsPlayer1; this.matchesAsPlayer1 = matchesAsPlayer1;
} }
@OneToMany(mappedBy = "player2")
@OneToMany(mappedBy = "player2", cascade = CascadeType.DETACH)
public Collection<Match> getMatchesAsPlayer2() { public Collection<Match> getMatchesAsPlayer2() {
return matchesAsPlayer2; return matchesAsPlayer2;
} }
@ -76,7 +76,7 @@ public class Player {
this.matchesAsPlayer2 = matchesAsPlayer2; this.matchesAsPlayer2 = matchesAsPlayer2;
} }
@OneToOne
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "info", referencedColumnName = "id") @JoinColumn(name = "info", referencedColumnName = "id")
public PlayerInfo getPlayerInfo() { public PlayerInfo getPlayerInfo() {
return playerInfo; return playerInfo;


+ 1
- 1
src/main/java/app/data/entity/PlayerInfo.java View File

@ -44,7 +44,7 @@ public class PlayerInfo {
return Objects.hash(id, url); return Objects.hash(id, url);
} }
@OneToOne(mappedBy = "playerInfo")
@OneToOne(mappedBy = "playerInfo", cascade = CascadeType.DETACH)
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }


+ 1
- 1
src/main/java/app/data/entity/Season.java View File

@ -56,7 +56,7 @@ public class Season {
return Objects.hash(id, yearStart, yearEnd); return Objects.hash(id, yearStart, yearEnd);
} }
@OneToMany(mappedBy = "season")
@OneToMany(mappedBy = "season", cascade = CascadeType.ALL)
public Collection<Matchday> getMatchdays() { public Collection<Matchday> getMatchdays() {
return matchdays; return matchdays;
} }


+ 0
- 2
src/main/java/app/views/main/MainView.java View File

@ -37,8 +37,6 @@ import java.util.Optional;
@Theme(value = Lumo.class, variant = Lumo.DARK) @Theme(value = Lumo.class, variant = Lumo.DARK)
public class MainView extends AppLayout { public class MainView extends AppLayout {
// TODO: Add Localization // TODO: Add Localization
// TODO: View for each match
// TODO: View for adding match data
// TODO: Handle database connection with environment variables // TODO: Handle database connection with environment variables
// TODO: add light theme // TODO: add light theme


+ 1
- 1
src/main/java/app/views/match/MatchView.java View File

@ -43,7 +43,7 @@ public class MatchView extends NavigationViewBase {
//////////// ////////////
private void configureLayout() { private void configureLayout() {
matchComponent = new MatchComponent(navigation, chessComService, gameService, gameInfoService, gameImageService);
matchComponent = new MatchComponent(navigation, chessComService, navigation.getMatchService(), gameService, gameInfoService, gameImageService);
add(matchComponent); add(matchComponent);
} }


+ 11
- 1
src/main/java/app/views/match/components/MatchComponent.java View File

@ -6,6 +6,7 @@ import app.data.entity.Match;
import app.data.service.ChessComService; import app.data.service.ChessComService;
import app.data.service.GameInfoService; import app.data.service.GameInfoService;
import app.data.service.GameService; import app.data.service.GameService;
import app.data.service.MatchService;
import app.gameimage.GameImageService; import app.gameimage.GameImageService;
import app.navigation.Navigation; import app.navigation.Navigation;
import app.utils.ChessComUtils; import app.utils.ChessComUtils;
@ -23,6 +24,7 @@ import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.component.orderedlayout.FlexLayout;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.progressbar.ProgressBar;
import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.shared.Registration; import com.vaadin.flow.shared.Registration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -36,6 +38,7 @@ public class MatchComponent extends Div implements ContentConfigurable {
private final Navigation navigation; private final Navigation navigation;
private final ChessComService chessComService; private final ChessComService chessComService;
private final MatchService matchService;
private final GameService gameService; private final GameService gameService;
private final GameInfoService gameInfoService; private final GameInfoService gameInfoService;
private final GameImageService gameImageService; private final GameImageService gameImageService;
@ -53,6 +56,7 @@ public class MatchComponent extends Div implements ContentConfigurable {
// TODO: autocorrect "/live/game" to "/game/live/" // TODO: autocorrect "/live/game" to "/game/live/"
private final Button editSubmitButton = new Button("Submit", new Icon(VaadinIcon.CHECK)); private final Button editSubmitButton = new Button("Submit", new Icon(VaadinIcon.CHECK));
// TODO: disable when no 6 values in form, and make sure you don't freeze forever when there are wrong entries // TODO: disable when no 6 values in form, and make sure you don't freeze forever when there are wrong entries
// TODO: use overlapping progress here
private Registration editSubmitButtonRegistration; private Registration editSubmitButtonRegistration;
private final Button editCancelButton = new Button("Cancel", new Icon(VaadinIcon.CLOSE)); private final Button editCancelButton = new Button("Cancel", new Icon(VaadinIcon.CLOSE));
private Registration editCancelButtonRegistration; private Registration editCancelButtonRegistration;
@ -62,11 +66,13 @@ public class MatchComponent extends Div implements ContentConfigurable {
public MatchComponent(Navigation navigation, public MatchComponent(Navigation navigation,
@Autowired ChessComService chessComService, @Autowired ChessComService chessComService,
@Autowired MatchService matchService, // TODO: get this stuff from navigation instead, or even better: Do it like PaussHFramework
@Autowired GameService gameService, @Autowired GameService gameService,
@Autowired GameInfoService gameInfoService, @Autowired GameInfoService gameInfoService,
@Autowired GameImageService gameImageService) { @Autowired GameImageService gameImageService) {
this.navigation = navigation; this.navigation = navigation;
this.chessComService = chessComService; this.chessComService = chessComService;
this.matchService = matchService;
this.gameService = gameService; this.gameService = gameService;
this.gameInfoService = gameInfoService; this.gameInfoService = gameInfoService;
this.gameImageService = gameImageService; this.gameImageService = gameImageService;
@ -172,10 +178,14 @@ public class MatchComponent extends Div implements ContentConfigurable {
if (chessComButtonButtonRegistration != null) chessComButtonButtonRegistration.remove(); if (chessComButtonButtonRegistration != null) chessComButtonButtonRegistration.remove();
chessComButtonButtonRegistration = chessComButton.addClickListener(event -> { chessComButtonButtonRegistration = chessComButton.addClickListener(event -> {
ProgressBar progressBar = new ProgressBar();
progressBar.setIndeterminate(true);
editLayout.add(progressBar);
List<Game> gamesBetweenPlayers = chessComService.getLatestGamesBetweenPlayers(match, 6, 2); List<Game> gamesBetweenPlayers = chessComService.getLatestGamesBetweenPlayers(match, 6, 2);
for (int i = 0; i < Math.min(gamesBetweenPlayers.size(), 6); i++) { for (int i = 0; i < Math.min(gamesBetweenPlayers.size(), 6); i++) {
editTextFields.get(i).setValue(ChessComUtils.getGameURL(gamesBetweenPlayers.get(i))); editTextFields.get(i).setValue(ChessComUtils.getGameURL(gamesBetweenPlayers.get(i)));
} }
editLayout.remove(progressBar);
}); });
if (editSubmitButtonRegistration != null) editSubmitButtonRegistration.remove(); if (editSubmitButtonRegistration != null) editSubmitButtonRegistration.remove();
@ -185,7 +195,7 @@ public class MatchComponent extends Div implements ContentConfigurable {
Optional<Game> game = chessComService.getGame(textField.getValue(), match); // TODO: handle this when Optional is empty! Optional<Game> game = chessComService.getGame(textField.getValue(), match); // TODO: handle this when Optional is empty!
game.ifPresent(value -> match.getGames().add(value)); game.ifPresent(value -> match.getGames().add(value));
} }
match.getGames().forEach(game -> gameInfoService.update(game.getGameInfo()));
matchService.update(match);
match.getGames().forEach(gameImageService::createImageIfNotPresent); match.getGames().forEach(gameImageService::createImageIfNotPresent);
navigation.setEditFlag(false); navigation.setEditFlag(false);


Loading…
Cancel
Save