initial commit
This commit is contained in:
BIN
ResHotel.vpp
Normal file
BIN
ResHotel.vpp
Normal file
Binary file not shown.
BIN
livrables/ResHotel_ClassDiagram.jpg
Normal file
BIN
livrables/ResHotel_ClassDiagram.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
BIN
livrables/ResHotel_ERDiagram.jpg
Normal file
BIN
livrables/ResHotel_ERDiagram.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
116
pom.xml
Normal file
116
pom.xml
Normal file
@@ -0,0 +1,116 @@
|
||||
<?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>vthedon.uqac.pooa</groupId>
|
||||
<artifactId>reshotel</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>reshotel</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.hibernate.dialect/sqlite-dialect -->
|
||||
<dependency>
|
||||
<groupId>com.github.gwenn</groupId>
|
||||
<artifactId>sqlite-dialect</artifactId>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.39.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.6.12.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>8.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement
|
||||
><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>vthedon.uqac.pooa.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
20
src/main/java/vthedon/uqac/pooa/App.java
Normal file
20
src/main/java/vthedon/uqac/pooa/App.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package vthedon.uqac.pooa;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import vthedon.uqac.pooa.core.Adresse;
|
||||
import vthedon.uqac.pooa.core.Client;
|
||||
import vthedon.uqac.pooa.core.SystemeGestionReservations;
|
||||
import vthedon.uqac.pooa.core.SystemeGestionReservationsImpl;
|
||||
import vthedon.uqac.pooa.ui.UI;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("reshotel");
|
||||
|
||||
SystemeGestionReservationsImpl sgr = new SystemeGestionReservationsImpl(emf);
|
||||
sgr.start();
|
||||
|
||||
}
|
||||
}
|
||||
164
src/main/java/vthedon/uqac/pooa/core/Adresse.java
Normal file
164
src/main/java/vthedon/uqac/pooa/core/Adresse.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Adresse")
|
||||
public class Adresse implements Serializable {
|
||||
public Adresse() {
|
||||
}
|
||||
|
||||
@Column(name = "idAdresse", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "ADRESSE_IDADRESSE_GENERATOR")
|
||||
@GenericGenerator(name = "ADRESSE_IDADRESSE_GENERATOR", strategy = "native")
|
||||
private int idAdresse;
|
||||
|
||||
@Column(name = "rue", nullable = true, length = 255)
|
||||
private String rue;
|
||||
|
||||
@Column(name = "codePostal", nullable = true, length = 10)
|
||||
private String codePostal;
|
||||
|
||||
@Column(name = "ville", nullable = true, length = 255)
|
||||
private String ville;
|
||||
|
||||
@Column(name = "province", nullable = true, length = 255)
|
||||
private String province;
|
||||
|
||||
@Column(name = "pays", nullable = true, length = 255)
|
||||
private String pays;
|
||||
|
||||
@OneToMany(mappedBy = "adresse", targetEntity = Hebergement.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Hebergement> hebergements = new HashSet<Hebergement>();
|
||||
|
||||
@OneToMany(mappedBy = "adresse", targetEntity = Ticket.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Ticket> tickets = new HashSet<Ticket>();
|
||||
|
||||
@OneToMany(mappedBy = "adresse", targetEntity = Client.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Client> clients = new HashSet<Client>();
|
||||
|
||||
public int getIdAdresse() {
|
||||
return idAdresse;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdAdresse();
|
||||
}
|
||||
|
||||
public void setRue(String value) {
|
||||
this.rue = value;
|
||||
}
|
||||
|
||||
public String getRue() {
|
||||
return rue;
|
||||
}
|
||||
|
||||
public void setCodePostal(String value) {
|
||||
this.codePostal = value;
|
||||
}
|
||||
|
||||
public String getCodePostal() {
|
||||
return codePostal;
|
||||
}
|
||||
|
||||
public void setVille(String value) {
|
||||
this.ville = value;
|
||||
}
|
||||
|
||||
public String getVille() {
|
||||
return ville;
|
||||
}
|
||||
|
||||
public void setProvince(String value) {
|
||||
this.province = value;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setPays(String value) {
|
||||
this.province = value;
|
||||
}
|
||||
|
||||
public String getPays() {
|
||||
return pays;
|
||||
}
|
||||
|
||||
public void setHebergements(Set<Hebergement> value) {
|
||||
this.hebergements = value;
|
||||
}
|
||||
|
||||
public Set<Hebergement> getHebergements() {
|
||||
return hebergements;
|
||||
}
|
||||
|
||||
public void setTickets(Set<Ticket> value) {
|
||||
this.tickets = value;
|
||||
}
|
||||
|
||||
public Set<Ticket> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setClients(Set<Client> value) {
|
||||
this.clients = value;
|
||||
}
|
||||
|
||||
public Set<Client> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public String getFirstNotNull() {
|
||||
if (!rue.equals(""))
|
||||
return rue;
|
||||
else if (!ville.equals(""))
|
||||
return ville;
|
||||
else if (!province.equals(""))
|
||||
return province;
|
||||
else if (!pays.equals(""))
|
||||
return pays;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String toString = "";
|
||||
toString += "Rue : " + this.rue + "\n";
|
||||
toString += "Code Postal : " + this.codePostal + "\n";
|
||||
toString += "Ville : " + this.ville + "\n";
|
||||
toString += "Province : " + this.province + "\n";
|
||||
toString += "Pays : " + this.pays + "\n";
|
||||
return toString;
|
||||
}
|
||||
|
||||
public String toStringReduce() {
|
||||
String toString = this.rue + ", " + this.codePostal + ", " + this.ville + ", " + this.province + ", " + this.pays;
|
||||
return toString;
|
||||
}
|
||||
|
||||
}
|
||||
197
src/main/java/vthedon/uqac/pooa/core/Chambres.java
Normal file
197
src/main/java/vthedon/uqac/pooa/core/Chambres.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Chambres")
|
||||
@IdClass(ChambresPK.class)
|
||||
public class Chambres implements Serializable {
|
||||
public Chambres() {
|
||||
}
|
||||
|
||||
public boolean equals(Object aObj) {
|
||||
if (aObj == this)
|
||||
return true;
|
||||
if (!(aObj instanceof Chambres))
|
||||
return false;
|
||||
Chambres chambres = (Chambres) aObj;
|
||||
if (getTypeChambre() == null) {
|
||||
if (chambres.getTypeChambre() != null)
|
||||
return false;
|
||||
} else if (!getTypeChambre().equals(chambres.getTypeChambre()))
|
||||
return false;
|
||||
if (getHebergement() == null) {
|
||||
if (chambres.getHebergement() != null)
|
||||
return false;
|
||||
} else if (!getHebergement().equals(chambres.getHebergement()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashcode = 0;
|
||||
if (getTypeChambre() != null) {
|
||||
hashcode = hashcode + (int) getTypeChambre().getORMID();
|
||||
}
|
||||
if (getHebergement() != null) {
|
||||
hashcode = hashcode + (getHebergement().getAdresse() == null ? 0 : getHebergement().getAdresse().hashCode());
|
||||
hashcode = hashcode
|
||||
+ (getHebergement().getTypeHebergement() == null ? 0 : getHebergement().getTypeHebergement().hashCode());
|
||||
}
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@PrimaryKeyJoinColumn
|
||||
@ManyToOne(targetEntity = TypeChambre.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idTypeChambre", referencedColumnName = "idTypeChambre", nullable = false) }, foreignKey = @ForeignKey(name = "FKChambres482652"))
|
||||
private TypeChambre typeChambre;
|
||||
|
||||
@Column(name = "idTypeChambre", nullable = false, insertable = false, updatable = false)
|
||||
@Id
|
||||
@GeneratedValue(generator = "CHAMBRES_IDTYPECHAMBREID_GENERATOR")
|
||||
@GenericGenerator(name = "CHAMBRES_IDTYPECHAMBREID_GENERATOR", strategy = "foreign", parameters = @Parameter(name = "property", value = "idTypeChambre"))
|
||||
private int idTypeChambre;
|
||||
|
||||
public int getIdTypeChambre() {
|
||||
return idTypeChambre;
|
||||
}
|
||||
|
||||
@Id
|
||||
@ManyToOne(targetEntity = Hebergement.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = { @JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false),
|
||||
@JoinColumn(name = "idTypeHebergement", referencedColumnName = "idTypeHebergement", nullable = false) }, foreignKey = @ForeignKey(name = "FKChambres994569"))
|
||||
private Hebergement hebergement;
|
||||
|
||||
@Column(name = "nom", nullable = false, length = 120)
|
||||
private String nom = "Basic";
|
||||
|
||||
@Column(name = "quantite", nullable = false, length = 10)
|
||||
private int quantite = 1;
|
||||
|
||||
@Column(name = "prixNuit", nullable = false, precision = 5, scale = 2)
|
||||
private java.math.BigDecimal prixNuit;
|
||||
|
||||
@ManyToMany(mappedBy = "chambres", targetEntity = Service.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Service> services = new HashSet<Service>();
|
||||
|
||||
@OneToMany(mappedBy = "chambre", targetEntity = Reservation.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Reservation> reservations = new HashSet<Reservation>();
|
||||
|
||||
public void setNom(String value) {
|
||||
this.nom = value;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setQuantite(int value) {
|
||||
this.quantite = value;
|
||||
}
|
||||
|
||||
public int getQuantite() {
|
||||
return quantite;
|
||||
}
|
||||
|
||||
public void setPrixNuit(java.math.BigDecimal value) {
|
||||
this.prixNuit = value;
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getPrixNuit() {
|
||||
return prixNuit;
|
||||
}
|
||||
|
||||
public void setTypeChambre(TypeChambre value) {
|
||||
this.typeChambre = value;
|
||||
}
|
||||
|
||||
public TypeChambre getTypeChambre() {
|
||||
return typeChambre;
|
||||
}
|
||||
|
||||
public void setHebergement(Hebergement value) {
|
||||
this.hebergement = value;
|
||||
}
|
||||
|
||||
public Hebergement getHebergement() {
|
||||
return hebergement;
|
||||
}
|
||||
|
||||
public void setServices(Set<Service> value) {
|
||||
this.services = value;
|
||||
}
|
||||
|
||||
public Set<Service> getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public void setReservations(Set<Reservation> value) {
|
||||
this.reservations = value;
|
||||
}
|
||||
|
||||
public Set<Reservation> getReservations() {
|
||||
return reservations;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String toString = "";
|
||||
toString += "- " + this.nom + " -\n";
|
||||
toString += "\t" + "Type de chambre : " + this.typeChambre.toString() + "\n";
|
||||
toString += "\t" + "Prix par nuit : " + this.prixNuit + " $\n";
|
||||
toString += "\t" + "Service : ";
|
||||
for (Service s : this.services)
|
||||
toString += s.toString() + ", ";
|
||||
toString += "\b";
|
||||
return toString;
|
||||
}
|
||||
|
||||
@Transient
|
||||
private boolean _saved = false;
|
||||
|
||||
public void onSave() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return _saved;
|
||||
}
|
||||
|
||||
}
|
||||
77
src/main/java/vthedon/uqac/pooa/core/ChambresPK.java
Normal file
77
src/main/java/vthedon/uqac/pooa/core/ChambresPK.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
|
||||
@Embeddable
|
||||
public class ChambresPK implements Serializable {
|
||||
public boolean equals(Object aObj) {
|
||||
if (aObj == this)
|
||||
return true;
|
||||
if (!(aObj instanceof ChambresPK))
|
||||
return false;
|
||||
ChambresPK chambrespk = (ChambresPK) aObj;
|
||||
if (getIdTypeChambre() == null) {
|
||||
if (chambrespk.getIdTypeChambre() != null)
|
||||
return false;
|
||||
} else if (!getIdTypeChambre().equals(chambrespk.getIdTypeChambre()))
|
||||
return false;
|
||||
if (getHebergement() == null) {
|
||||
if (chambrespk.getHebergement() != null)
|
||||
return false;
|
||||
} else if (!getHebergement().equals(chambrespk.getHebergement()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashcode = 0;
|
||||
if (getIdTypeChambre() != null) {
|
||||
hashcode = hashcode + (int) getIdTypeChambre().getORMID();
|
||||
}
|
||||
if (getHebergement() != null) {
|
||||
hashcode = hashcode + (getHebergement().getAdresse() == null ? 0 : getHebergement().getAdresse().hashCode());
|
||||
hashcode = hashcode
|
||||
+ (getHebergement().getTypeHebergement() == null ? 0 : getHebergement().getTypeHebergement().hashCode());
|
||||
}
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@ManyToOne(targetEntity = TypeChambre.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.LOCK })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idTypeChambre", referencedColumnName = "idTypeChambre", nullable = false) }, foreignKey = @ForeignKey(name = "FKChambres482652"))
|
||||
private TypeChambre typeChambre;
|
||||
|
||||
public void setIdTypeChambre(TypeChambre value) {
|
||||
this.typeChambre = value;
|
||||
}
|
||||
|
||||
public TypeChambre getIdTypeChambre() {
|
||||
return this.typeChambre;
|
||||
}
|
||||
|
||||
@ManyToOne(targetEntity = Hebergement.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = { @JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false),
|
||||
@JoinColumn(name = "idTypeHebergement", referencedColumnName = "idTypeHebergement", nullable = false) }, foreignKey = @ForeignKey(name = "FKChambres994569"))
|
||||
private Hebergement hebergement;
|
||||
|
||||
public void setHebergement(Hebergement value) {
|
||||
this.hebergement = value;
|
||||
}
|
||||
|
||||
public Hebergement getHebergement() {
|
||||
return this.hebergement;
|
||||
}
|
||||
|
||||
}
|
||||
158
src/main/java/vthedon/uqac/pooa/core/Client.java
Normal file
158
src/main/java/vthedon/uqac/pooa/core/Client.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Client")
|
||||
public class Client implements Serializable {
|
||||
public Client() {
|
||||
}
|
||||
|
||||
public boolean equals(Object aObj) {
|
||||
if (aObj == this)
|
||||
return true;
|
||||
if (!(aObj instanceof Client))
|
||||
return false;
|
||||
Client client = (Client) aObj;
|
||||
if ((getEmail() != null && !getEmail().equals(client.getEmail()))
|
||||
|| (getEmail() == null && client.getEmail() != null))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashcode = 0;
|
||||
hashcode = hashcode + (getEmail() == null ? 0 : getEmail().hashCode());
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@Column(name = "email", nullable = false, length = 120)
|
||||
@Id
|
||||
private String email;
|
||||
|
||||
@Column(name = "nom", nullable = false, length = 50)
|
||||
private String nom;
|
||||
|
||||
@Column(name = "prenom", nullable = false, length = 50)
|
||||
private String prenom;
|
||||
|
||||
@ManyToOne(targetEntity = Adresse.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false) }, foreignKey = @ForeignKey(name = "FKClient895989"))
|
||||
private Adresse adresse;
|
||||
|
||||
@Column(name = "tel", nullable = false, length = 15)
|
||||
private String tel;
|
||||
|
||||
@OneToMany(mappedBy = "client", targetEntity = Reservation.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Reservation> reservation = new HashSet<Reservation>();
|
||||
|
||||
@OneToMany(mappedBy = "client", targetEntity = Ticket.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Ticket> ticket = new HashSet<Ticket>();
|
||||
|
||||
public void setEmail(String value) {
|
||||
this.email = value;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getORMID() {
|
||||
return getEmail();
|
||||
}
|
||||
|
||||
public void setNom(String value) {
|
||||
this.nom = value;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setPrenom(String value) {
|
||||
this.prenom = value;
|
||||
}
|
||||
|
||||
public String getPrenom() {
|
||||
return prenom;
|
||||
}
|
||||
|
||||
public void setTel(String value) {
|
||||
this.tel = value;
|
||||
}
|
||||
|
||||
public String getTel() {
|
||||
return tel;
|
||||
}
|
||||
|
||||
public void setAdresse(Adresse value) {
|
||||
this.adresse = value;
|
||||
}
|
||||
|
||||
public Adresse getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public void setReservation(Set<Reservation> value) {
|
||||
this.reservation = value;
|
||||
}
|
||||
|
||||
public Set<Reservation> getReservations() {
|
||||
return reservation;
|
||||
}
|
||||
|
||||
public void setTicket(Set<Ticket> value) {
|
||||
this.ticket = value;
|
||||
}
|
||||
|
||||
public Set<Ticket> getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(getEmail());
|
||||
}
|
||||
|
||||
@Transient
|
||||
private boolean _saved = false;
|
||||
|
||||
public void onSave() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return _saved;
|
||||
}
|
||||
|
||||
}
|
||||
165
src/main/java/vthedon/uqac/pooa/core/Hebergement.java
Normal file
165
src/main/java/vthedon/uqac/pooa/core/Hebergement.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Hebergement")
|
||||
@IdClass(HebergementPK.class)
|
||||
public class Hebergement implements Serializable {
|
||||
public Hebergement() {
|
||||
}
|
||||
|
||||
public boolean equals(Object aObj) {
|
||||
if (aObj == this)
|
||||
return true;
|
||||
if (!(aObj instanceof Hebergement))
|
||||
return false;
|
||||
Hebergement hebergement = (Hebergement) aObj;
|
||||
if (getAdresse() == null) {
|
||||
if (hebergement.getAdresse() != null)
|
||||
return false;
|
||||
} else if (!getAdresse().equals(hebergement.getAdresse()))
|
||||
return false;
|
||||
if (getTypeHebergement() == null) {
|
||||
if (hebergement.getTypeHebergement() != null)
|
||||
return false;
|
||||
} else if (!getTypeHebergement().equals(hebergement.getIdTypeHebergement()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashcode = 0;
|
||||
if (getAdresse() != null) {
|
||||
hashcode = hashcode + (int) getAdresse().getORMID();
|
||||
}
|
||||
if (getTypeHebergement() != null) {
|
||||
hashcode = hashcode + (int) getTypeHebergement().getORMID();
|
||||
}
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@PrimaryKeyJoinColumn
|
||||
@ManyToOne(targetEntity = Adresse.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false) }, foreignKey = @ForeignKey(name = "FKHebergemen383161"))
|
||||
private Adresse adresse;
|
||||
|
||||
@Column(name = "idAdresse", nullable = false, insertable = false, updatable = false)
|
||||
@Id
|
||||
@GeneratedValue(generator = "HEBERGEMENT_IDADRESSEID_GENERATOR")
|
||||
@GenericGenerator(name = "HEBERGEMENT_IDADRESSEID_GENERATOR", strategy = "foreign", parameters = @Parameter(name = "property", value = "idAdresse"))
|
||||
private int idAdresse;
|
||||
|
||||
public int getIdAdresse() {
|
||||
return idAdresse;
|
||||
}
|
||||
|
||||
@PrimaryKeyJoinColumn
|
||||
@ManyToOne(targetEntity = TypeHebergement.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idTypeHebergement", referencedColumnName = "idTypeHebergement", nullable = false) }, foreignKey = @ForeignKey(name = "FKHebergemen305581"))
|
||||
private TypeHebergement typeHebergement;
|
||||
|
||||
@Column(name = "idTypeHebergement", nullable = false, insertable = false, updatable = false)
|
||||
@Id
|
||||
@GeneratedValue(generator = "HEBERGEMENT_IDTYPEHEBERGEMENTID_GENERATOR")
|
||||
@GenericGenerator(name = "HEBERGEMENT_IDTYPEHEBERGEMENTID_GENERATOR", strategy = "foreign", parameters = @Parameter(name = "property", value = "idTypeHebergement"))
|
||||
private int idTypeHebergement;
|
||||
|
||||
public int getIdTypeHebergement() {
|
||||
return idTypeHebergement;
|
||||
}
|
||||
|
||||
@Column(name = "nom", nullable = false, length = 120)
|
||||
private String nom;
|
||||
|
||||
@OneToMany(mappedBy = "hebergement", targetEntity = Chambres.class)
|
||||
@Cascade({ CascadeType.ALL})
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Chambres> chambres = new HashSet<Chambres>();
|
||||
|
||||
public void setNom(String value) {
|
||||
this.nom = value;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setTypeHebergement(TypeHebergement value) {
|
||||
this.typeHebergement = value;
|
||||
}
|
||||
|
||||
public TypeHebergement getTypeHebergement() {
|
||||
return typeHebergement;
|
||||
}
|
||||
|
||||
public void setAdresse(Adresse value) {
|
||||
this.adresse = value;
|
||||
}
|
||||
|
||||
public Adresse getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public void setChambres(Set<Chambres> value) {
|
||||
this.chambres = value;
|
||||
}
|
||||
|
||||
public Set<Chambres> getChambres() {
|
||||
return chambres;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String toString = "";
|
||||
toString += "--- " + this.nom + " ---\n";
|
||||
toString += "\t" + this.typeHebergement.toString() + "\n";
|
||||
toString += "\t" + this.adresse.toStringReduce();
|
||||
return toString;
|
||||
}
|
||||
|
||||
@Transient
|
||||
private boolean _saved = false;
|
||||
|
||||
public void onSave() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return _saved;
|
||||
}
|
||||
|
||||
}
|
||||
72
src/main/java/vthedon/uqac/pooa/core/HebergementPK.java
Normal file
72
src/main/java/vthedon/uqac/pooa/core/HebergementPK.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
|
||||
@Embeddable
|
||||
public class HebergementPK implements Serializable {
|
||||
public boolean equals(Object aObj) {
|
||||
if (aObj == this)
|
||||
return true;
|
||||
if (!(aObj instanceof HebergementPK))
|
||||
return false;
|
||||
HebergementPK hebergementpk = (HebergementPK) aObj;
|
||||
if (getIdAdresse() == null) {
|
||||
if (hebergementpk.getIdAdresse() != null)
|
||||
return false;
|
||||
} else if (!getIdAdresse().equals(hebergementpk.getIdAdresse()))
|
||||
return false;
|
||||
if (getIdTypeHebergement() == null) {
|
||||
if (hebergementpk.getIdTypeHebergement() != null)
|
||||
return false;
|
||||
} else if (!getIdTypeHebergement().equals(hebergementpk.getIdTypeHebergement()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashcode = 0;
|
||||
if (getIdAdresse() != null) {
|
||||
hashcode = hashcode + (int) getIdAdresse().getORMID();
|
||||
}
|
||||
if (getIdTypeHebergement() != null) {
|
||||
hashcode = hashcode + (int) getIdTypeHebergement().getORMID();
|
||||
}
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@ManyToOne(targetEntity = Adresse.class, fetch = FetchType.LAZY)
|
||||
@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false) }, foreignKey = @ForeignKey(name = "FKHebergemen383161"))
|
||||
private Adresse adresse;
|
||||
|
||||
public void setIdAdresse(Adresse value) {
|
||||
this.adresse = value;
|
||||
}
|
||||
|
||||
public Adresse getIdAdresse() {
|
||||
return this.adresse;
|
||||
}
|
||||
|
||||
@ManyToOne(targetEntity = TypeHebergement.class, fetch = FetchType.LAZY)
|
||||
@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idTypeHebergement", referencedColumnName = "idTypeHebergement", nullable = false) }, foreignKey = @ForeignKey(name = "FKHebergemen305581"))
|
||||
private TypeHebergement typeHebergement;
|
||||
|
||||
public void setIdTypeHebergement(TypeHebergement value) {
|
||||
this.typeHebergement = value;
|
||||
}
|
||||
|
||||
public TypeHebergement getIdTypeHebergement() {
|
||||
return this.typeHebergement;
|
||||
}
|
||||
|
||||
}
|
||||
103
src/main/java/vthedon/uqac/pooa/core/Reservation.java
Normal file
103
src/main/java/vthedon/uqac/pooa/core/Reservation.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Reservation")
|
||||
public class Reservation implements Serializable {
|
||||
public Reservation() {
|
||||
}
|
||||
|
||||
@Column(name = "idReservation", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "RESERVATION_IDRESERVATION_GENERATOR")
|
||||
@GenericGenerator(name = "RESERVATION_IDRESERVATION_GENERATOR", strategy = "native")
|
||||
private int idReservation;
|
||||
|
||||
@ManyToOne(targetEntity = Client.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "email", referencedColumnName = "email", nullable = false) }, foreignKey = @ForeignKey(name = "FKReservatio821544"))
|
||||
private Client client;
|
||||
|
||||
@ManyToOne(targetEntity = Chambres.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = { @JoinColumn(name = "idTypeChambre", referencedColumnName = "idTypeChambre", nullable = false),
|
||||
@JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false),
|
||||
@JoinColumn(name = "idTypeHebergement", referencedColumnName = "idTypeHebergement", nullable = false) }, foreignKey = @ForeignKey(name = "FKReservatio112505"))
|
||||
private Chambres chambre;
|
||||
|
||||
@Column(name = "dateDepart", nullable = false)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateDepart;
|
||||
|
||||
@Column(name = "dateArrivee", nullable = false)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateArrivee;
|
||||
|
||||
public int getIdReservation() {
|
||||
return idReservation;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdReservation();
|
||||
}
|
||||
|
||||
public void setDateDepart(Date value) {
|
||||
this.dateDepart = value;
|
||||
}
|
||||
|
||||
public Date getDateDepart() {
|
||||
return dateDepart;
|
||||
}
|
||||
|
||||
public void setDateArrivee(Date value) {
|
||||
this.dateArrivee = value;
|
||||
}
|
||||
|
||||
public Date getDateArrivee() {
|
||||
return dateArrivee;
|
||||
}
|
||||
|
||||
public void setClient(Client value) {
|
||||
this.client = value;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setChambre(Chambres value) {
|
||||
this.chambre = value;
|
||||
}
|
||||
|
||||
public Chambres getChambre() {
|
||||
return chambre;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(getIdReservation());
|
||||
}
|
||||
|
||||
}
|
||||
93
src/main/java/vthedon/uqac/pooa/core/Service.java
Normal file
93
src/main/java/vthedon/uqac/pooa/core/Service.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Service")
|
||||
public class Service implements Serializable {
|
||||
public Service() {
|
||||
}
|
||||
|
||||
@Column(name = "idService", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "SERVICE_IDSERVICE_GENERATOR")
|
||||
@GenericGenerator(name = "SERVICE_IDSERVICE_GENERATOR", strategy = "native")
|
||||
private int idService;
|
||||
|
||||
@Column(name = "denomination", nullable = false, length = 255)
|
||||
private String denomination;
|
||||
|
||||
@ManyToMany(targetEntity = Chambres.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinTable(name = "Chambres_Service", joinColumns = { @JoinColumn(name = "idService") }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "idTypeChambre"), @JoinColumn(name = "idAdresse"), @JoinColumn(name = "idTypeHebergement") })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Chambres> chambres = new HashSet<Chambres>();
|
||||
|
||||
@ManyToMany(targetEntity = Ticket.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinTable(name = "Ticket_Service", joinColumns = { @JoinColumn(name = "idService") }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "idTicket") })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Ticket> tickets = new HashSet<Ticket>();
|
||||
|
||||
public int getIdService() {
|
||||
return idService;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdService();
|
||||
}
|
||||
|
||||
public void setDenomination(String value) {
|
||||
this.denomination = value;
|
||||
}
|
||||
|
||||
public String getDenomination() {
|
||||
return denomination;
|
||||
}
|
||||
|
||||
public void setChambres(Set<Chambres> value) {
|
||||
this.chambres = value;
|
||||
}
|
||||
|
||||
public Set<Chambres> getChambres() {
|
||||
return this.chambres;
|
||||
}
|
||||
|
||||
public void setTickets(Set<Ticket> value) {
|
||||
this.tickets = value;
|
||||
}
|
||||
|
||||
public Set<Ticket> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public boolean addChambres(Chambres chambres) {
|
||||
return this.chambres.add(chambres);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getDenomination();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
public interface SystemeGestionReservations {
|
||||
|
||||
public boolean enregistrerRenseignementsClient(Client client);
|
||||
|
||||
public boolean enregistrerRenseignementsHebergement(Hebergement hebergement);
|
||||
|
||||
public Reservation reserver(Chambres chambres, Ticket ticket);
|
||||
|
||||
public boolean annulerReservation(Client client);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import vthedon.uqac.pooa.ui.UI;
|
||||
|
||||
public class SystemeGestionReservationsImpl implements SystemeGestionReservations {
|
||||
|
||||
private EntityManager em;
|
||||
private UI ui;
|
||||
|
||||
public void start() {
|
||||
|
||||
int choix = -1;
|
||||
while (choix != 0) {
|
||||
ui.printMenu();
|
||||
choix = UI.readInt("-> ");
|
||||
switch (choix) {
|
||||
case 1:
|
||||
enregistrerRenseignementsClient(ui.formClient());
|
||||
break;
|
||||
case 2:
|
||||
enregistrerRenseignementsHebergement(ui.formHebergement());
|
||||
break;
|
||||
case 3:
|
||||
rechercher(getClientByMail());
|
||||
break;
|
||||
case 4:
|
||||
gererTickets(loadTickets(getClientByMail()));
|
||||
break;
|
||||
case 5:
|
||||
annulerReservation(getClientByMail());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<TypeChambre> loadTypeChambres() {
|
||||
return em.createNativeQuery("SELECT * FROM typeChambre", TypeChambre.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
private List<TypeHebergement> loadTypeHebergements() {
|
||||
return em
|
||||
.createNativeQuery("SELECT * FROM typeHebergement", TypeHebergement.class).getResultList();
|
||||
}
|
||||
|
||||
private List<Service> loadServices() {
|
||||
return em.createNativeQuery("SELECT * FROM service", Service.class).getResultList();
|
||||
}
|
||||
|
||||
private List<Ticket> loadTickets(Client client) {
|
||||
return em.createNativeQuery("SELECT * FROM ticket", Ticket.class).getResultList();
|
||||
}
|
||||
|
||||
public SystemeGestionReservationsImpl(EntityManagerFactory emf) {
|
||||
this.em = emf.createEntityManager();
|
||||
this.ui = new UI(loadTypeChambres(), loadTypeHebergements(), loadServices());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enregistrerRenseignementsClient(Client client) {
|
||||
this.em.getTransaction().begin();
|
||||
this.em.persist(client);
|
||||
this.em.getTransaction().commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enregistrerRenseignementsHebergement(Hebergement hebergement) {
|
||||
this.em.getTransaction().begin();
|
||||
this.em.persist(hebergement);
|
||||
this.em.getTransaction().commit();
|
||||
this.ui.setServices(loadServices());
|
||||
return true;
|
||||
}
|
||||
|
||||
public Ticket rechercher(Client client) {
|
||||
Ticket ticket = ui.formTicket(client);
|
||||
this.em.getTransaction().begin();
|
||||
this.em.persist(ticket);
|
||||
this.em.getTransaction().commit();
|
||||
|
||||
for (Chambres c : resultatsRecherche(ticket)) {
|
||||
System.out.println(c.getHebergement().toString());
|
||||
System.out.println(c.toString());
|
||||
System.out.println();
|
||||
}
|
||||
return ticket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean annulerReservation(Client client) {
|
||||
List<Reservation> reservations = new ArrayList<Reservation>();
|
||||
reservations.addAll(client.getReservations());
|
||||
Reservation res = ui.choixReservation(reservations);
|
||||
|
||||
if (res != null) {
|
||||
em.getTransaction().begin();
|
||||
Query query = em.createQuery("DELETE FROM Reservation r WHERE idReservation = :idReservation ");
|
||||
query.setParameter("idReservation", res.getIdReservation());
|
||||
int ret = query.executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
return ret > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Reservation gererTickets(List<Ticket> tickets) {
|
||||
Ticket ticket = ui.choixTicket(tickets);
|
||||
|
||||
Chambres toReserve = ui.choixChambres(resultatsRecherche(ticket));
|
||||
|
||||
reserver(toReserve, ticket);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Client getClientByMail() {
|
||||
return (Client) em.createNativeQuery("SELECT * FROM client WHERE email LIKE ?", Client.class)
|
||||
.setParameter(1, ui.identifierClient())
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
private List<Chambres> resultatsRecherche(Ticket ticket) {
|
||||
ArrayList<Integer> servicesIds = new ArrayList<Integer>();
|
||||
for (Service s : ticket.getServices())
|
||||
servicesIds.add(s.getIdService());
|
||||
|
||||
String queryString = "SELECT DISTINCT c FROM Chambres c JOIN c.services s WHERE ";
|
||||
queryString += "c NOT IN (SELECT c from Chambres c JOIN c.reservations r WHERE r.dateArrivee BETWEEN :dateArrivee AND :dateDepart OR r.dateDepart BETWEEN :dateArrivee AND :dateDepart OR r.dateArrivee > :dateArrivee AND r.dateDepart < :dateDepart ) ";
|
||||
queryString += ((ticket.getPrixMin() == null) ? "" : "AND c.prixNuit >= :prixMin ");
|
||||
queryString += ((ticket.getPrixMax() == null) ? "" : "AND c.prixNuit <= :prixMax ");
|
||||
queryString += ((servicesIds.size() == 0) ? "" : "AND s.idService IN :servicesIds ");
|
||||
queryString += ((ticket.getTypeChambres() == null) ? "" : "AND c.typeChambre IN :typeChambres ");
|
||||
queryString += ((ticket.getTypeHebergements() == null) ? ""
|
||||
: "AND c.hebergement.typeHebergement IN :typeHebergements ");
|
||||
queryString += ((ticket.getAdresse().getRue().equals("")) ? "" : "AND c.hebergement.adresse.rue LIKE :rue ");
|
||||
queryString += ((ticket.getAdresse().getCodePostal().equals("")) ? ""
|
||||
: "AND c.hebergement.adresse.codePostal LIKE :codePostal ");
|
||||
queryString += ((ticket.getAdresse().getVille().equals("")) ? "" : "AND c.hebergement.adresse.ville LIKE :ville ");
|
||||
queryString += ((ticket.getAdresse().getProvince().equals("")) ? ""
|
||||
: "AND c.hebergement.adresse.province LIKE :province ");
|
||||
queryString += ((ticket.getAdresse().getPays().equals("")) ? "" : "AND c.hebergement.adresse.pays LIKE :pays ");
|
||||
queryString += "GROUP BY c ";
|
||||
queryString += "HAVING count(c) = 3";
|
||||
|
||||
Query query = em.createQuery(queryString);
|
||||
|
||||
query.setParameter("dateArrivee", ticket.getDateArrivee());
|
||||
query.setParameter("dateDepart", ticket.getDateDepart());
|
||||
|
||||
if (ticket.getPrixMin() != null)
|
||||
query.setParameter("prixMin", ticket.getPrixMin());
|
||||
if (ticket.getPrixMax() != null)
|
||||
query.setParameter("prixMax", ticket.getPrixMax());
|
||||
if (servicesIds.size() != 0)
|
||||
query.setParameter("servicesIds", servicesIds);
|
||||
if (ticket.getTypeChambres() != null)
|
||||
query.setParameter("typeChambres", ticket.getTypeChambres());
|
||||
if (ticket.getTypeHebergements() != null)
|
||||
query.setParameter("typeHebergements", ticket.getTypeHebergements());
|
||||
if (!ticket.getAdresse().getRue().equals(""))
|
||||
query.setParameter("rue", ticket.getAdresse().getRue());
|
||||
if (!ticket.getAdresse().getCodePostal().equals(""))
|
||||
query.setParameter("codePostal", ticket.getAdresse().getCodePostal());
|
||||
if (!ticket.getAdresse().getVille().equals(""))
|
||||
query.setParameter("ville", ticket.getAdresse().getVille());
|
||||
if (!ticket.getAdresse().getProvince().equals(""))
|
||||
query.setParameter("province", ticket.getAdresse().getProvince());
|
||||
if (!ticket.getAdresse().getPays().equals(""))
|
||||
query.setParameter("pays", ticket.getAdresse().getPays());
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reservation reserver(Chambres chambres, Ticket ticket) {
|
||||
Reservation res = new Reservation();
|
||||
res.setDateArrivee(ticket.getDateArrivee());
|
||||
res.setDateDepart(ticket.getDateDepart());
|
||||
res.setClient(ticket.getClient());
|
||||
res.setChambre(chambres);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(res);
|
||||
Query query = em.createQuery("DELETE FROM Ticket r WHERE idTicket = :idTicket ");
|
||||
query.setParameter("idTicket", ticket.getIdTicket());
|
||||
query.executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
197
src/main/java/vthedon/uqac/pooa/core/Ticket.java
Normal file
197
src/main/java/vthedon/uqac/pooa/core/Ticket.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
import net.bytebuddy.implementation.ToStringMethod;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "Ticket")
|
||||
public class Ticket implements Serializable {
|
||||
public Ticket() {
|
||||
}
|
||||
|
||||
@Column(name = "idTicket", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "TICKET_IDTICKET_GENERATOR")
|
||||
@GenericGenerator(name = "TICKET_IDTICKET_GENERATOR", strategy = "native")
|
||||
private int idTicket;
|
||||
|
||||
@ManyToOne(targetEntity = Client.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "email", referencedColumnName = "email", nullable = false) }, foreignKey = @ForeignKey(name = "FKTicket267767"))
|
||||
private Client client;
|
||||
|
||||
@ManyToOne(targetEntity = Adresse.class, fetch = FetchType.LAZY)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "idAdresse", referencedColumnName = "idAdresse", nullable = false) }, foreignKey = @ForeignKey(name = "FKTicket143761"))
|
||||
private Adresse adresse;
|
||||
|
||||
@Column(name = "dateArrivee", nullable = true)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateArrivee;
|
||||
|
||||
@Column(name = "dateDepart", nullable = true)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateDepart;
|
||||
|
||||
@Column(name = "prixMin", nullable = true, precision = 5, scale = 2)
|
||||
private java.math.BigDecimal prixMin;
|
||||
|
||||
@Column(name = "prixMax", nullable = true, precision = 5, scale = 2)
|
||||
private java.math.BigDecimal prixMax;
|
||||
|
||||
@ManyToMany(targetEntity = TypeHebergement.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinTable(name = "TypeHebergement_Ticket", joinColumns = { @JoinColumn(name = "idTicket") }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "idTypeHebergement") })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<TypeHebergement> typeHebergements = new HashSet<TypeHebergement>();
|
||||
|
||||
@ManyToMany(targetEntity = TypeChambre.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@JoinTable(name = "TypeChambre_Ticket", joinColumns = { @JoinColumn(name = "idTicket") }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "idTypeChambre") })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<TypeChambre> typeChambres = new HashSet<TypeChambre>();
|
||||
|
||||
@ManyToMany(mappedBy = "tickets", targetEntity = Service.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Service> services = new HashSet<Service>();
|
||||
|
||||
public int getIdTicket() {
|
||||
return idTicket;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdTicket();
|
||||
}
|
||||
|
||||
public void setDateArrivee(Date value) {
|
||||
this.dateArrivee = value;
|
||||
}
|
||||
|
||||
public Date getDateArrivee() {
|
||||
return dateArrivee;
|
||||
}
|
||||
|
||||
public void setDateDepart(Date value) {
|
||||
this.dateDepart = value;
|
||||
}
|
||||
|
||||
public Date getDateDepart() {
|
||||
return dateDepart;
|
||||
}
|
||||
|
||||
public void setPrixMin(java.math.BigDecimal value) {
|
||||
this.prixMin = value;
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getPrixMin() {
|
||||
return prixMin;
|
||||
}
|
||||
|
||||
public void setPrixMax(java.math.BigDecimal value) {
|
||||
this.prixMax = value;
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getPrixMax() {
|
||||
return prixMax;
|
||||
}
|
||||
|
||||
public void setTypeHebergements(Set<TypeHebergement> value) {
|
||||
this.typeHebergements = value;
|
||||
}
|
||||
|
||||
public Set<TypeHebergement> getTypeHebergements() {
|
||||
return typeHebergements;
|
||||
}
|
||||
|
||||
public void setTypeChambres(Set<TypeChambre> value) {
|
||||
this.typeChambres = value;
|
||||
}
|
||||
|
||||
public Set<TypeChambre> getTypeChambres() {
|
||||
return typeChambres;
|
||||
}
|
||||
|
||||
public void setAdresse(Adresse value) {
|
||||
this.adresse = value;
|
||||
}
|
||||
|
||||
public Adresse getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public void setClient(Client value) {
|
||||
this.client = value;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setServices(Set<Service> value) {
|
||||
this.services = value;
|
||||
}
|
||||
|
||||
public Set<Service> getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String toString = "";
|
||||
toString += "-------- Ticket " + this.idTicket + " --------" + "\n";
|
||||
toString += "client : " + client.getEmail() + "\n\n";
|
||||
toString += "Type d'hebergement : ";
|
||||
for(TypeHebergement th : this.typeHebergements){
|
||||
toString += th.toString() + ", ";
|
||||
}
|
||||
toString += "\b\n";
|
||||
toString += "Type de chambres : ";
|
||||
for(TypeChambre tc : this.typeChambres){
|
||||
toString += tc.toString() + ", ";
|
||||
}
|
||||
toString += "\b\n\n";
|
||||
toString += "Prix min : " + this.prixMin + "\n";
|
||||
toString += "Prix Max : " + this.prixMax + "\n";
|
||||
toString += "Date d'arrivée : " + this.dateArrivee.toString() + "\n";
|
||||
toString += "Date de départ : " + this.dateDepart.toString() + "\n\n";
|
||||
toString += "Localisation : \n" + this.adresse.toString() + "\n\n";
|
||||
toString += "Service : ";
|
||||
for(Service s : this.services){
|
||||
toString += s.toString() + ", ";
|
||||
}
|
||||
toString += "\b\n\n";
|
||||
return toString;
|
||||
}
|
||||
|
||||
}
|
||||
98
src/main/java/vthedon/uqac/pooa/core/TypeChambre.java
Normal file
98
src/main/java/vthedon/uqac/pooa/core/TypeChambre.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "TypeChambre")
|
||||
public class TypeChambre implements Serializable, Comparable<TypeChambre> {
|
||||
public TypeChambre() {
|
||||
}
|
||||
|
||||
@Column(name = "idTypeChambre", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "TYPECHAMBRE_IDTYPECHAMBRE_GENERATOR")
|
||||
@GenericGenerator(name = "TYPECHAMBRE_IDTYPECHAMBRE_GENERATOR", strategy = "native")
|
||||
private int idTypeChambre;
|
||||
|
||||
@Column(name = "denomination", nullable = false, length = 50)
|
||||
private String denomination;
|
||||
|
||||
@ManyToMany(mappedBy = "typeChambres", targetEntity = Ticket.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Ticket> tickets = new HashSet<Ticket>();
|
||||
|
||||
@OneToMany(mappedBy = "idTypeChambre", targetEntity = Chambres.class)
|
||||
@Cascade({ CascadeType.ALL})
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Chambres> chambres = new HashSet<Chambres>();
|
||||
|
||||
public int getIdTypeChambre() {
|
||||
return idTypeChambre;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdTypeChambre();
|
||||
}
|
||||
|
||||
public void setDenomination(String value) {
|
||||
this.denomination = value;
|
||||
}
|
||||
|
||||
public String getDenomination() {
|
||||
return denomination;
|
||||
}
|
||||
|
||||
public void setTickets(Set<Ticket> value) {
|
||||
this.tickets = value;
|
||||
}
|
||||
|
||||
public Set<Ticket> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setChambres(Set<Chambres> value) {
|
||||
this.chambres = value;
|
||||
}
|
||||
|
||||
public Set<Chambres> getChambres() {
|
||||
return chambres;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getDenomination();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TypeChambre) {
|
||||
return denomination.equals(((TypeChambre) obj).getDenomination());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeChambre arg0) {
|
||||
return this.idTypeChambre - arg0.idTypeChambre;
|
||||
}
|
||||
}
|
||||
89
src/main/java/vthedon/uqac/pooa/core/TypeHebergement.java
Normal file
89
src/main/java/vthedon/uqac/pooa/core/TypeHebergement.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package vthedon.uqac.pooa.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
|
||||
@Entity
|
||||
@Proxy(lazy = false)
|
||||
@Table(name = "TypeHebergement")
|
||||
public class TypeHebergement implements Serializable, Comparable<TypeHebergement> {
|
||||
public TypeHebergement() {
|
||||
}
|
||||
|
||||
@Column(name = "idTypeHebergement", nullable = false, length = 10)
|
||||
@Id
|
||||
@GeneratedValue(generator = "TYPEHEBERGEMENT_IDTYPEHEBERGEMENT_GENERATOR")
|
||||
@GenericGenerator(name = "TYPEHEBERGEMENT_IDTYPEHEBERGEMENT_GENERATOR", strategy = "native")
|
||||
private int idTypeHebergement;
|
||||
|
||||
@Column(name = "denomination", nullable = false, length = 30)
|
||||
private String denomination;
|
||||
|
||||
@ManyToMany(mappedBy = "typeHebergements", targetEntity = Ticket.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Ticket> tickets = new HashSet<Ticket>();
|
||||
|
||||
@OneToMany(mappedBy = "idTypeHebergement", targetEntity = Hebergement.class)
|
||||
@Cascade({ CascadeType.ALL })
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private Set<Hebergement> hebergement = new HashSet<Hebergement>();
|
||||
|
||||
public int getIdTypeHebergement() {
|
||||
return idTypeHebergement;
|
||||
}
|
||||
|
||||
public int getORMID() {
|
||||
return getIdTypeHebergement();
|
||||
}
|
||||
|
||||
public void setDenomination(String value) {
|
||||
this.denomination = value;
|
||||
}
|
||||
|
||||
public String getDenomination() {
|
||||
return denomination;
|
||||
}
|
||||
|
||||
public void setIdTicket(Set<Ticket> value) {
|
||||
this.tickets = value;
|
||||
}
|
||||
|
||||
public Set<Ticket> getIdTicket() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setHebergement(Set<Hebergement> value) {
|
||||
this.hebergement = value;
|
||||
}
|
||||
|
||||
public Set<Hebergement> getHebergement() {
|
||||
return hebergement;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getDenomination();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeHebergement arg0) {
|
||||
return this.idTypeHebergement - arg0.idTypeHebergement;
|
||||
}
|
||||
|
||||
}
|
||||
415
src/main/java/vthedon/uqac/pooa/ui/UI.java
Normal file
415
src/main/java/vthedon/uqac/pooa/ui/UI.java
Normal file
@@ -0,0 +1,415 @@
|
||||
package vthedon.uqac.pooa.ui;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import vthedon.uqac.pooa.core.Adresse;
|
||||
import vthedon.uqac.pooa.core.Chambres;
|
||||
import vthedon.uqac.pooa.core.Client;
|
||||
import vthedon.uqac.pooa.core.Hebergement;
|
||||
import vthedon.uqac.pooa.core.Reservation;
|
||||
import vthedon.uqac.pooa.core.Service;
|
||||
import vthedon.uqac.pooa.core.Ticket;
|
||||
import vthedon.uqac.pooa.core.TypeChambre;
|
||||
import vthedon.uqac.pooa.core.TypeHebergement;
|
||||
|
||||
public class UI {
|
||||
|
||||
public static final int MAX_COLUMN = 72;
|
||||
|
||||
private List<TypeChambre> typeChambres;
|
||||
private List<TypeHebergement> typeHebergements;
|
||||
private List<Service> services;
|
||||
|
||||
public UI(List<TypeChambre> typeChambres, List<TypeHebergement> typeHebergements, List<Service> services) {
|
||||
this.typeHebergements = typeHebergements;
|
||||
this.typeChambres = typeChambres;
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public List<TypeChambre> getTypeChambres() {
|
||||
return this.typeChambres;
|
||||
}
|
||||
|
||||
public void setTypeChambres(List<TypeChambre> typeChambres) {
|
||||
this.typeChambres = typeChambres;
|
||||
}
|
||||
|
||||
public List<TypeHebergement> getTypeHebergements() {
|
||||
return this.typeHebergements;
|
||||
}
|
||||
|
||||
public void setTypeHebergements(List<TypeHebergement> typeHebergements) {
|
||||
this.typeHebergements = typeHebergements;
|
||||
}
|
||||
|
||||
public List<Service> getServices() {
|
||||
return this.services;
|
||||
}
|
||||
|
||||
public void setServices(List<Service> services) {
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public static int readInt(String beforeReadText) {
|
||||
while (true) {
|
||||
try {
|
||||
return Integer.parseInt(readString(beforeReadText));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Date readDate(String beforeReadText) {
|
||||
while (true) {
|
||||
try {
|
||||
System.out.println(beforeReadText);
|
||||
Calendar.getInstance().set(readInt("Année : "), readInt("Mois : "),
|
||||
readInt("Jour :"));
|
||||
return Calendar.getInstance().getTime();
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean readBoolean(String beforeReadText) {
|
||||
return readString(beforeReadText + "(y/n) ").charAt(0) == 'y';
|
||||
}
|
||||
|
||||
public static BigDecimal readBigDecimal(String beforeReadText) {
|
||||
while (true) {
|
||||
try {
|
||||
return BigDecimal.valueOf(Double.parseDouble(readString(beforeReadText)));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String readString() throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine();
|
||||
}
|
||||
|
||||
public static String readString(String beforeReadText) {
|
||||
while (true) {
|
||||
System.out.print(beforeReadText);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void printAppName() {
|
||||
println(" _____ ______ _____ _ _ ____ _______ ______ _ ");
|
||||
println(" | __ \\ | ____| / ____| | | | | / __ \\ |__ __| | ____| | | ");
|
||||
println(" | |__) | | |__ | (___ | |__| | | | | | | | | |__ | | ");
|
||||
println(" | _ / | __| \\___ \\ | __ | | | | | | | | __| | | ");
|
||||
println(" | | \\ \\ | |____ ____) | | | | | | |__| | | | | |____ | |____ ");
|
||||
println(" |_| \\_\\ |______| |_____/ |_| |_| \\____/ |_| |______| |______|");
|
||||
}
|
||||
|
||||
public void printMenu() {
|
||||
clearScreen();
|
||||
printAppName();
|
||||
jumpLine();
|
||||
jumpLine();
|
||||
printCenter("MENU", '*', '*');
|
||||
jumpLine();
|
||||
println("1 - Enregistrer un client");
|
||||
println("2 - Enregistrer un hébergement");
|
||||
println("3 - Effectuer une recherche");
|
||||
println("4 - Gerer un ticket");
|
||||
println("5 - Gerer une reservation");
|
||||
println("0 - Quitter");
|
||||
}
|
||||
|
||||
public Adresse formAdresse() {
|
||||
Adresse adresse = new Adresse();
|
||||
printCenter("Adresse", '-', '-');
|
||||
adresse.setRue(readString("Rue : "));
|
||||
adresse.setCodePostal(readString("Code postal : "));
|
||||
adresse.setVille(readString("Ville : "));
|
||||
adresse.setProvince(readString("Province : "));
|
||||
adresse.setPays(readString("Pays : "));
|
||||
jumpLine();
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public Client formClient() {
|
||||
Client client = new Client();
|
||||
printCenter("Informations Générales", '-', '-');
|
||||
client.setNom(readString("Nom : "));
|
||||
client.setPrenom(readString("Prénom : "));
|
||||
client.setEmail(readString("Email : "));
|
||||
client.setTel(readString("Téléphone : "));
|
||||
jumpLine();
|
||||
client.setAdresse(formAdresse());
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public Hebergement formHebergement() {
|
||||
Hebergement hebergement = new Hebergement();
|
||||
printCenter("Informations Générales", '-', '-');
|
||||
hebergement.setNom(readString("Nom de l'etablissement : "));
|
||||
hebergement.setAdresse(formAdresse());
|
||||
hebergement.setTypeHebergement(choixTypeHebergement());
|
||||
jumpLine();
|
||||
while (readBoolean("Voulez vous ajouter un type de chambre à votre etablissement ? ")) {
|
||||
hebergement.getChambres().add(formChambre(hebergement));
|
||||
jumpLine();
|
||||
}
|
||||
return hebergement;
|
||||
}
|
||||
|
||||
public Set<Service> formServices(boolean canAdd) {
|
||||
return formServices(null, canAdd);
|
||||
}
|
||||
|
||||
public Set<Service> formServices(Chambres chambres, boolean canAdd) {
|
||||
printCenter("Services", '-', '-');
|
||||
String phrase;
|
||||
if (canAdd)
|
||||
phrase = "Selectionnez ou insérer votre service (q pour quitter) : ";
|
||||
else
|
||||
phrase = "Selectionnez vos services : ";
|
||||
|
||||
Set<Service> services = new HashSet<Service>();
|
||||
println("Services : ");
|
||||
for (int i = 0; i < this.services.size(); i++) {
|
||||
println(i + " - " + this.services.get(i).getDenomination());
|
||||
}
|
||||
jumpLine();
|
||||
jumpLine();
|
||||
for (Service service : services) {
|
||||
print(service.getDenomination() + ", ");
|
||||
}
|
||||
jumpLine();
|
||||
String service = readString(phrase);
|
||||
|
||||
while (!service.equals("q")) {
|
||||
try {
|
||||
int choix = Integer.parseInt(service);
|
||||
if (chambres != null)
|
||||
this.services.get(choix).addChambres(chambres);
|
||||
|
||||
services.add(this.services.get(choix));
|
||||
this.services.remove(this.services.get(choix));
|
||||
|
||||
println("Services : ");
|
||||
for (int i = 0; i < this.services.size(); i++) {
|
||||
println(i + " - " + this.services.get(i).getDenomination());
|
||||
}
|
||||
jumpLine();
|
||||
print("--> ");
|
||||
for (Service serv : services) {
|
||||
print(serv.getDenomination() + ", ");
|
||||
}
|
||||
jumpLine();
|
||||
} catch (NumberFormatException e) {
|
||||
if (canAdd) {
|
||||
Service s = new Service();
|
||||
s.setDenomination(service);
|
||||
if (chambres != null)
|
||||
s.addChambres(chambres);
|
||||
services.add(s);
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
|
||||
service = readString(phrase);
|
||||
|
||||
}
|
||||
|
||||
this.services.addAll(services);
|
||||
return services;
|
||||
}
|
||||
|
||||
public Ticket formTicket(Client client) {
|
||||
printCenter("RECHERCHER UNE LOCATION", '*', '*');
|
||||
printCenter("Localisation", '-', '-');
|
||||
println("Laissez vide les champs non renseignés");
|
||||
Adresse loc = formAdresse();
|
||||
jumpLine();
|
||||
|
||||
printCenter("Type d'Hebergement", '-', '-');
|
||||
println("Laissez vide si aucune spécification");
|
||||
TypeHebergement th = null;
|
||||
try {
|
||||
th = choixTypeHebergement();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
}
|
||||
jumpLine();
|
||||
|
||||
printCenter("Type de Chambre", '-', '-');
|
||||
println("Laissez vide si aucune spécification");
|
||||
TypeChambre tc = null;
|
||||
try {
|
||||
tc = choixTypeChambre();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
}
|
||||
jumpLine();
|
||||
|
||||
printCenter("Date de séjour", '-', '-');
|
||||
Date dArrive = readDate("Date d'arrivée : ");
|
||||
jumpLine();
|
||||
Date dDepart = readDate("Date de départ : ");
|
||||
jumpLine();
|
||||
|
||||
printCenter("Services", '-', '-');
|
||||
List<Service> services = new ArrayList<>();
|
||||
services.addAll(formServices(false));
|
||||
jumpLine();
|
||||
|
||||
Ticket t = new Ticket();
|
||||
t.setAdresse(loc);
|
||||
t.setClient(client);
|
||||
|
||||
HashSet<TypeChambre> setTC = new HashSet<TypeChambre>();
|
||||
setTC.add(tc);
|
||||
t.setTypeChambres(setTC);
|
||||
|
||||
HashSet<TypeHebergement> setTH = new HashSet<TypeHebergement>();
|
||||
setTH.add(th);
|
||||
t.setTypeHebergements(setTH);
|
||||
|
||||
t.setDateArrivee(dArrive);
|
||||
t.setDateDepart(dDepart);
|
||||
jumpLine();
|
||||
|
||||
t.setPrixMin(readBigDecimal("Prix minimum : "));
|
||||
t.setPrixMax(readBigDecimal("Prix maximal : "));
|
||||
jumpLine();
|
||||
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
public Chambres formChambre(Hebergement hebergement) {
|
||||
Chambres chambres = new Chambres();
|
||||
printCenter("Informations Générales", '-', '-');
|
||||
chambres.setTypeChambre(choixTypeChambre());
|
||||
chambres.setNom(readString("Dénomination : "));
|
||||
chambres.setPrixNuit(readBigDecimal("Prix par nuit : "));
|
||||
chambres.setQuantite(readInt("Nombre de chambre de ce type : "));
|
||||
chambres.setHebergement(hebergement);
|
||||
chambres.setServices(formServices(chambres, true));
|
||||
jumpLine();
|
||||
return chambres;
|
||||
|
||||
}
|
||||
|
||||
public String identifierClient() {
|
||||
printCenter("Client", '-', '-');
|
||||
return readString("Email du client : ");
|
||||
}
|
||||
|
||||
private void print(String text) {
|
||||
System.out.print(text);
|
||||
}
|
||||
|
||||
private void println(String text) {
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
private void jumpLine() {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public Ticket choixTicket(List<Ticket> tickets) {
|
||||
println("Tickets : ");
|
||||
String toPrint = "";
|
||||
for (int i = 0; i < tickets.size(); i++) {
|
||||
toPrint += i + " - Ticket " + tickets.get(i).getIdTicket() + " : du " + tickets.get(i).getDateArrivee().toString()
|
||||
+ " au " + tickets.get(i).getDateDepart().toString() + " | " + tickets.get(i).getAdresse().getFirstNotNull()
|
||||
+ " | ";
|
||||
for (TypeHebergement th : tickets.get(i).getTypeHebergements())
|
||||
toPrint += th.toString() + ", ";
|
||||
toPrint += "| ";
|
||||
for (TypeChambre tc : tickets.get(i).getTypeChambres())
|
||||
toPrint += tc.toString() + ", ";
|
||||
toPrint += "| Entre " + tickets.get(i).getPrixMin() + " $ et " + tickets.get(i).getPrixMax();
|
||||
println(toPrint);
|
||||
toPrint = "";
|
||||
}
|
||||
jumpLine();
|
||||
return tickets.get(readInt("Ticket à éditer : "));
|
||||
}
|
||||
|
||||
public Chambres choixChambres(List<Chambres> chambres) {
|
||||
for (int i = 0; i < chambres.size(); i++) {
|
||||
printCenter("OPTION " + i, '#', '#');
|
||||
println(chambres.get(i).getHebergement().toString());
|
||||
println(chambres.get(i).toString());
|
||||
jumpLine();
|
||||
}
|
||||
|
||||
return chambres.get(readInt("Option choisie : "));
|
||||
}
|
||||
|
||||
public Reservation choixReservation(List<Reservation> reservations) {
|
||||
println("Reservations : ");
|
||||
String toPrint = "";
|
||||
for (int i = 0; i < reservations.size(); i++) {
|
||||
toPrint += "\t" + i + " - Réservation " + reservations.get(i).getIdReservation() + " : du "
|
||||
+ reservations.get(i).getDateArrivee().toString() + " au " + reservations.get(i).getDateDepart().toString()
|
||||
+ " | " + reservations.get(i).getChambre().getHebergement().getNom();
|
||||
println(toPrint);
|
||||
toPrint = "";
|
||||
}
|
||||
int val = readInt(toPrint);
|
||||
if(val < reservations.size() && val >= 0)
|
||||
return reservations.get(val);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void printCenter(String text, char left, char right) {
|
||||
int i = 1;
|
||||
while ((MAX_COLUMN - text.length()) / 2 > i) {
|
||||
System.out.print(left);
|
||||
i++;
|
||||
}
|
||||
print(" " + text + " ");
|
||||
i = 1;
|
||||
while ((MAX_COLUMN - text.length()) / 2 > i) {
|
||||
System.out.print(right);
|
||||
i++;
|
||||
}
|
||||
jumpLine();
|
||||
}
|
||||
|
||||
private TypeHebergement choixTypeHebergement() throws IndexOutOfBoundsException {
|
||||
println("Type d'etablissement : ");
|
||||
for (int i = 0; i < typeHebergements.size(); i++) {
|
||||
println("\t" + i + " - " + typeHebergements.get(i).getDenomination());
|
||||
}
|
||||
return typeHebergements.get(readInt("Votre choix : "));
|
||||
}
|
||||
|
||||
private TypeChambre choixTypeChambre() throws IndexOutOfBoundsException {
|
||||
println("Type de chambre : ");
|
||||
for (int i = 0; i < typeChambres.size(); i++) {
|
||||
println("\t" + i + " - " + typeChambres.get(i).getDenomination());
|
||||
}
|
||||
return typeChambres.get(readInt("Votre choix : "));
|
||||
}
|
||||
|
||||
private void clearScreen() {
|
||||
System.out.print("\033[H\033[2J");
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
}
|
||||
30
src/main/resources/META-INF/persistence.xml
Normal file
30
src/main/resources/META-INF/persistence.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="reshotel" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>vthedon.uqac.pooa.core.Adresse</class>
|
||||
<class>vthedon.uqac.pooa.core.Chambres</class>
|
||||
<class>vthedon.uqac.pooa.core.Client</class>
|
||||
<class>vthedon.uqac.pooa.core.Hebergement</class>
|
||||
<class>vthedon.uqac.pooa.core.Reservation</class>
|
||||
<class>vthedon.uqac.pooa.core.Service</class>
|
||||
<class>vthedon.uqac.pooa.core.Ticket</class>
|
||||
<class>vthedon.uqac.pooa.core.Service</class>
|
||||
<class>vthedon.uqac.pooa.core.Ticket</class>
|
||||
<class>vthedon.uqac.pooa.core.TypeChambre</class>
|
||||
<class>vthedon.uqac.pooa.core.TypeHebergement</class>
|
||||
<properties>
|
||||
|
||||
<property name="hibernate.dialect" value="org.sqlite.hibernate.dialect.SQLiteDialect"/>
|
||||
<property name="hibernate.connection.url" value="jdbc:sqlite:src/main/resources/database/reshotel.db"/>
|
||||
<property name="hibernate.connection.driver_class" value="org.sqlite.JDBC"/>
|
||||
<property name="hibernate.connection.username" value=""/>
|
||||
<property name="hibernate.connection.password" value=""/>
|
||||
<property name="hibernate.show_sql" value="false"/>
|
||||
<property name="hibernate.format_sql" value="true"/>
|
||||
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
11
src/main/resources/database/base.sql
Normal file
11
src/main/resources/database/base.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
INSERT INTO Adresse VALUES ( ? ,"241 Rue Morin", "G7H4X8", "Chicoutimi", "Québec", "Canada");
|
||||
INSERT INTO TypeHebergement VALUES
|
||||
( ?, "Hôtel"),
|
||||
( ?, "Motel"),
|
||||
( ?, "Couette et Café");
|
||||
INSERT INTO Hebergement VALUES (1, 1, "Hôtel du Fjord");
|
||||
INSERT INTO TypeChambre VALUES
|
||||
( ?, "Simple"),
|
||||
( ?, "Double"),
|
||||
( ?, "Suite");
|
||||
|
||||
BIN
src/main/resources/database/reshotel.db
Normal file
BIN
src/main/resources/database/reshotel.db
Normal file
Binary file not shown.
11
src/main/resources/database/test.sql
Normal file
11
src/main/resources/database/test.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
INSERT INTO chambres(idTypeChambre,idAdresse, idTypeHebergement, quantite, prixNuit)
|
||||
SELECT TypeChambre.idTypeChambre, Hebergement.idAdresse,TypeHebergement.idTypeHebergement, 10, 110.50
|
||||
FROM Hebergement, TypeChambre, TypeHebergement, Adresse
|
||||
WHERE Adresse.rue LIKE "241 Rue Morin"
|
||||
AND Adresse.codePostal LIKE "G7H4X8"
|
||||
AND Adresse.ville LIKE "Chicoutimi"
|
||||
AND Adresse.province LIKE "Québec"
|
||||
AND Adresse.pays LIKE "Canada"
|
||||
AND TypeChambre.denomination LIKE "Simple"
|
||||
AND TypeHebergement.idTypeHebergement = Hebergement.idTypeHebergement
|
||||
AND Adresse.idAdresse = Hebergement.idAdresse
|
||||
20
src/main/resources/database/test2.sql
Normal file
20
src/main/resources/database/test2.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
select
|
||||
*, count(*)
|
||||
from
|
||||
Chambres chambres0_
|
||||
inner join
|
||||
Chambres_Service services1_
|
||||
on chambres0_.idAdresse=services1_.idTypeChambre
|
||||
and chambres0_.idTypeHebergement=services1_.idAdresse
|
||||
and chambres0_.idTypeChambre=services1_.idTypeHebergement
|
||||
inner join
|
||||
Service service2_
|
||||
on services1_.idService=service2_.idService
|
||||
where chambres0_.prixNuit >= 0
|
||||
and chambres0_.prixNuit <= 3000
|
||||
and services1_.idService IN (1,5,9)
|
||||
and chambres0_.idTypeChambre = 2
|
||||
and chambres0_.idTypeHebergement = 1
|
||||
GROUP BY chambres0_.idAdresse, chambres0_.idTypeHebergement, chambres0_.idTypeChambre
|
||||
HAVING count(*) = 3;
|
||||
|
||||
20
src/test/java/vthedon/uqac/pooa/AppTest.java
Normal file
20
src/test/java/vthedon/uqac/pooa/AppTest.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package vthedon.uqac.pooa;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user