KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > persistance > bo > Contact


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 /**
14  *
15  * @author ofabre
16  *
17  *
18  */

19 @Entity
20 public class Contact {
21     
22     // Fields
23
private String JavaDoc contactId;
24     
25     private String JavaDoc email;
26     
27     private String JavaDoc firstName;
28     
29     private String JavaDoc lastName;
30     
31     private String JavaDoc phone;
32     
33     // Relations
34
private Address address;
35
36     public Contact() {
37         super();
38         // TODO Auto-generated constructor stub
39
}
40     
41     public Contact(Address address, String JavaDoc email, String JavaDoc firstName, String JavaDoc lastName, String JavaDoc 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 JavaDoc contactId, Address address, String JavaDoc email, String JavaDoc firstName, String JavaDoc lastName, String JavaDoc phone) {
51         super();
52         // TODO Auto-generated constructor stub
53
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     /**
81      *
82      * @return
83      */

84     @Id @GeneratedValue(generator = "system-uuid")
85     @GenericGenerator(name="system-uuid", strategy = "uuid")
86     public String JavaDoc getContactId() {
87         return contactId;
88     }
89
90     public void setContactId(String JavaDoc contactId) {
91         this.contactId = contactId;
92     }
93
94     public String JavaDoc getEmail() {
95         return email;
96     }
97
98     public void setEmail(String JavaDoc email) {
99         this.email = email;
100     }
101
102     public String JavaDoc getFirstName() {
103         return firstName;
104     }
105
106     public void setFirstName(String JavaDoc firstName) {
107         this.firstName = firstName;
108     }
109
110     public String JavaDoc getLastName() {
111         return lastName;
112     }
113
114     public void setLastName(String JavaDoc lastName) {
115         this.lastName = lastName;
116     }
117
118     public String JavaDoc getPhone() {
119         return phone;
120     }
121
122     public void setPhone(String JavaDoc phone) {
123         this.phone = phone;
124     }
125
126     /**
127      * @see java.lang.Object#equals(Object)
128      */

129     public boolean equals(Object JavaDoc 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     /**
142      * @see java.lang.Object#hashCode()
143      */

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     /**
151      * @see java.lang.Object#toString()
152      */

153     public String JavaDoc 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