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 13 import org.hibernate.annotations.GenericGenerator; 14 import org.objectweb.rentacar.persistance.dao.AgencyDAO; 15 import org.objectweb.rentacar.persistance.dao.DAOException; 16 import org.apache.commons.lang.builder.EqualsBuilder; 17 import org.apache.commons.lang.builder.HashCodeBuilder; 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 20 25 @Entity 26 public class CentralOffice { 27 28 private String centralOfficeId; 30 31 private String host; 32 33 private String port; 34 35 private Set <Agency> agencies; 37 38 public CentralOffice() { 39 super(); 40 } 42 43 public CentralOffice(Set <Agency> agencies) { 44 super(); 45 this.agencies = agencies; 46 } 47 48 public CentralOffice(String centralOfficeId, Set <Agency> agencies) { 49 super(); 50 this.centralOfficeId = centralOfficeId; 52 this.agencies = agencies; 53 } 54 55 public CentralOffice(CentralOfficeVO centralOfficeVO) { 56 super(); 57 this.centralOfficeId = centralOfficeVO.getCentralOfficeId(); 59 Set <Agency> agencies = new HashSet <Agency>(); 60 for (String agencyId : centralOfficeVO.getAgencies()) { 61 try { 62 agencies.add((Agency)AgencyDAO.getInstance().retrieveById(Agency.class, agencyId)); 63 } catch (DAOException e) { 64 e.printStackTrace(); 65 } 66 } 67 this.agencies = agencies; 68 this.host = centralOfficeVO.getHost(); 69 this.port = centralOfficeVO.getPort(); 70 } 71 72 @OneToMany(cascade=CascadeType.ALL) 73 @JoinColumn(name = "centralOffice_centralOfficeId") 74 public Set <Agency> getAgencies() { 75 return agencies; 76 } 77 78 public void setAgencies(Set <Agency> agencies) { 79 this.agencies = agencies; 80 } 81 82 @Id @GeneratedValue(generator = "system-uuid") 83 @GenericGenerator(name="system-uuid", strategy = "uuid") 84 public String getCentralOfficeId() { 85 return centralOfficeId; 86 } 87 88 public void setCentralOfficeId(String centralOfficeId) { 89 this.centralOfficeId = centralOfficeId; 90 } 91 92 public String getHost() { 93 return host; 94 } 95 96 public void setHost(String host) { 97 this.host = host; 98 } 99 100 public String getPort() { 101 return port; 102 } 103 104 public void setPort(String port) { 105 this.port = port; 106 } 107 108 111 public boolean equals(Object object) { 112 if (!(object instanceof CentralOffice)) { 113 return false; 114 } 115 CentralOffice rhs = (CentralOffice) object; 116 return new EqualsBuilder().append(this.centralOfficeId, 117 rhs.centralOfficeId).append(this.host, rhs.host).append( 118 this.agencies, rhs.agencies).append(this.port, rhs.port) 119 .isEquals(); 120 } 121 122 125 public int hashCode() { 126 return new HashCodeBuilder(135413657, -892320915).append( 127 this.centralOfficeId).append(this.host).append(this.agencies) 128 .append(this.port).toHashCode(); 129 } 130 131 134 public String toString() { 135 return new ToStringBuilder(this).append("centralOfficeId", 136 this.centralOfficeId).append("agencies", this.agencies).append( 137 "host", this.host).append("port", this.port).toString(); 138 } 139 140 141 142 } 143 | Popular Tags |