1 package org.objectweb.rentacar.persistance.bo; 2 3 import javax.persistence.CascadeType; 4 import javax.persistence.Entity; 5 import javax.persistence.GeneratedValue; 6 import javax.persistence.Id; 7 import javax.persistence.OneToOne; 8 import org.apache.commons.lang.builder.EqualsBuilder; 9 import org.apache.commons.lang.builder.HashCodeBuilder; 10 import org.apache.commons.lang.builder.ToStringBuilder; 11 import org.hibernate.annotations.GenericGenerator; 12 13 19 @Entity 20 public class Contact { 21 22 private String contactId; 24 25 private String email; 26 27 private String firstName; 28 29 private String lastName; 30 31 private String phone; 32 33 private Address address; 35 36 public Contact() { 37 super(); 38 } 40 41 public Contact(Address address, String email, String firstName, String lastName, String phone) { 42 super(); 43 this.address = address; 44 this.email = email; 45 this.firstName = firstName; 46 this.lastName = lastName; 47 this.phone = phone; 48 } 49 50 public Contact(String contactId, Address address, String email, String firstName, String lastName, String phone) { 51 super(); 52 this.contactId = contactId; 54 this.address = address; 55 this.email = email; 56 this.firstName = firstName; 57 this.lastName = lastName; 58 this.phone = phone; 59 } 60 61 public Contact(ContactVO contactVO) { 62 super(); 63 this.contactId = contactVO.getContactId(); 64 this.address = new Address(contactVO.getAddress()); 65 this.email = contactVO.getEmail(); 66 this.firstName = contactVO.getFirstName(); 67 this.lastName = contactVO.getLastName(); 68 this.phone = contactVO.getPhone(); 69 } 70 71 @OneToOne(cascade=CascadeType.ALL) 72 public Address getAddress() { 73 return address; 74 } 75 76 public void setAddress(Address address) { 77 this.address = address; 78 } 79 80 84 @Id @GeneratedValue(generator = "system-uuid") 85 @GenericGenerator(name="system-uuid", strategy = "uuid") 86 public String getContactId() { 87 return contactId; 88 } 89 90 public void setContactId(String contactId) { 91 this.contactId = contactId; 92 } 93 94 public String getEmail() { 95 return email; 96 } 97 98 public void setEmail(String email) { 99 this.email = email; 100 } 101 102 public String getFirstName() { 103 return firstName; 104 } 105 106 public void setFirstName(String firstName) { 107 this.firstName = firstName; 108 } 109 110 public String getLastName() { 111 return lastName; 112 } 113 114 public void setLastName(String lastName) { 115 this.lastName = lastName; 116 } 117 118 public String getPhone() { 119 return phone; 120 } 121 122 public void setPhone(String phone) { 123 this.phone = phone; 124 } 125 126 129 public boolean equals(Object object) { 130 if (!(object instanceof Contact)) { 131 return false; 132 } 133 Contact rhs = (Contact) object; 134 return new EqualsBuilder().append(this.phone, rhs.phone).append( 135 this.address, rhs.address).append(this.email, rhs.email) 136 .append(this.contactId, rhs.contactId).append(this.firstName, 137 rhs.firstName).append(this.lastName, rhs.lastName) 138 .isEquals(); 139 } 140 141 144 public int hashCode() { 145 return new HashCodeBuilder(-684648355, 551342479).append(this.phone) 146 .append(this.address).append(this.email).append(this.contactId) 147 .append(this.firstName).append(this.lastName).toHashCode(); 148 } 149 150 153 public String toString() { 154 return new ToStringBuilder(this).append("phone", this.phone).append( 155 "lastName", this.lastName).append("email", this.email).append( 156 "contactId", this.contactId).append("address", this.address) 157 .append("firstName", this.firstName).toString(); 158 } 159 160 161 162 } 163 | Popular Tags |