View Javadoc
1   package org.woehlke.greenshop.oodm.customer.entities;
2   
3   import org.hibernate.annotations.NotFound;
4   import org.hibernate.annotations.NotFoundAction;
5   import org.hibernate.validator.constraints.Length;
6   
7   import javax.persistence.Column;
8   import javax.persistence.Entity;
9   import javax.persistence.GeneratedValue;
10  import javax.persistence.GenerationType;
11  import javax.persistence.Id;
12  import javax.persistence.JoinColumn;
13  import javax.persistence.ManyToOne;
14  import javax.persistence.Table;
15  import javax.validation.constraints.NotNull;
16  
17  /**
18   mysql> desc countries;
19   +----------------------+--------------+------+-----+---------+----------------+
20   | Field                | Type         | Null | Key | Default | Extra          |
21   +----------------------+--------------+------+-----+---------+----------------+
22   | countries_id         | int(11)      | NO   | PRI | NULL    | auto_increment |
23   | countries_name       | varchar(255) | NO   | MUL | NULL    |                |
24   | countries_iso_code_2 | char(2)      | NO   |     | NULL    |                |
25   | countries_iso_code_3 | char(3)      | NO   |     | NULL    |                |
26   | address_format_id    | int(11)      | NO   |     | NULL    |                |
27   +----------------------+--------------+------+-----+---------+----------------+
28   */
29  @Entity
30  @Table(name="countries")
31  public class Country {
32  	
33  	@Id
34  	@GeneratedValue(strategy=GenerationType.AUTO)
35  	@Column(name="countries_id",columnDefinition = "INT(11)")
36  	private Long id;
37  
38      @Length(min=1,max=128)
39  	@Column(name="countries_name")
40  	@NotNull
41  	private String name;
42  
43      @Length(min=2,max=2)
44  	@Column(name="countries_iso_code_2",length=2,columnDefinition = "char(2)")
45  	@NotNull
46  	private String isoCode2;
47  
48      @Length(min=3,max=3)
49  	@Column(name="countries_iso_code_3",length=3,columnDefinition = "char(3)")
50  	@NotNull
51  	private String isoCode3;
52  
53      @NotFound(action= NotFoundAction.IGNORE)
54  	@ManyToOne
55  	@JoinColumn(name="address_format_id")
56  	private AddressFormat addressFormat;
57  
58  	public Long getId() {
59  		return id;
60  	}
61  
62  	public void setId(Long id) {
63  		this.id = id;
64  	}
65  
66  	public String getName() {
67  		return name;
68  	}
69  
70  	public void setName(String name) {
71  		this.name = name;
72  	}
73  
74  	public String getIsoCode2() {
75  		return isoCode2;
76  	}
77  
78  	public void setIsoCode2(String isoCode2) {
79  		this.isoCode2 = isoCode2;
80  	}
81  
82  	public String getIsoCode3() {
83  		return isoCode3;
84  	}
85  
86  	public void setIsoCode3(String isoCode3) {
87  		this.isoCode3 = isoCode3;
88  	}
89  
90  	public AddressFormat getAddressFormat() {
91  		return addressFormat;
92  	}
93  
94  	public void setAddressFormat(AddressFormat addressFormat) {
95  		this.addressFormat = addressFormat;
96  	}
97  
98  	@Override
99  	public int hashCode() {
100 		final int prime = 31;
101 		int result = 1;
102 		result = prime * result
103 				+ ((addressFormat == null) ? 0 : addressFormat.hashCode());
104 		result = prime * result + ((id == null) ? 0 : id.hashCode());
105 		result = prime * result
106 				+ ((isoCode2 == null) ? 0 : isoCode2.hashCode());
107 		result = prime * result
108 				+ ((isoCode3 == null) ? 0 : isoCode3.hashCode());
109 		result = prime * result + ((name == null) ? 0 : name.hashCode());
110 		return result;
111 	}
112 
113 	@Override
114 	public boolean equals(Object obj) {
115 		if (this == obj)
116 			return true;
117 		if (obj == null)
118 			return false;
119 		if (getClass() != obj.getClass())
120 			return false;
121 		Country other = (Country) obj;
122 		if (addressFormat == null) {
123 			if (other.addressFormat != null)
124 				return false;
125 		} else if (!addressFormat.equals(other.addressFormat))
126 			return false;
127 		if (id == null) {
128 			if (other.id != null)
129 				return false;
130 		} else if (!id.equals(other.id))
131 			return false;
132 		if (isoCode2 == null) {
133 			if (other.isoCode2 != null)
134 				return false;
135 		} else if (!isoCode2.equals(other.isoCode2))
136 			return false;
137 		if (isoCode3 == null) {
138 			if (other.isoCode3 != null)
139 				return false;
140 		} else if (!isoCode3.equals(other.isoCode3))
141 			return false;
142 		if (name == null) {
143 			if (other.name != null)
144 				return false;
145 		} else if (!name.equals(other.name))
146 			return false;
147 		return true;
148 	}
149 
150 	@Override
151 	public String toString() {
152 		return "Country [id=" + id + ", name=" + name + ", isoCode2="
153 				+ isoCode2 + ", isoCode3=" + isoCode3 + ", addressFormat="
154 				+ addressFormat + "]";
155 	}
156 	
157 }