1 package org.objectweb.rentacar.persistance.bo; 2 3 import java.util.Date ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 7 import javax.persistence.CascadeType; 8 import javax.persistence.Entity; 9 import javax.persistence.FetchType; 10 import javax.persistence.GeneratedValue; 11 import javax.persistence.Id; 12 import javax.persistence.JoinColumn; 13 import javax.persistence.ManyToMany; 14 import javax.persistence.ManyToOne; 15 import javax.persistence.Temporal; 16 import javax.persistence.TemporalType; 17 18 import org.apache.commons.lang.builder.EqualsBuilder; 19 import org.apache.commons.lang.builder.HashCodeBuilder; 20 import org.apache.commons.lang.builder.ToStringBuilder; 21 import org.hibernate.annotations.GenericGenerator; 22 23 28 @Entity 29 public class Reservation { 30 31 private String reservationId; 32 33 private Contact customer; 34 35 private Set <Car> cars; 36 37 private Date startingDate; 38 39 private Date endingDate; 40 41 private Agency startingAgency; 42 43 private Agency endingAgency; 44 45 46 public Reservation() { 47 super(); 48 } 49 50 public Reservation(Contact customer, Set <Car> cars, Date startingDate, Date endingDate, Agency startingAgency, Agency endingAgency) { 51 super(); 52 this.customer = customer; 53 this.cars = cars; 54 this.startingDate = startingDate; 55 this.endingDate = endingDate; 56 this.startingAgency = startingAgency; 57 this.endingAgency = endingAgency; 58 } 59 60 public Reservation(String reservationId, Contact customer, Set <Car> cars, Date startingDate, Date endingDate, Agency startingAgency, Agency endingAgency) { 61 super(); 62 this.reservationId = reservationId; 63 this.customer = customer; 64 this.cars = cars; 65 this.startingDate = startingDate; 66 this.endingDate = endingDate; 67 this.startingAgency = startingAgency; 68 this.endingAgency = endingAgency; 69 } 70 71 public Reservation(ReservationVO reservationVO) { 72 super(); 73 this.reservationId = reservationVO.getReservationId(); 74 this.customer = new Contact(reservationVO.getCustomer()); 75 Set <Car> cars = new HashSet <Car>(); 76 for (CarVO car : reservationVO.getCars()) { 77 cars.add(new Car(car)); 78 } 79 this.cars = cars; 80 this.startingDate = reservationVO.getStartingDate(); 81 this.endingDate = reservationVO.getEndingDate(); 82 this.startingAgency = new Agency(reservationVO.getStartingAgency()); 83 this.endingAgency = new Agency(reservationVO.getEndingAgency()); 84 } 85 86 87 @ManyToMany(fetch=FetchType.EAGER) 88 @JoinColumn(name="reservation_reservaionId") 89 public Set <Car> getCars() { 90 return cars; 91 } 92 93 public void setCars(Set <Car> cars) { 94 this.cars = cars; 95 } 96 97 @ManyToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}) 98 public Contact getCustomer() { 99 return customer; 100 } 101 102 public void setCustomer(Contact customer) { 103 this.customer = customer; 104 } 105 106 @ManyToOne 107 @JoinColumn(name="ending_agency") 108 public Agency getEndingAgency() { 109 return endingAgency; 110 } 111 112 public void setEndingAgency(Agency endingAgency) { 113 this.endingAgency = endingAgency; 114 } 115 116 @Temporal(TemporalType.TIMESTAMP) 117 public Date getEndingDate() { 118 return endingDate; 119 } 120 121 public void setEndingDate(Date endingDate) { 122 this.endingDate = endingDate; 123 } 124 125 @Id @GeneratedValue(generator = "system-uuid") 126 @GenericGenerator(name="system-uuid", strategy = "uuid") 127 public String getReservationId() { 128 return reservationId; 129 } 130 131 public void setReservationId(String reservationId) { 132 this.reservationId = reservationId; 133 } 134 135 @ManyToOne 136 @JoinColumn(name="starting_agency") 137 public Agency getStartingAgency() { 138 return startingAgency; 139 } 140 141 public void setStartingAgency(Agency startingAgency) { 142 this.startingAgency = startingAgency; 143 } 144 145 @Temporal(TemporalType.TIMESTAMP) 146 public Date getStartingDate() { 147 return startingDate; 148 } 149 150 public void setStartingDate(Date startingDate) { 151 this.startingDate = startingDate; 152 } 153 154 157 public boolean equals(Object object) { 158 if (!(object instanceof Reservation)) { 159 return false; 160 } 161 Reservation rhs = (Reservation) object; 162 return new EqualsBuilder().append(this.endingDate, rhs.endingDate) 163 .append(this.cars, rhs.cars).append(this.startingDate, rhs.startingDate).append( 164 this.reservationId, rhs.reservationId).append( 165 this.customer, rhs.customer).append(this.endingAgency, 166 rhs.endingAgency).append(this.startingAgency, 167 rhs.startingAgency).isEquals(); 168 } 169 170 173 public int hashCode() { 174 return new HashCodeBuilder(2130538209, 1222600301).append( 175 this.endingDate).append(this.cars).append( 176 this.startingDate).append(this.reservationId).append( 177 this.customer).append(this.endingAgency).append( 178 this.startingAgency).toHashCode(); 179 } 180 181 184 public String toString() { 185 return new ToStringBuilder(this).append("startingDate", 186 this.startingDate).append("car", this.cars).append( 187 "reservationId", this.reservationId).append("customer", 188 this.customer).append("startingAgency", this.startingAgency) 189 .append("endingAgency", 190 this.endingAgency) 191 .append("endingDate", this.endingDate).toString(); 192 } 193 194 } 195 | Popular Tags |