Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 KB | None | 0 0
  1. /**
  2.  * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
  3.  *
  4.  * You may not modify, use, reproduce, or distribute this software except in
  5.  * compliance with  the terms of the License at:
  6.  * http://java.net/projects/javaeetutorial/pages/BerkeleyLicense
  7.  */
  8. /*
  9.  * To change this template, choose Tools | Templates
  10.  * and open the template in the editor.
  11.  */
  12. package javaeetutorial.addressbook.entity;
  13.  
  14. import java.io.Serializable;
  15. import java.util.Date;
  16.  
  17. import javax.persistence.Entity;
  18. import javax.persistence.GeneratedValue;
  19. import javax.persistence.GenerationType;
  20. import javax.persistence.Id;
  21. import javax.persistence.Temporal;
  22. import javax.validation.constraints.NotNull;
  23. import javax.validation.constraints.Past;
  24. import javax.validation.constraints.Pattern;
  25.  
  26. import org.hibernate.annotations.Cache;
  27. import org.hibernate.annotations.CacheConcurrencyStrategy;
  28.  
  29. /**
  30.  *
  31.  * @author ian
  32.  */
  33. @Entity
  34. @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
  35. public class Contact implements Serializable {
  36.  
  37.     private static final long serialVersionUID = -825634229676522580L;
  38.     @Id
  39.     @GeneratedValue(strategy = GenerationType.AUTO)
  40.     private Long id;
  41.     @NotNull
  42.     protected String firstName;
  43.     @NotNull
  44.     protected String lastName;
  45.     @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\."
  46.             + "[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@"
  47.             + "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9]"
  48.             + "(?:[a-z0-9-]*[a-z0-9])?",
  49.             message = "{invalid.email}")
  50.     protected String email;
  51.     @Pattern(regexp = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$",
  52.             message = "{invalid.phonenumber}")
  53.     protected String mobilePhone;
  54.     @Pattern(regexp = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$",
  55.             message = "{invalid.phonenumber}")
  56.     protected String homePhone;
  57.     @Temporal(javax.persistence.TemporalType.DATE)
  58.     @Past
  59.     protected Date birthday;
  60.  
  61.     /**
  62.      * Get the value of birthday
  63.      *
  64.      * @return the value of birthday
  65.      */
  66.     public Date getBirthday() {
  67.         return birthday;
  68.     }
  69.  
  70.     /**
  71.      * Set the value of birthday
  72.      *
  73.      * @param birthday new value of birthday
  74.      */
  75.     public void setBirthday(Date birthday) {
  76.         this.birthday = birthday;
  77.     }
  78.  
  79.     /**
  80.      * Get the value of homePhone
  81.      *
  82.      * @return the value of homePhone
  83.      */
  84.     public String getHomePhone() {
  85.         return homePhone;
  86.     }
  87.  
  88.     /**
  89.      * Set the value of homePhone
  90.      *
  91.      * @param homePhone new value of homePhone
  92.      */
  93.     public void setHomePhone(String homePhone) {
  94.         this.homePhone = homePhone;
  95.     }
  96.  
  97.     /**
  98.      * Get the value of mobilePhone
  99.      *
  100.      * @return the value of mobilePhone
  101.      */
  102.     public String getMobilePhone() {
  103.         return mobilePhone;
  104.     }
  105.  
  106.     /**
  107.      * Set the value of mobilePhone
  108.      *
  109.      * @param mobilePhone new value of mobilePhone
  110.      */
  111.     public void setMobilePhone(String mobilePhone) {
  112.         this.mobilePhone = mobilePhone;
  113.     }
  114.  
  115.     /**
  116.      * Get the value of email
  117.      *
  118.      * @return the value of email
  119.      */
  120.     public String getEmail() {
  121.         return email;
  122.     }
  123.  
  124.     /**
  125.      * Set the value of email
  126.      *
  127.      * @param email new value of email
  128.      */
  129.     public void setEmail(String email) {
  130.         this.email = email;
  131.     }
  132.  
  133.     /**
  134.      * Get the value of lastName
  135.      *
  136.      * @return the value of lastName
  137.      */
  138.     public String getLastName() {
  139.         return lastName;
  140.     }
  141.  
  142.     /**
  143.      * Set the value of lastName
  144.      *
  145.      * @param lastName new value of lastName
  146.      */
  147.     public void setLastName(String lastName) {
  148.         this.lastName = lastName;
  149.     }
  150.  
  151.     /**
  152.      * Get the value of firstName
  153.      *
  154.      * @return the value of firstName
  155.      */
  156.     public String getFirstName() {
  157.         return firstName;
  158.     }
  159.  
  160.     /**
  161.      * Set the value of firstName
  162.      *
  163.      * @param firstName new value of firstName
  164.      */
  165.     public void setFirstName(String firstName) {
  166.         this.firstName = firstName;
  167.     }
  168.  
  169.     public Long getId() {
  170.         return id;
  171.     }
  172.  
  173.     public void setId(Long id) {
  174.         this.id = id;
  175.     }
  176.  
  177.     @Override
  178.     public int hashCode() {
  179.         int hash = 0;
  180.         hash += (id != null ? id.hashCode() : 0);
  181.         return hash;
  182.     }
  183.  
  184.     @Override
  185.     public boolean equals(Object object) {
  186.         // TODO: Warning - this method won't work in the case the id fields are not set
  187.         if (!(object instanceof Contact)) {
  188.             return false;
  189.         }
  190.         Contact other = (Contact) object;
  191.         if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
  192.             return false;
  193.         }
  194.         return true;
  195.     }
  196.  
  197.     @Override
  198.     public String toString() {
  199.         return "addressbook.entity.Contact[id=" + id + "]";
  200.     }
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement