Compare commits
6 Commits
tp_servlet
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
529d3ef855 | ||
|
|
6f75f83f58 | ||
|
|
3f264c2a01 | ||
|
|
93224bb17d | ||
|
|
bc5a0e488d | ||
|
|
1139a6ec7e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/target/
|
|
||||||
76
README.md
76
README.md
@@ -1,68 +1,18 @@
|
|||||||
# Template de projet pour le TP JPA UniR
|
# TP TAA
|
||||||
|
|
||||||
```mermaid
|
|
||||||
classDiagram
|
|
||||||
Utilisateur "*" -- "*" Session
|
|
||||||
Session "*" -- "1" Quizz
|
|
||||||
Quizz "1" -- "1..*" Question
|
|
||||||
Utilisateur "1" -- "*" Quizz
|
|
||||||
Question "1" -- "1" Reponse
|
|
||||||
Reponse <|-- ReponseCourte
|
|
||||||
Reponse <|-- Choix
|
|
||||||
|
|
||||||
|
|
||||||
class Utilisateur {
|
## TP1 - TP2
|
||||||
-id : int
|
|
||||||
name : String
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
getName()String
|
|
||||||
setName(name:String)void
|
|
||||||
|
|
||||||
}
|
Le compte rendu pour le TP1 et TP2 partie servlet est dans la branche tp_servlet
|
||||||
class Session{
|
|
||||||
-id : int
|
|
||||||
theme : int
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
getTheme()String
|
|
||||||
setTheme(theme:String)void
|
|
||||||
}
|
|
||||||
class Quizz{
|
|
||||||
-id : int
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
}
|
|
||||||
class Reponse{
|
|
||||||
- id : int
|
|
||||||
reponses : ArrayList<String>
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
getReponse()ArrayList<String>
|
|
||||||
setReponse(reponse:ArrayList<String> )void
|
|
||||||
}
|
|
||||||
class Choix{
|
|
||||||
- id : int
|
|
||||||
choix : List<String>
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
getChoix()List<String>
|
|
||||||
setChoix(choix:List<String>)void
|
|
||||||
}
|
|
||||||
class ReponseCourte{
|
|
||||||
- id : int
|
|
||||||
value : String
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
getVlaue()String
|
|
||||||
setId(id:String)void
|
|
||||||
}
|
|
||||||
class Question{
|
|
||||||
- id : int
|
|
||||||
getId()int
|
|
||||||
setId(id:int)void
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
Le compte rendu de la partie API Rest du TP2 est dans la branche tp_rest
|
||||||
|
|
||||||
Commande pour supprimer: ```rm -rd data/*```
|
## TP3 - TP4
|
||||||
|
|
||||||
|
Le compte rendu des TP3 et TP4 est dans la branche tp_spring
|
||||||
|
|
||||||
|
## Auteurs
|
||||||
|
|
||||||
|
- Tuan Minh VU
|
||||||
|
|
||||||
|
- Thibaut ROCHAS
|
||||||
|
|||||||
BIN
hsqldb-2.7.2.jar
BIN
hsqldb-2.7.2.jar
Binary file not shown.
37
pom.xml
37
pom.xml
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>test</groupId>
|
|
||||||
<artifactId>testjpa</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate</groupId>
|
|
||||||
<artifactId>hibernate-core</artifactId>
|
|
||||||
<version>6.2.7.Final</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<version>1.7.30</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hsqldb</groupId>
|
|
||||||
<artifactId>hsqldb</artifactId>
|
|
||||||
<version>2.7.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
<version>8.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
mkdir data
|
|
||||||
cd data
|
|
||||||
java -cp ..\hsqldb-2.7.2.jar org.hsqldb.Server
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
mvn dependency:copy-dependencies
|
|
||||||
mkdir data 2> /dev/null
|
|
||||||
cd data
|
|
||||||
java -cp ../target/dependency/hsqldb-2.7.2.jar org.hsqldb.Server
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
java -cp hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#mvn dependency:copy-dependencies
|
|
||||||
java -cp hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
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,10 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import metier.Question;
|
|
||||||
|
|
||||||
public class QuestionDAO extends GenericDAOImpl<Integer, Question> {
|
|
||||||
public QuestionDAO(){
|
|
||||||
super();
|
|
||||||
this.setClass(Question.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import metier.Quizz;
|
|
||||||
|
|
||||||
public class QuizzDAO extends GenericDAOImpl<Integer, Quizz>{
|
|
||||||
public QuizzDAO(){
|
|
||||||
super();
|
|
||||||
this.setClass(Quizz.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteAllQuiz(){
|
|
||||||
EntityTransaction et= em.getTransaction();
|
|
||||||
et.begin();
|
|
||||||
em.createQuery("delete from Quizz").executeUpdate();
|
|
||||||
et.commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import jakarta.persistence.Query;
|
|
||||||
import metier.Reponse;
|
|
||||||
|
|
||||||
public class ReponseDAO extends GenericDAOImpl<Integer, Reponse> {
|
|
||||||
public ReponseDAO(){
|
|
||||||
super();
|
|
||||||
this.setClass(Reponse.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public List<String> getGoodResponses(){
|
|
||||||
EntityTransaction t=em.getTransaction();
|
|
||||||
t.begin();
|
|
||||||
Query query=em.createQuery("select r from Reponse r where r.reponses");
|
|
||||||
List<String> lString=query.getResultList();
|
|
||||||
t.commit();
|
|
||||||
return lString;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import jakarta.persistence.Query;
|
|
||||||
import metier.Session;
|
|
||||||
import metier.Utilisateur;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SessionDAO extends GenericDAOImpl<Integer, Session> {
|
|
||||||
public SessionDAO() {
|
|
||||||
super();
|
|
||||||
this.setClass(Session.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<Session> findByTheme(String theme){
|
|
||||||
EntityTransaction t=em.getTransaction();
|
|
||||||
t.begin();
|
|
||||||
Query query=em.createQuery("select s from Session s where s.theme=:theme");
|
|
||||||
query.setParameter("theme",theme);
|
|
||||||
List<Session> sessions=query.getResultList();
|
|
||||||
t.commit();
|
|
||||||
if(sessions.size()>0){
|
|
||||||
return sessions;
|
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package DAO;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import jakarta.persistence.Query;
|
|
||||||
import metier.Utilisateur;
|
|
||||||
|
|
||||||
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
|
||||||
public UtilisateurDAO() {
|
|
||||||
super();
|
|
||||||
this.setClass(Utilisateur.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int findByEmail(String email){
|
|
||||||
EntityTransaction t=em.getTransaction();
|
|
||||||
t.begin();
|
|
||||||
Query query=em.createQuery("select u from Utilisateur u where u.email=:email");
|
|
||||||
query.setParameter("email",email);
|
|
||||||
Utilisateur u=(Utilisateur)query.getSingleResult();
|
|
||||||
t.commit();
|
|
||||||
return u.getId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package jpa;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
|
||||||
import jakarta.persistence.Persistence;
|
|
||||||
|
|
||||||
public class EntityManagerHelper {
|
|
||||||
|
|
||||||
private static final EntityManagerFactory emf;
|
|
||||||
private static final ThreadLocal<EntityManager> threadLocal;
|
|
||||||
|
|
||||||
static {
|
|
||||||
emf = Persistence.createEntityManagerFactory("dev");
|
|
||||||
threadLocal = new ThreadLocal<EntityManager>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityManager getEntityManager() {
|
|
||||||
EntityManager em = threadLocal.get();
|
|
||||||
|
|
||||||
if (em == null) {
|
|
||||||
em = emf.createEntityManager();
|
|
||||||
threadLocal.set(em);
|
|
||||||
}
|
|
||||||
return em;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeEntityManager() {
|
|
||||||
EntityManager em = threadLocal.get();
|
|
||||||
if (em != null) {
|
|
||||||
em.close();
|
|
||||||
threadLocal.set(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeEntityManagerFactory() {
|
|
||||||
emf.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void beginTransaction() {
|
|
||||||
getEntityManager().getTransaction().begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollback() {
|
|
||||||
getEntityManager().getTransaction().rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commit() {
|
|
||||||
getEntityManager().getTransaction().commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
package jpa;
|
|
||||||
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import metier.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JpaTest {
|
|
||||||
|
|
||||||
|
|
||||||
private EntityManager manager;
|
|
||||||
|
|
||||||
public JpaTest(EntityManager manager) {
|
|
||||||
this.manager = manager;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param args
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
EntityManager manager = EntityManagerHelper.getEntityManager();
|
|
||||||
|
|
||||||
JpaTest test = new JpaTest(manager);
|
|
||||||
|
|
||||||
EntityTransaction tx = manager.getTransaction();
|
|
||||||
tx.begin();
|
|
||||||
try {
|
|
||||||
test.create_user_test();
|
|
||||||
test.create_session_test();
|
|
||||||
//test.list_utilisateur();
|
|
||||||
test.list_session();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
tx.commit();
|
|
||||||
|
|
||||||
|
|
||||||
manager.close();
|
|
||||||
EntityManagerHelper.closeEntityManagerFactory();
|
|
||||||
System.out.println(".. done");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void create_user_test() {
|
|
||||||
int numUser = manager.createQuery("SELECT u FROM Utilisateur u", Utilisateur.class).getResultList().size();
|
|
||||||
if (numUser == 0) {
|
|
||||||
//Utilisateur
|
|
||||||
Utilisateur utilisateur1 = new Utilisateur();
|
|
||||||
utilisateur1.setName("Tibo");
|
|
||||||
|
|
||||||
Utilisateur utilisateur2 = new Utilisateur();
|
|
||||||
utilisateur2.setName("Rochas");
|
|
||||||
|
|
||||||
|
|
||||||
manager.persist(utilisateur1);
|
|
||||||
manager.persist(utilisateur2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void create_session_test() {
|
|
||||||
int numUser = manager.createQuery("SELECT u FROM Session u", Session.class).getResultList().size();
|
|
||||||
if (numUser == 0) {
|
|
||||||
//Utilisateur
|
|
||||||
|
|
||||||
|
|
||||||
Session session1 = new Session();
|
|
||||||
session1.setCodePIN(1703);
|
|
||||||
session1.setTheme("Inphormatik");
|
|
||||||
session1.setQuizzs(new ArrayList<>());
|
|
||||||
|
|
||||||
List<Utilisateur> ulist = manager.createQuery("select user from Utilisateur user").getResultList();
|
|
||||||
session1.setUtilisateurs(ulist);
|
|
||||||
|
|
||||||
|
|
||||||
manager.persist(session1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void list_utilisateur(){
|
|
||||||
List<Utilisateur> result_utilisatuer_list= manager.createQuery("select u from Utilisateur u", Utilisateur.class).getResultList();
|
|
||||||
for (Utilisateur u : result_utilisatuer_list) {
|
|
||||||
System.out.println(u.getId() + " " + u.getName() +" "+ u.getEmail());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void list_session(){
|
|
||||||
List<Session> result_session_list= manager.createQuery("select s from Session s", Session.class).getResultList();
|
|
||||||
for (Session s : result_session_list) {
|
|
||||||
System.out.println(s.getCodePIN() + " " + s.getTheme());
|
|
||||||
for(Utilisateur u : s.getUtilisateurs()){
|
|
||||||
System.out.println(u.getId() + " " + u.getName() +" "+ u.getEmail());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
|
||||||
public class Choix extends Reponse{
|
|
||||||
ArrayList<String> choix;
|
|
||||||
|
|
||||||
public Choix() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getChoix() {
|
|
||||||
return this.choix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChoix(ArrayList<String> choix) {
|
|
||||||
this.choix = choix;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Question implements Serializable {
|
|
||||||
private int id;
|
|
||||||
private Reponse reponse;
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToOne(cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name ="bonne_reponse", referencedColumnName = "id")
|
|
||||||
public Reponse getReponse() {
|
|
||||||
return reponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReponse(Reponse reponse) {
|
|
||||||
this.reponse = reponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Quizz implements Serializable {
|
|
||||||
private Session session;
|
|
||||||
private int id;
|
|
||||||
private Utilisateur utilisateur;
|
|
||||||
|
|
||||||
public Quizz(){
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
public int getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id){
|
|
||||||
this.id=id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
public Session getSession(){
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSession(Session session){
|
|
||||||
this.session=session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name="id_utilisateur")
|
|
||||||
public Utilisateur getUtilisateur(){
|
|
||||||
return utilisateur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUtilisateur(Utilisateur u){
|
|
||||||
this.utilisateur=u;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Inheritance(strategy=InheritanceType.JOINED)
|
|
||||||
@DiscriminatorColumn(name="Type_reponse")
|
|
||||||
@DiscriminatorValue("Reponse")
|
|
||||||
public abstract class Reponse implements Serializable {
|
|
||||||
private int id;
|
|
||||||
private Question question;
|
|
||||||
public ArrayList<String> reponses;
|
|
||||||
|
|
||||||
public Reponse(){}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToOne
|
|
||||||
public Question getQuestion(){
|
|
||||||
return this.question;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuestion(Question question){
|
|
||||||
this.question=question;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getReponses(){
|
|
||||||
return this.reponses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReponses(ArrayList<String> reponses){
|
|
||||||
this.reponses=reponses;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@PrimaryKeyJoinColumn(name = "RC_Id")
|
|
||||||
public class ReponseCourte extends Reponse{
|
|
||||||
String value;
|
|
||||||
|
|
||||||
public ReponseCourte(){
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value){
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
public String getValue(){
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Session implements Serializable {
|
|
||||||
private int codePIN;
|
|
||||||
private List<Quizz> quizzs;
|
|
||||||
private List<Utilisateur> utilisateurs;
|
|
||||||
private String theme;
|
|
||||||
|
|
||||||
public Session(){
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodePIN(int codePIN){
|
|
||||||
this.codePIN = codePIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
public int getCodePIN(){
|
|
||||||
return this.codePIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuizzs(List<Quizz> quizzs){
|
|
||||||
this.quizzs = quizzs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(mappedBy="session")
|
|
||||||
public List<Quizz> getQuizzs(){
|
|
||||||
return this.quizzs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUtilisateurs(List<Utilisateur> utilisateurs){
|
|
||||||
this.utilisateurs = utilisateurs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "session")
|
|
||||||
public List<Utilisateur> getUtilisateurs() {
|
|
||||||
return this.utilisateurs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTheme(){
|
|
||||||
return this.theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTheme(String theme){
|
|
||||||
this.theme = theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addUser(Utilisateur user){
|
|
||||||
this.utilisateurs.add(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package metier;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Utilisateur implements Serializable {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
private List<Session> session;
|
|
||||||
private String email;
|
|
||||||
private String password;
|
|
||||||
private List<Quizz> quizzs;
|
|
||||||
|
|
||||||
public Utilisateur() {}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column(unique=true)
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
@JoinTable(
|
|
||||||
name="utilisateur_session",
|
|
||||||
joinColumns = @JoinColumn(name="utilisateur_id"),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "session_pin")
|
|
||||||
)
|
|
||||||
public List<Session> getSession() {
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSession(List<Session> session){
|
|
||||||
this.session = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "utilisateur")
|
|
||||||
public List<Quizz> getQuizzs() {
|
|
||||||
return quizzs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuizzs(List<Quizz> quizzs) {
|
|
||||||
this.quizzs = quizzs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
|
||||||
version="3.0">
|
|
||||||
|
|
||||||
<persistence-unit name="dev" transaction-type="RESOURCE_LOCAL">
|
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
|
||||||
<properties>
|
|
||||||
<property name="jakarta.persistence.jdbc.driver"
|
|
||||||
value="org.hsqldb.jdbcDriver" />
|
|
||||||
<property name="jakarta.persistence.jdbc.url"
|
|
||||||
value="jdbc:hsqldb:hsql://localhost/" />
|
|
||||||
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
|
||||||
<property name="jakarta.persistence.jdbc.password" value="" />
|
|
||||||
<property
|
|
||||||
name="jakarta.persistence.schema-generation.database.action"
|
|
||||||
value="create" />
|
|
||||||
<property name="jakarta.persistence.dialect"
|
|
||||||
value="org.hibernate.dialect.HSQLDialect" />
|
|
||||||
<property name="hibernate.show_sql" value="true" />
|
|
||||||
</properties>
|
|
||||||
</persistence-unit>
|
|
||||||
<persistence-unit name="prod" transaction-type="RESOURCE_LOCAL">
|
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
|
||||||
<properties>
|
|
||||||
<property name="jakarta.persistence.jdbc.driver"
|
|
||||||
value="org.hsqldb.jdbcDriver" />
|
|
||||||
<property name="jakarta.persistence.jdbc.url"
|
|
||||||
value="jdbc:hsqldb:hsql://localhost/" />
|
|
||||||
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
|
||||||
<property name="jakarta.persistence.jdbc.password" value="" />
|
|
||||||
<property
|
|
||||||
name="jakarta.persistence.schema-generation.database.action"
|
|
||||||
value="update" />
|
|
||||||
<property name="jakarta.persistence.dialect"
|
|
||||||
value="org.hibernate.dialect.HSQLDialect" />
|
|
||||||
<property name="hibernate.show_sql" value="true" />
|
|
||||||
|
|
||||||
</properties>
|
|
||||||
</persistence-unit>
|
|
||||||
|
|
||||||
<persistence-unit name="mysql">
|
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<property name="jakarta.persistence.jdbc.driver"
|
|
||||||
value="com.mysql.cj.jdbc.Driver" />
|
|
||||||
<property name="jakarta.persistence.jdbc.url"
|
|
||||||
value="jdbc:mysql://localhost/mydatabase" />
|
|
||||||
<property name="jakarta.persistence.jdbc.user" value="tlc" />
|
|
||||||
<property name="jakarta.persistence.jdbc.password" value="tlc" />
|
|
||||||
<property
|
|
||||||
name="jakarta.persistence.schema-generation.database.action"
|
|
||||||
value="update" />
|
|
||||||
<property name="jakarta.persistence.dialect"
|
|
||||||
value="org.hibernate.dialect.MySQL8Dialect" />
|
|
||||||
<property name="hibernate.show_sql" value="true" />
|
|
||||||
<property name="hibernate.c3p0.min_size" value="5" />
|
|
||||||
<property name="hibernate.c3p0.max_size" value="20" />
|
|
||||||
<property name="hibernate.c3p0.timeout" value="300" />
|
|
||||||
<property name="hibernate.c3p0.max_statements" value="50" />
|
|
||||||
<property name="hibernate.c3p0.idle_test_period" value="3000" />
|
|
||||||
</properties>
|
|
||||||
</persistence-unit>
|
|
||||||
|
|
||||||
</persistence>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
----------------------------------------------log4j.properties
|
|
||||||
|
|
||||||
### direct log messages to stdout
|
|
||||||
###
|
|
||||||
log4j.rootLogger=INFO, stdout
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.Target=System.out
|
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
|
||||||
|
|
||||||
# Log everything. Good for troubleshooting
|
|
||||||
log4j.logger.org.hibernate=ERROR
|
|
||||||
|
|
||||||
# Log all JDBC parameters
|
|
||||||
log4j.logger.org.hibernate.type=ERROR
|
|
||||||
Reference in New Issue
Block a user