1 package org.objectweb.rentacar.persistance.bo; 2 3 import java.util.HashSet ; 4 import java.util.Set ; 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 24 @Entity 25 public class Agency { 26 27 private String agencyId; 29 30 private String host; 31 32 private String port; 33 34 private String warName; 35 36 private Contact contact; 38 39 private Set <Car> cars; 40 41 public Agency() { 42 super(); 43 } 44 45 public Agency(Contact contact, Set <Car> cars) { 46 super(); 47 this.contact = contact; 48 this.cars = cars; 49 } 50 51 public Agency(String agencyId, Contact contact, Set <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 <Car> cars = new HashSet <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 getAgencyId() { 76 return agencyId; 77 } 78 79 public void setAgencyId(String agencyId) { 80 this.agencyId = agencyId; 81 } 82 83 @OneToMany(cascade = CascadeType.ALL) 84 @JoinColumn(name = "agency_agencyId") 85 public Set <Car> getCars() { 86 return cars; 87 } 88 89 public void setCars(Set <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 getHost() { 103 return host; 104 } 105 106 public void setHost(String host) { 107 this.host = host; 108 } 109 110 public String getPort() { 111 return port; 112 } 113 114 public void setPort(String port) { 115 this.port = port; 116 } 117 118 public String getWarName() { 119 return warName; 120 } 121 122 public void setWarName(String warName) { 123 this.warName = warName; 124 } 125 126 129 public boolean equals(Object 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 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 152 public String 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 |