merge + gitignore
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
public class ChoixDAO {
|
|
||||||
}
|
|
||||||
13
src/main/java/DAO/Generic.java
Normal file
13
src/main/java/DAO/Generic.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package DAO;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface Generic<K, T extends Serializable> {
|
||||||
|
void create(final T entity);
|
||||||
|
T findById(final K id);
|
||||||
|
T update(final T entity);
|
||||||
|
void delete(final T entity);
|
||||||
|
void deleteById(final K id);
|
||||||
|
List<T> findAll();
|
||||||
|
}
|
||||||
60
src/main/java/DAO/GenericDAOImpl.java
Normal file
60
src/main/java/DAO/GenericDAOImpl.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package DAO;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import jakarta.persistence.PersistenceException;
|
||||||
|
import jpa.EntityManagerHelper;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class GenericDAOImpl<K, T extends Serializable> implements Generic<K, T> {
|
||||||
|
protected EntityManager em;
|
||||||
|
private Class<T> entityClass;
|
||||||
|
|
||||||
|
public GenericDAOImpl() {
|
||||||
|
this.em = EntityManagerHelper.getEntityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Pour connaitre qu'on travaille avec quelle classe
|
||||||
|
public void setClass(Class<T> class2){
|
||||||
|
this.entityClass= class2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> findAll() {
|
||||||
|
return em.createQuery("select e from " + entityClass.getName() + " as e", entityClass).getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CRUD
|
||||||
|
public void create(T entity){
|
||||||
|
EntityTransaction t = em.getTransaction();
|
||||||
|
t.begin();
|
||||||
|
em.persist(entity);
|
||||||
|
t.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T findById(K id) {
|
||||||
|
return em.find(entityClass, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T update(T entity){
|
||||||
|
EntityTransaction t = em.getTransaction();
|
||||||
|
t.begin();
|
||||||
|
T T_sync = em.merge(entity);
|
||||||
|
t.commit();
|
||||||
|
return T_sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(T entity){
|
||||||
|
EntityTransaction t = em.getTransaction();
|
||||||
|
t.begin();
|
||||||
|
em.remove(entity);
|
||||||
|
t.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(K id) {
|
||||||
|
T T_to_be_deleted = em.find(entityClass, id);
|
||||||
|
em.remove(T_to_be_deleted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
package DAO;
|
package DAO;
|
||||||
|
|
||||||
public class QuestionDAO {
|
import metier.Question;
|
||||||
|
|
||||||
|
public class QuestionDAO extends GenericDAOImpl<Integer, Question> {
|
||||||
|
public QuestionDAO(){
|
||||||
|
super();
|
||||||
|
this.setClass(Question.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
package DAO;
|
package DAO;
|
||||||
|
|
||||||
public class QuizzDAO {
|
import metier.Quizz;
|
||||||
|
|
||||||
|
public class QuizzDAO extends GenericDAOImpl<Integer, Quizz>{
|
||||||
|
public QuizzDAO(){
|
||||||
|
super();
|
||||||
|
this.setClass(Quizz.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
public class ReponseCourteDAO {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
package DAO;
|
package DAO;
|
||||||
|
|
||||||
public class ReponseDAO {
|
import metier.Reponse;
|
||||||
|
|
||||||
|
public class ReponseDAO extends GenericDAOImpl<Integer, Reponse> {
|
||||||
|
public ReponseDAO(){
|
||||||
|
super();
|
||||||
|
this.setClass(Reponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
package DAO;
|
package DAO;
|
||||||
|
|
||||||
public class SessionDAO {
|
|
||||||
|
import metier.Session;
|
||||||
|
|
||||||
|
public class SessionDAO extends GenericDAOImpl<Integer, Session> {
|
||||||
|
public SessionDAO() {
|
||||||
|
super();
|
||||||
|
this.setClass(Session.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface Tous<T, Id extends Serializable> {
|
|
||||||
T create(T t);
|
|
||||||
T update(T t);
|
|
||||||
T read(Id id);
|
|
||||||
void delete(T t);
|
|
||||||
List<T> findAll();
|
|
||||||
|
|
||||||
T save(T t);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import jakarta.persistence.PersistenceException;
|
|
||||||
import jpa.EntityManagerHelper;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public abstract class TousDAOImpl<T, Id extends Serializable> implements Tous<T, Id> {
|
|
||||||
protected EntityManager em;
|
|
||||||
private Class<T> entityClass;
|
|
||||||
|
|
||||||
public TousDAOImpl() {
|
|
||||||
this.em = EntityManagerHelper.getEntityManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T save(T t) {
|
|
||||||
EntityTransaction tx = em.getTransaction();
|
|
||||||
try {
|
|
||||||
tx.begin();
|
|
||||||
em.persist(t);
|
|
||||||
tx.commit();
|
|
||||||
return t;
|
|
||||||
} catch (PersistenceException e) {
|
|
||||||
throw new PersistenceException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
package DAO;
|
package DAO;
|
||||||
|
|
||||||
public class UtilisateurDAO {
|
import metier.Utilisateur;
|
||||||
|
|
||||||
|
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||||
|
public UtilisateurDAO() {
|
||||||
|
super();
|
||||||
|
this.setClass(Utilisateur.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package jpa;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import metier.*;
|
||||||
|
|
||||||
public class JpaTest {
|
public class JpaTest {
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class JpaTest {
|
|||||||
tx.begin();
|
tx.begin();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// TODO create and persist entity
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -36,6 +37,24 @@ public class JpaTest {
|
|||||||
System.out.println(".. done");
|
System.out.println(".. done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void create_quizz() {
|
||||||
|
int numQuizz = manager.createQuery("SELECT q FROM Quizz q", Quizz.class).getResultList().size();
|
||||||
|
if (numQuizz == 0) {
|
||||||
|
//Utilisateur
|
||||||
|
Utilisateur utilisateur1 = new Utilisateur();
|
||||||
|
utilisateur1.setId(1);
|
||||||
|
utilisateur1.setName("Tibo");
|
||||||
|
|
||||||
|
Utilisateur utilisateur2 = new Utilisateur();
|
||||||
|
utilisateur2.setId(2);
|
||||||
|
utilisateur2.setName("Rochas");
|
||||||
|
|
||||||
|
manager.persist(utilisateur1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,30 +2,12 @@ package metier;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
|
|
||||||
public class Choix extends Reponse{
|
public class Choix extends Reponse{
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
ArrayList<String> choix;
|
ArrayList<String> choix;
|
||||||
|
|
||||||
public Choix() {
|
public Choix() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setId(int id){
|
|
||||||
this.id=id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(){
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
import jakarta.persistence.CascadeType;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class Question {
|
public class Question implements Serializable {
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@OneToMany(mappedBy ="reponse", cascade = CascadeType.DETACH)
|
@OneToMany(mappedBy ="reponse", cascade = CascadeType.DETACH)
|
||||||
private Reponse reponse;
|
private Reponse reponse;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,36 +4,34 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class Quizz{
|
public class Quizz implements Serializable {
|
||||||
|
|
||||||
|
public int id;
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name="id_utilisateur")
|
|
||||||
private Utilisateur utilisateur;
|
private Utilisateur utilisateur;
|
||||||
|
|
||||||
public Quizz(){
|
public Quizz(){
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
public int getId(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public void setId(int id){
|
public void setId(Integer id){
|
||||||
this.id=id;
|
this.id=id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId(){
|
@ManyToOne
|
||||||
return this.id;
|
@JoinColumn(name="id_utilisateur")
|
||||||
}
|
|
||||||
|
|
||||||
public void setutilisateur(Utilisateur utilisateur){
|
|
||||||
this.utilisateur=utilisateur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Utilisateur getUtilisateur(){
|
public Utilisateur getUtilisateur(){
|
||||||
return this.utilisateur;
|
return utilisateur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUtilisateur(Utilisateur u){
|
||||||
|
this.utilisateur=u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,28 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
public abstract class Reponse {
|
public abstract class Reponse implements Serializable {
|
||||||
|
private int id;
|
||||||
|
private ArrayList<String> reponses;
|
||||||
|
|
||||||
|
public Reponse(){}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
public int getId() {
|
||||||
|
return id;
|
||||||
ArrayList<String> reponses;
|
|
||||||
|
|
||||||
|
|
||||||
public Reponse(){
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
public void setId(int id){
|
this.id = id;
|
||||||
this.id=id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId(){
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReponses(ArrayList<String> reponses){
|
public void setReponses(ArrayList<String> reponses){
|
||||||
this.reponses=reponses;
|
this.reponses=reponses;
|
||||||
|
|||||||
@@ -1,37 +1,17 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
|
|
||||||
public class ReponseCourte extends Reponse{
|
public class ReponseCourte extends Reponse{
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
|
|
||||||
public ReponseCourte(){
|
public ReponseCourte(){
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setId(int id){
|
|
||||||
this.id=id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(){
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value){
|
public void setValue(String value){
|
||||||
this.value=value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(){
|
public String getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Session {
|
public class Session implements Serializable {
|
||||||
|
|
||||||
@Id
|
|
||||||
private int codePIN;
|
private int codePIN;
|
||||||
|
|
||||||
@OneToMany
|
|
||||||
private ArrayList<Quizz> activities;
|
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
private ArrayList<Utilisateur> utilisateurs;
|
private ArrayList<Utilisateur> utilisateurs;
|
||||||
|
|
||||||
public Session(){
|
public Session(){
|
||||||
@@ -23,25 +17,20 @@ public class Session {
|
|||||||
this.codePIN = codePIN;
|
this.codePIN = codePIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getCodePIN(){
|
public int getCodePIN(){
|
||||||
return this.codePIN;
|
return this.codePIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivities(ArrayList<Quizz> activities){
|
|
||||||
this.activities = activities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Quizz> getActivities(){
|
|
||||||
return this.activities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUtilisateurs(ArrayList<Utilisateur> utilisateurs){
|
public void setUtilisateurs(ArrayList<Utilisateur> utilisateurs){
|
||||||
this.utilisateurs = utilisateurs;
|
this.utilisateurs = utilisateurs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
public ArrayList<Utilisateur> getUtilisateurs() {
|
public ArrayList<Utilisateur> getUtilisateurs() {
|
||||||
return this.utilisateurs;
|
return this.utilisateurs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,20 +2,16 @@ package metier;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Utilisateur{
|
public class Utilisateur implements Serializable {
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
private Session session;
|
private Session session;
|
||||||
|
|
||||||
@Column(unique=true)
|
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@@ -24,6 +20,8 @@ public class Utilisateur{
|
|||||||
|
|
||||||
public Utilisateur() {}
|
public Utilisateur() {}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -40,14 +38,7 @@ public class Utilisateur{
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Session getSession() {
|
@Column(unique=true)
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSession(Session session){
|
|
||||||
this.session = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
@@ -56,6 +47,15 @@ public class Utilisateur{
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
public Session getSession() {
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSession(Session session){
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return this.password;
|
return this.password;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
BIN
target/classes/DAO/Generic.class
Normal file
BIN
target/classes/DAO/Generic.class
Normal file
Binary file not shown.
BIN
target/classes/DAO/GenericDAOImpl.class
Normal file
BIN
target/classes/DAO/GenericDAOImpl.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user