1 /*
2 * Copyright 2007 The International Moth Class Association (IMCA)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.imca.model.entities;
17
18 import javax.persistence.Entity;
19 import javax.persistence.GeneratedValue;
20 import javax.persistence.GenerationType;
21 import javax.persistence.Id;
22 import javax.persistence.NamedQueries;
23 import javax.persistence.NamedQuery;
24
25 /**
26 * An persistence entity description. There is no logic just getter and setters,
27 * for the properties. This Object represents a table in the database and the
28 * properties are fields.
29 *
30 * @author dougculnane
31 */
32 @Entity
33 @NamedQueries ({
34 @NamedQuery(name = "AddressBasicSearch",
35 query = "SELECT a FROM AddressEntity a WHERE " +
36 "a.street1 LIKE :search " +
37 "OR a.street2 LIKE :search " +
38 "OR a.city LIKE :search " +
39 "OR a.area LIKE :search")
40 })
41 public class AddressEntity {
42
43 /**
44 * Object Identifier.
45 */
46 @Id
47 @GeneratedValue(strategy=GenerationType.TABLE)
48 private long id;
49
50 /**
51 * First line in address.
52 */
53 private String street1 = "";
54
55 /**
56 * Second line in address.
57 */
58 private String street2 = "";
59
60 /**
61 * Nearest City.
62 */
63 private String city = "";
64
65 /**
66 * Area or country.
67 */
68 private String area = "";
69
70 /**
71 * Post Code.
72 */
73 private String postCode = "";
74
75 /**
76 * ISO 2 digit country code.
77 */
78 private String countryCode = "";
79
80 /**
81 * Get the area.
82 *
83 * @return
84 */
85 public String getArea() {
86 return area;
87 }
88
89 /**
90 * Set the area.
91 */
92 public void setArea(String area) {
93 this.area = area;
94 }
95
96 /**
97 * Get the city.
98 *
99 * @return
100 */
101 public String getCity() {
102 return city;
103 }
104
105 /**
106 * Set the city.
107 */
108 public void setCity(String city) {
109 this.city = city;
110 }
111
112 /**
113 * Get the countryCode.
114 *
115 * @return
116 */
117 public String getCountryCode() {
118 return countryCode;
119 }
120
121 /**
122 * Set the countryCode.
123 */
124 public void setCountryCode(String countryCode) {
125 this.countryCode = countryCode;
126 }
127
128 /**
129 * Get the id.
130 *
131 * @return
132 */
133 public long getId() {
134 return id;
135 }
136
137 /**
138 * Set the id.
139 */
140 public void setId(long id) {
141 this.id = id;
142 }
143
144 /**
145 * Get the postCode.
146 *
147 * @return
148 */
149 public String getPostCode() {
150 return postCode;
151 }
152
153 /**
154 * Set the postCode.
155 */
156 public void setPostCode(String postCode) {
157 this.postCode = postCode;
158 }
159
160 /**
161 * Get the street1.
162 *
163 * @return
164 */
165 public String getStreet1() {
166 return street1;
167 }
168
169 /**
170 * Set the street1.
171 */
172 public void setStreet1(String street1) {
173 this.street1 = street1;
174 }
175
176 /**
177 * Get the street2.
178 *
179 * @return
180 */
181 public String getStreet2() {
182 return street2;
183 }
184
185 /**
186 * Set the street2.
187 */
188 public void setStreet2(String street2) {
189 this.street2 = street2;
190 }
191
192 /**
193 * Override the Object method to give a usable human readable
194 * representation of the Object.
195 */
196 public String toString(){
197 StringBuffer buf = new StringBuffer();
198 addToString(buf, this.street1);
199 addToString(buf, this.street2);
200 addToString(buf, this.city);
201 addToString(buf, this.area);
202 addToString(buf, this.postCode);
203 addToString(buf, this.countryCode);
204 return buf.toString();
205 }
206
207 /**
208 * Utility for building string.
209 *
210 * @param buf A String Buffer.
211 * @param field Field to add to buffer if not null etc.
212 */
213 private void addToString(StringBuffer buf, String field){
214 if (field != null && field.length() > 0) {
215 if (buf.length() > 0){
216 buf.append(", ");
217 }
218 buf.append(field);
219 }
220 }
221 }