Implementation de la bdd
This commit is contained in:
부모
2d4b549824
커밋
7f1fb4a929
4개의 변경된 파일과 21개의 추가작업 그리고 8개의 파일을 삭제
|
@ -1,11 +1,11 @@
|
||||||
chatapp/Model/MessageHorodate.java
|
|
||||||
chatapp.Model.MessageHorodate
|
|
||||||
chatapp/Model/Utilisateur.java
|
|
||||||
chatapp.Model.Utilisateur
|
|
||||||
chatapp/Model/ListUtilisateurs.java
|
|
||||||
chatapp.Model.ListUtilisateurs
|
|
||||||
chatapp/Launcher.java
|
chatapp/Launcher.java
|
||||||
chatapp.Launcher
|
chatapp.Launcher
|
||||||
|
chatapp/Model/ListUtilisateurs.java
|
||||||
|
chatapp.Model.ListUtilisateurs
|
||||||
|
chatapp/Model/Utilisateur.java
|
||||||
|
chatapp.Model.Utilisateur
|
||||||
|
chatapp/Model/MessageHorodate.java
|
||||||
|
chatapp.Model.MessageHorodate
|
||||||
chatapp/Model/DataBase.java
|
chatapp/Model/DataBase.java
|
||||||
chatapp.Model.DataBase
|
chatapp.Model.DataBase
|
||||||
chatapp/Protocol/RunnerEcouteTCP.java
|
chatapp/Protocol/RunnerEcouteTCP.java
|
||||||
|
|
|
@ -98,6 +98,7 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
//-------Change son propre nom d'utilisateur-------//
|
//-------Change son propre nom d'utilisateur-------//
|
||||||
this.getActifUsers().modifierList(this.getMe().getPseudo(), nouveau);
|
this.getActifUsers().modifierList(this.getMe().getPseudo(), nouveau);
|
||||||
this.getMe().setPseudo(nouveau);
|
this.getMe().setPseudo(nouveau);
|
||||||
|
db.majPseudo("MacYAYA",nouveau);
|
||||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
||||||
this.getActifUsers().afficherListeUtilisateurs();
|
this.getActifUsers().afficherListeUtilisateurs();
|
||||||
return true;
|
return true;
|
||||||
|
@ -150,6 +151,10 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
System.out.println("Connexion reussie");
|
System.out.println("Connexion reussie");
|
||||||
//db.ajoutUtilisateurs(this.me.getId(),this.me.getPseudo());
|
//db.ajoutUtilisateurs(this.me.getId(),this.me.getPseudo());
|
||||||
db.majPseudo("MacYAYA",this.me.getPseudo());
|
db.majPseudo("MacYAYA",this.me.getPseudo());
|
||||||
|
db.majUtilisateursActifs(true,"MACYAYA");
|
||||||
|
//db.ajoutUtilisateurs(this.me.getId(),this.me.getPseudo());
|
||||||
|
//db.CreationTableHistorique("MACE","MACF");
|
||||||
|
//db.ajoutHistorique("MACE","MACF","Prout");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -183,6 +188,7 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
// Message que l'on envoie à tous les utilisateurs actifs
|
// Message que l'on envoie à tous les utilisateurs actifs
|
||||||
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
|
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
|
||||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||||
|
db.majUtilisateursActifs(false,"MACYAYA");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
main.stop();
|
main.stop();
|
||||||
|
@ -257,4 +263,5 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
public Application getMain() {
|
public Application getMain() {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
public DataBase getDb(){return this.db;}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class DataBase {
|
||||||
grand = ID1 ;
|
grand = ID1 ;
|
||||||
}
|
}
|
||||||
String nomTable = "Chat_" + petit + "_" + grand ;
|
String nomTable = "Chat_" + petit + "_" + grand ;
|
||||||
String Requete = "CREATE TABLE IF NOT EXISTS`" + nomTable +"` (\n" + "`Destinataire` varchar(100) NOT NULL,\n" + " `Source` varchar(100) NOT NULL,\n" + " `Envoi` timestamp NOT NULL,\n" + " `Message` text NOT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;";
|
String Requete = "CREATE TABLE IF NOT EXISTS`" + nomTable +"` (\n" + "`Destinataire` varchar(100) NOT NULL,\n" + " `Source` varchar(100) NOT NULL,\n" + " `Envoi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" + " `Message` text NOT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;";
|
||||||
System.out.println(Requete);
|
System.out.println(Requete);
|
||||||
PreparedStatement Ps = null ;
|
PreparedStatement Ps = null ;
|
||||||
//Statement est utilisé pour envoyer une requete SQL à la base de donnee
|
//Statement est utilisé pour envoyer une requete SQL à la base de donnee
|
||||||
|
@ -180,7 +180,7 @@ public class DataBase {
|
||||||
*/
|
*/
|
||||||
public void ajoutUtilisateurs(String ID , String Pseudo ) {
|
public void ajoutUtilisateurs(String ID , String Pseudo ) {
|
||||||
// Verification que l'utilisateur n'existe pas
|
// Verification que l'utilisateur n'existe pas
|
||||||
String existe= "SELECT Pseudo FROM Customers WHERE ID = " + ID;
|
String existe= "SELECT Pseudo FROM Utilisateurs WHERE ID = " + ID +",";
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
ResultSet rs = null ;
|
ResultSet rs = null ;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import chatapp.Controller.ChatApp;
|
import chatapp.Controller.ChatApp;
|
||||||
|
import chatapp.Model.DataBase;
|
||||||
import chatapp.Model.MessageHorodate;
|
import chatapp.Model.MessageHorodate;
|
||||||
import chatapp.Model.Utilisateur;
|
import chatapp.Model.Utilisateur;
|
||||||
import chatapp.View.FenetreSession;
|
import chatapp.View.FenetreSession;
|
||||||
|
@ -23,6 +24,7 @@ public class SessionClavardage extends Thread {
|
||||||
private ObjectOutputStream out;
|
private ObjectOutputStream out;
|
||||||
private ObjectInputStream in;
|
private ObjectInputStream in;
|
||||||
private PropertyChangeSupport pcs;
|
private PropertyChangeSupport pcs;
|
||||||
|
private DataBase db;
|
||||||
private ArrayList<MessageHorodate> derniersMsg; // on met temporairement les derniers msgs pour éviter les pb de synchro inter-threads
|
private ArrayList<MessageHorodate> derniersMsg; // on met temporairement les derniers msgs pour éviter les pb de synchro inter-threads
|
||||||
private int SessionID;
|
private int SessionID;
|
||||||
public SessionClavardage(Socket link, ChatApp app) {
|
public SessionClavardage(Socket link, ChatApp app) {
|
||||||
|
@ -37,6 +39,7 @@ public class SessionClavardage extends Thread {
|
||||||
}
|
}
|
||||||
this.derniersMsg = new ArrayList<MessageHorodate>();
|
this.derniersMsg = new ArrayList<MessageHorodate>();
|
||||||
this.SessionID = 2;
|
this.SessionID = 2;
|
||||||
|
this.db=DataBase.getInstance();
|
||||||
|
|
||||||
Platform.runLater( () ->
|
Platform.runLater( () ->
|
||||||
new FenetreSession(this)
|
new FenetreSession(this)
|
||||||
|
@ -59,6 +62,7 @@ public class SessionClavardage extends Thread {
|
||||||
}
|
}
|
||||||
this.derniersMsg = new ArrayList<MessageHorodate>();
|
this.derniersMsg = new ArrayList<MessageHorodate>();
|
||||||
this.pcs = new PropertyChangeSupport(this);
|
this.pcs = new PropertyChangeSupport(this);
|
||||||
|
//db.CreationTableHistorique("Doudou","Marvel");
|
||||||
this.start();
|
this.start();
|
||||||
Platform.runLater( () ->
|
Platform.runLater( () ->
|
||||||
new FenetreSession(this)
|
new FenetreSession(this)
|
||||||
|
@ -90,6 +94,7 @@ public class SessionClavardage extends Thread {
|
||||||
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),msg,1);
|
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),msg,1);
|
||||||
try {
|
try {
|
||||||
getOut().writeObject(msgh.toString());
|
getOut().writeObject(msgh.toString());
|
||||||
|
app.getDb().ajoutHistorique(app.getMe().getId(), u2.getId(),msg);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -106,6 +111,7 @@ public class SessionClavardage extends Thread {
|
||||||
String plaintext = null;
|
String plaintext = null;
|
||||||
MessageHorodate msg = null;
|
MessageHorodate msg = null;
|
||||||
System.out.println("Session demarre");
|
System.out.println("Session demarre");
|
||||||
|
app.getDb().CreationTableHistorique(app.getMe().getId(), u2.getId());
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
plaintext = (String) getIn().readObject();
|
plaintext = (String) getIn().readObject();
|
||||||
|
|
불러오는 중…
Reference in a new issue