mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-07-09 13:27:45 +00:00
fix: devWeb - Display game when game end
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
package uppa.project.bean;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import uppa.project.database.dao.DAO;
|
||||||
|
import uppa.project.database.dao.DAOException;
|
||||||
|
import uppa.project.database.dao.EntityManagerProvider;
|
||||||
|
import uppa.project.database.dao.jpa.Game_JPA_DAO_Factory;
|
||||||
|
import uppa.project.database.pojo.Player;
|
||||||
|
|
||||||
|
public class PlayerBean {
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
public PlayerBean(Player player){
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validate(){
|
||||||
|
EntityManager em = EntityManagerProvider.getInstance();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
DAO<Player> playerDAO = new Game_JPA_DAO_Factory().getDAOPlayer();
|
||||||
|
Player dbPlayer = new Player(player.getGame(),player.getUser());
|
||||||
|
dbPlayer.setScore(player.getScore());
|
||||||
|
if (player.isWinner()) dbPlayer.setWinner();
|
||||||
|
dbPlayer.setClickCount(player.getClickCount());
|
||||||
|
dbPlayer.setRapidClickCount(player.getRapidClickCount());
|
||||||
|
dbPlayer.setRightClickCount(player.getRightClickCount());
|
||||||
|
player.getGame().addPlayer(dbPlayer);
|
||||||
|
player.getUser().addPlayedGame(dbPlayer);
|
||||||
|
playerDAO.create(dbPlayer);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
return true;
|
||||||
|
} catch (DAOException e) {
|
||||||
|
System.out.println("Player :" + this.player.getUser().getUsername() +"n'a pas pu être enregistré en base de données");
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,7 +151,7 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, createdAt, players);
|
return Objects.hash(id, createdAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import jakarta.websocket.server.ServerEndpoint;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import uppa.project.bean.PlayerBean;
|
||||||
import uppa.project.database.dao.DAO;
|
import uppa.project.database.dao.DAO;
|
||||||
import uppa.project.database.dao.DAOException;
|
import uppa.project.database.dao.DAOException;
|
||||||
import uppa.project.database.dao.EntityManagerProvider;
|
import uppa.project.database.dao.EntityManagerProvider;
|
||||||
@@ -227,10 +228,12 @@ public class GameWS {
|
|||||||
theoricWinner.setWinner();
|
theoricWinner.setWinner();
|
||||||
|
|
||||||
EntityManager em = EntityManagerProvider.getFactory().createEntityManager();
|
EntityManager em = EntityManagerProvider.getFactory().createEntityManager();
|
||||||
DAO<Player> playerDAO = new Game_JPA_DAO_Factory().getDAOPlayer();
|
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
for (Player p : games.get(game)) playerDAO.create(p);
|
for (Player p : games.get(game)) {
|
||||||
|
PlayerBean playerBean = new PlayerBean(p);
|
||||||
|
if (playerBean.validate()) System.out.println("Player "+p.getUser().getUsername()+" sauvegardé en base de données");
|
||||||
|
else System.out.println("");
|
||||||
|
};
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user