Advertisement
Guest User

EmailContact.java

a guest
Apr 30th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. package com.example.model;
  2.  
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.GenerationType;
  7. import javax.persistence.Id;
  8. import javax.persistence.OneToOne;
  9. import javax.persistence.Table;
  10.  
  11. import org.springframework.beans.factory.annotation.Required;
  12.  
  13. @Entity
  14. @Table(name = "email_contact")
  15. public class EmailContact extends BaseObject {
  16.  
  17.     private static final long serialVersionUID = 6643356695108989062L;
  18.  
  19.     private Long id;
  20.     private Customer customer;
  21.     private String emailAddress;
  22.  
  23.     public EmailContact() {
  24.         super();
  25.     }
  26.  
  27.     public EmailContact(String emailAddress) {
  28.         super();
  29.         this.emailAddress = emailAddress;
  30.     }
  31.  
  32.     @Id
  33.     @GeneratedValue(strategy = GenerationType.AUTO)
  34.     public Long getId() {
  35.         return id;
  36.     }
  37.  
  38.     public void setId(Long id) {
  39.         this.id = id;
  40.     }
  41.  
  42.     @OneToOne
  43.     @Required
  44.     public Customer getCustomer() {
  45.         return customer;
  46.     }
  47.  
  48.     public void setCustomer(Customer customer) {
  49.         if (this.customer != null && !this.customer.equals(customer)) {
  50.             throw new RuntimeException("Invalid state: Customer cannot be changed on an existing EmailContact");
  51.         }
  52.         this.customer = customer;
  53.     }
  54.  
  55.     @Column(name = "email_address", length = 255)
  56.     @Required
  57.     public String getEmailAddress() {
  58.         return emailAddress;
  59.     }
  60.  
  61.     public void setEmailAddress(String emailAddress) {
  62.         this.emailAddress = emailAddress;
  63.     }
  64.  
  65.     @Override
  66.     public int hashCode() {
  67.         final int prime = 31;
  68.         int result = 1;
  69.         result = prime * result + ((customer == null) ? 0 : customer.hashCode());
  70.         result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
  71.         return result;
  72.     }
  73.  
  74.     @Override
  75.     public boolean equals(Object obj) {
  76.         if (this == obj)
  77.             return true;
  78.         if (obj == null)
  79.             return false;
  80.         if (getClass() != obj.getClass())
  81.             return false;
  82.         EmailContact other = (EmailContact) obj;
  83.         if (customer == null) {
  84.             if (other.customer != null)
  85.                 return false;
  86.         } else if (!customer.equals(other.customer))
  87.             return false;
  88.         if (emailAddress == null) {
  89.             if (other.emailAddress != null)
  90.                 return false;
  91.         } else if (!emailAddress.equals(other.emailAddress))
  92.             return false;
  93.         return true;
  94.     }
  95.  
  96.     @Override
  97.     public String toString() {
  98.         return "EmailContact [id=" + (id == null ? "null" : id.toString()) + ", customer=" + (customer==null?"null":customer.getCustomerNumber()) + ", emailAddress=" + emailAddress + "]";
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement