Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. package bean;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.CascadeType;
  6. import javax.persistence.Entity;
  7. import javax.persistence.FetchType;
  8. import javax.persistence.GeneratedValue;
  9. import javax.persistence.GenerationType;
  10. import javax.persistence.Id;
  11. import javax.persistence.OneToMany;
  12. import javax.persistence.Table;
  13. import javax.validation.constraints.Size;
  14.  
  15. import org.hibernate.validator.constraints.NotEmpty;
  16.  
  17. import com.fasterxml.jackson.annotation.JsonManagedReference;
  18.  
  19. @Entity
  20. @Table(name="t_users")
  21. public class User {
  22.    
  23.     /**
  24.      * identifiant de l'utilisateur
  25.      */
  26.     @Id
  27.     @GeneratedValue(strategy=GenerationType.AUTO)
  28.     private Integer id;
  29.        
  30.     /**
  31.      *  Liste des commandes liés à l'utilisateur :
  32.      * 1-n unidirectionnelle
  33.      */
  34.     @OneToMany(mappedBy="user", cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
  35.     @JsonManagedReference
  36.     private List<Order> orders;
  37.    
  38.     /**
  39.      * Adresse mail (unique dans le système)
  40.      */
  41.     @NotEmpty(message="Le mail ne peut pas être vide")
  42.     private String mail = null;
  43.  
  44.     /**
  45.      * Mot de passe
  46.      */
  47.     @NotEmpty(message="Le mot de passe ne peut pas être vide")
  48.     @Size(min=6 , message="Le mot de passe doit avoir au moins 6 caractères")
  49.     private String passwd = null;
  50.  
  51.     /**
  52.      * Nom & prénom
  53.      */
  54.     private String name = null;
  55.    
  56.     /**
  57.      * Adresse de livraison
  58.      */
  59.     private String delivery = null;
  60.    
  61.     /**
  62.      * Adresse de facturation
  63.      */
  64.     private String invoice = null;
  65.    
  66.     /**
  67.      * Constructeur
  68.      */
  69.     public User() {
  70.         this.mail = "";
  71.         this.passwd = "";
  72.         this.name = "";
  73.         this.delivery = "";
  74.         this.invoice = "";
  75.     }
  76.  
  77.     /**
  78.      * Constructeur avec paramètres
  79.      * @param id : identifiant, unique dans le système
  80.      * @param mail : unique dans le système
  81.      * @param passwd : mot de passe, doit faire 8 caractères
  82.      * @param name : nom & prénom
  83.      * @param delivery : adresse de livraison
  84.      * @param invoice : adresse de facturation
  85.      */
  86.     public User(Integer id, String mail, String passwd, String name, String delivery, String invoice) {
  87.         super();
  88.         this.id = id;
  89.         this.mail = mail;
  90.         this.passwd = passwd;
  91.         this.name = name;
  92.         this.delivery = delivery;
  93.         this.invoice = invoice;
  94.     }
  95.  
  96.     // ACCESSEURS
  97.     public String getMail() {
  98.         return mail;
  99.     }
  100.  
  101.  
  102.     public void setMail(String mail) {
  103.         this.mail = mail;
  104.     }
  105.  
  106.  
  107.     public String getPasswd() {
  108.         return passwd;
  109.     }
  110.  
  111.  
  112.     public void setPasswd(String passwd) {
  113.         this.passwd = passwd;
  114.     }
  115.  
  116.  
  117.     public String getName() {
  118.         return name;
  119.     }
  120.  
  121.  
  122.     public void setName(String name) {
  123.         this.name = name;
  124.     }
  125.  
  126.  
  127.     public String getDelivery() {
  128.         return delivery;
  129.     }
  130.  
  131.  
  132.     public void setDelivery(String delivery) {
  133.         this.delivery = delivery;
  134.     }
  135.  
  136.  
  137.     public String getInvoice() {
  138.         return invoice;
  139.     }
  140.  
  141.  
  142.     public void setInvoice(String invoice) {
  143.         this.invoice = invoice;
  144.     }
  145.  
  146.  
  147.     public Integer getId() {
  148.         return id;
  149.     }
  150.    
  151.     public void setId(Integer id) {
  152.         this.id = id;
  153.     }
  154.    
  155.     public List<Order> getOrders() {
  156.         return orders;
  157.     }
  158.  
  159.     public void setOrders(List<Order> orders) {
  160.         this.orders = orders;
  161.     }
  162.  
  163.     public String toString(){
  164.         String str = "------------ USER ---------------\n";
  165.         str += "id      : " + this.id + "\n";
  166.         str += "mail        : " + this.mail + "\n";
  167.         str += "passwd      : " + this.passwd + "\n";
  168.         str += "name        : " + this.name + "\n";
  169.         str += "delivery    : " + this.delivery + "\n";
  170.         str += "invoice     : " + this.invoice + "\n";
  171.         if (this.orders != null)
  172.             str += "nb commande : " + this.orders.size() + "\n";
  173.         str += "----------------------------------\n";
  174.         return str;
  175.     }
  176.    
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement