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;
}
@OneToOne
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "info", referencedColumnName = "id")
public GameInfo getGameInfo() {
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);
}
@OneToOne(mappedBy = "gameInfo", cascade = CascadeType.ALL)
@OneToOne(mappedBy = "gameInfo", cascade = CascadeType.DETACH)
public Game getGame() {
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);
}
@OneToMany(mappedBy = "match", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "match", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public Collection<Game> getGames() {
return games;
}
@ -46,7 +46,7 @@ public class Match {
this.games = games;
}
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "player1", referencedColumnName = "id", nullable = false)
public Player getPlayer1() {
return player1;
@ -56,7 +56,7 @@ public class Match {
this.player1 = player1;
}
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "player2", referencedColumnName = "id", nullable = false)
public Player getPlayer2() {
return player2;
@ -66,7 +66,7 @@ public class Match {
this.player2 = player2;
}
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false)
public Matchday getMatchday() {
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);
}
@OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public Collection<Match> getMatches() {
return matches;
}
@ -55,7 +55,7 @@ public class Matchday {
this.matches = matches;
}
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.DETACH)
@JoinColumn(name = "season", referencedColumnName = "id", nullable = false)
public Season getSeason() {
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);
}
@OneToMany(mappedBy = "player1")
@OneToMany(mappedBy = "player1", cascade = CascadeType.DETACH)
public Collection<Match> getMatchesAsPlayer1() {
return matchesAsPlayer1;
}
@ -67,7 +67,7 @@ public class Player {
this.matchesAsPlayer1 = matchesAsPlayer1;
}
@OneToMany(mappedBy = "player2")
@OneToMany(mappedBy = "player2", cascade = CascadeType.DETACH)
public Collection<Match> getMatchesAsPlayer2() {
return matchesAsPlayer2;
}
@ -76,7 +76,7 @@ public class Player {
this.matchesAsPlayer2 = matchesAsPlayer2;
}
@OneToOne
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "info", referencedColumnName = "id")
public PlayerInfo getPlayerInfo() {
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);
}
@OneToOne(mappedBy = "playerInfo")
@OneToOne(mappedBy = "playerInfo", cascade = CascadeType.DETACH)
public Player getPlayer() {
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);
}
@OneToMany(mappedBy = "season")
@OneToMany(mappedBy = "season", cascade = CascadeType.ALL)
public Collection<Matchday> getMatchdays() {
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)
public class MainView extends AppLayout {
// TODO: Add Localization
// TODO: View for each match
// TODO: View for adding match data
// TODO: Handle database connection with environment variables
// 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() {
matchComponent = new MatchComponent(navigation, chessComService, gameService, gameInfoService, gameImageService);
matchComponent = new MatchComponent(navigation, chessComService, navigation.getMatchService(), gameService, gameInfoService, gameImageService);
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.GameInfoService;
import app.data.service.GameService;
import app.data.service.MatchService;
import app.gameimage.GameImageService;
import app.navigation.Navigation;
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.HorizontalLayout;
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.shared.Registration;
import org.springframework.beans.factory.annotation.Autowired;
@ -36,6 +38,7 @@ public class MatchComponent extends Div implements ContentConfigurable {
private final Navigation navigation;
private final ChessComService chessComService;
private final MatchService matchService;
private final GameService gameService;
private final GameInfoService gameInfoService;
private final GameImageService gameImageService;
@ -53,6 +56,7 @@ public class MatchComponent extends Div implements ContentConfigurable {
// TODO: autocorrect "/live/game" to "/game/live/"
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: use overlapping progress here
private Registration editSubmitButtonRegistration;
private final Button editCancelButton = new Button("Cancel", new Icon(VaadinIcon.CLOSE));
private Registration editCancelButtonRegistration;
@ -62,11 +66,13 @@ public class MatchComponent extends Div implements ContentConfigurable {
public MatchComponent(Navigation navigation,
@Autowired ChessComService chessComService,
@Autowired MatchService matchService, // TODO: get this stuff from navigation instead, or even better: Do it like PaussHFramework
@Autowired GameService gameService,
@Autowired GameInfoService gameInfoService,
@Autowired GameImageService gameImageService) {
this.navigation = navigation;
this.chessComService = chessComService;
this.matchService = matchService;
this.gameService = gameService;
this.gameInfoService = gameInfoService;
this.gameImageService = gameImageService;
@ -172,10 +178,14 @@ public class MatchComponent extends Div implements ContentConfigurable {
if (chessComButtonButtonRegistration != null) chessComButtonButtonRegistration.remove();
chessComButtonButtonRegistration = chessComButton.addClickListener(event -> {
ProgressBar progressBar = new ProgressBar();
progressBar.setIndeterminate(true);
editLayout.add(progressBar);
List<Game> gamesBetweenPlayers = chessComService.getLatestGamesBetweenPlayers(match, 6, 2);
for (int i = 0; i < Math.min(gamesBetweenPlayers.size(), 6); i++) {
editTextFields.get(i).setValue(ChessComUtils.getGameURL(gamesBetweenPlayers.get(i)));
}
editLayout.remove(progressBar);
});
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!
game.ifPresent(value -> match.getGames().add(value));
}
match.getGames().forEach(game -> gameInfoService.update(game.getGameInfo()));
matchService.update(match);
match.getGames().forEach(gameImageService::createImageIfNotPresent);
navigation.setEditFlag(false);


Loading…
Cancel
Save