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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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.EntityTransaction;
|
||||
import metier.*;
|
||||
|
||||
public class JpaTest {
|
||||
|
||||
@@ -24,7 +25,7 @@ public class JpaTest {
|
||||
tx.begin();
|
||||
try {
|
||||
|
||||
// TODO create and persist entity
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -36,6 +37,24 @@ public class JpaTest {
|
||||
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 jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class Choix extends Reponse{
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
ArrayList<String> choix;
|
||||
|
||||
public Choix() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public void setId(int id){
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Question {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public class Question implements Serializable {
|
||||
private int id;
|
||||
|
||||
@OneToMany(mappedBy ="reponse", cascade = CascadeType.DETACH)
|
||||
private Reponse reponse;
|
||||
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -4,36 +4,34 @@ import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Quizz{
|
||||
public class Quizz implements Serializable {
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_utilisateur")
|
||||
public int id;
|
||||
private Utilisateur utilisateur;
|
||||
|
||||
public Quizz(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id){
|
||||
public void setId(Integer id){
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setutilisateur(Utilisateur utilisateur){
|
||||
this.utilisateur=utilisateur;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_utilisateur")
|
||||
public Utilisateur getUtilisateur(){
|
||||
return this.utilisateur;
|
||||
return utilisateur;
|
||||
}
|
||||
|
||||
public void setUtilisateur(Utilisateur u){
|
||||
this.utilisateur=u;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
package metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public abstract class Reponse {
|
||||
public abstract class Reponse implements Serializable {
|
||||
private int id;
|
||||
private ArrayList<String> reponses;
|
||||
|
||||
public Reponse(){}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
||||
ArrayList<String> reponses;
|
||||
|
||||
|
||||
public Reponse(){
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(int id){
|
||||
this.id=id;
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setReponses(ArrayList<String> reponses){
|
||||
this.reponses=reponses;
|
||||
|
||||
@@ -1,37 +1,17 @@
|
||||
package metier;
|
||||
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class ReponseCourte extends Reponse{
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
String value;
|
||||
|
||||
|
||||
public ReponseCourte(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public void setId(int id){
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setValue(String value){
|
||||
this.value=value;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
package metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Session {
|
||||
|
||||
@Id
|
||||
public class Session implements Serializable {
|
||||
private int codePIN;
|
||||
|
||||
@OneToMany
|
||||
private ArrayList<Quizz> activities;
|
||||
|
||||
@ManyToMany
|
||||
private ArrayList<Utilisateur> utilisateurs;
|
||||
|
||||
public Session(){
|
||||
@@ -23,25 +17,20 @@ public class Session {
|
||||
this.codePIN = codePIN;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getCodePIN(){
|
||||
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){
|
||||
this.utilisateurs = utilisateurs;
|
||||
}
|
||||
|
||||
@ManyToMany
|
||||
public ArrayList<Utilisateur> getUtilisateurs() {
|
||||
return this.utilisateurs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,20 +2,16 @@ package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class Utilisateur{
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public class Utilisateur implements Serializable {
|
||||
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToMany
|
||||
private Session session;
|
||||
|
||||
@Column(unique=true)
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
@@ -24,6 +20,8 @@ public class Utilisateur{
|
||||
|
||||
public Utilisateur() {}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -40,14 +38,7 @@ public class Utilisateur{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(Session session){
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Column(unique=true)
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
@@ -56,6 +47,15 @@ public class Utilisateur{
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@ManyToMany
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(Session session){
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
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