KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.rentacar.persistance.bo;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import javax.persistence.CascadeType;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratedValue;
9 import javax.persistence.Id;
10 import javax.persistence.JoinColumn;
11 import javax.persistence.OneToMany;
12 import javax.persistence.OneToOne;
13
14 import org.apache.commons.lang.builder.EqualsBuilder;
15 import org.apache.commons.lang.builder.HashCodeBuilder;
16 import org.apache.commons.lang.builder.ToStringBuilder;
17 import org.hibernate.annotations.GenericGenerator;
18
19 /**
20  *
21  * @author ofabre
22  *
23  */

24 @Entity
25 public class Agency {
26
27     // Fields
28
private String JavaDoc agencyId;
29     
30     private String JavaDoc host;
31     
32     private String JavaDoc port;
33     
34     private String JavaDoc warName;
35
36     // Relations
37
private Contact contact;
38
39     private Set JavaDoc<Car> cars;
40
41     public Agency() {
42         super();
43     }
44
45     public Agency(Contact contact, Set JavaDoc<Car> cars) {
46         super();
47         this.contact = contact;
48         this.cars = cars;
49     }
50
51     public Agency(String JavaDoc agencyId, Contact contact, Set JavaDoc<Car> cars) {
52         super();
53         this.agencyId = agencyId;
54         this.contact = contact;
55         this.cars = cars;
56     }
57
58     public Agency(AgencyVO agencyVO) {
59         super();
60         this.agencyId = agencyVO.getAgencyId();
61         this.contact = new Contact(agencyVO.getContact());
62         Set JavaDoc<Car> cars = new HashSet JavaDoc<Car>();
63         for (CarVO car : agencyVO.getCars()) {
64             cars.add(new Car(car));
65         }
66         this.cars = cars;
67         this.host = agencyVO.getHost();
68         this.port = agencyVO.getPort();
69         this.warName = agencyVO.getWarName();
70     }
71
72     @Id
73     @GeneratedValue(generator = "system-uuid")
74     @GenericGenerator(name = "system-uuid", strategy = "uuid")
75     public String JavaDoc getAgencyId() {
76         return agencyId;
77     }
78
79     public void setAgencyId(String JavaDoc agencyId) {
80         this.agencyId = agencyId;
81     }
82
83     @OneToMany(cascade = CascadeType.ALL)
84     @JoinColumn(name = "agency_agencyId")
85     public Set JavaDoc<Car> getCars() {
86         return cars;
87     }
88
89     public void setCars(Set JavaDoc<Car> cars) {
90         this.cars = cars;
91     }
92
93     @OneToOne(cascade = CascadeType.ALL)
94     public Contact getContact() {
95         return contact;
96     }
97
98     public void setContact(Contact contact) {
99         this.contact = contact;
100     }
101
102     public String JavaDoc getHost() {
103         return host;
104     }
105
106     public void setHost(String JavaDoc host) {
107         this.host = host;
108     }
109
110     public String JavaDoc getPort() {
111         return port;
112     }
113
114     public void setPort(String JavaDoc port) {
115         this.port = port;
116     }
117
118     public String JavaDoc getWarName() {
119         return warName;
120     }
121
122     public void setWarName(String JavaDoc warName) {
123         this.warName = warName;
124     }
125     
126     /**
127      * @see java.lang.Object#equals(Object)
128      */

129     public boolean equals(Object JavaDoc object) {
130         if (!(object instanceof Agency)) {
131             return false;
132         }
133         Agency rhs = (Agency) object;
134         return new EqualsBuilder().append(this.contact, rhs.contact).append(
135                 this.cars, rhs.cars).append(this.agencyId, rhs.agencyId)
136                 .append(this.host, rhs.host).append(this.port, rhs.port)
137                 .append(this.warName, rhs.warName).isEquals();
138     }
139
140     /**
141      * @see java.lang.Object#hashCode()
142      */

143     public int hashCode() {
144         return new HashCodeBuilder(1680302177, -561077521).append(this.contact)
145                 .append(this.cars).append(this.agencyId).append(this.host)
146                 .append(this.port).append(this.warName).toHashCode();
147     }
148
149     /**
150      * @see java.lang.Object#toString()
151      */

152     public String JavaDoc toString() {
153         return new ToStringBuilder(this).append("host", this.host).append(
154                 "agencyId", this.agencyId).append("contact", this.contact)
155                 .append("port", this.port).append("cars", this.cars).append(this.warName).toString();
156     }
157
158     
159
160 }
161
Popular Tags