]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java
Don't implement lists in a POJO/POJI, better handle it outside of it
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / branch / CompanyBranchOffice.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.branch;
18
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.FetchType;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import org.mxchange.jcontactsbusiness.CompanyContact;
35 import org.mxchange.jcountry.data.Country;
36 import org.mxchange.jcountry.data.CountryData;
37 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
38 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
39 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
40 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
41 import org.mxchange.jusercore.model.user.LoginUser;
42 import org.mxchange.jusercore.model.user.User;
43
44 /**
45  * A POJO for company branch offices
46  * <p>
47  * @author Roland Haeder
48  */
49 @Entity (name = "company_branch_offices")
50 @Table (name = "company_branch_offices")
51 public class CompanyBranchOffice implements BranchOffice, Comparable<BranchOffice> {
52
53         /**
54          * Serial number
55          */
56         private static final long serialVersionUID = 47_957_817_276_871_852L;
57
58         /**
59          * Branch office's city name
60          */
61         @Basic (optional = false)
62         @Column (name = "branch_city", length = 100, nullable = false)
63         private String branchCity;
64
65         /**
66          * Company that has this branch office
67          */
68         @JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
69         @OneToOne (targetEntity = CompanyContact.class, optional = false, cascade = CascadeType.ALL)
70         private Long branchCompanyContact;
71
72         /**
73          * Branch office's country code
74          */
75         @JoinColumn (name = "branch_country_id", nullable = false)
76         @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.MERGE, optional = false, fetch = FetchType.EAGER)
77         private Country branchCountry;
78
79         /**
80          * Branch office's main email address (example: branch-name@company.com)
81          */
82         @Column (name = "branch_email_address", length = 100)
83         private String branchEmailAddress;
84
85         /**
86          * Branch office's main fax number: +ccxxxxxxxxxx
87          */
88         @JoinColumn (name = "branch_fax_number_id")
89         @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
90         private DialableFaxNumber branchFaxNumber;
91
92         /**
93          * Branch office's house number
94          */
95         @Basic (optional = false)
96         @Column (name = "branch_house_number", length = 3, nullable = false)
97         private Short branchHouseNumber;
98
99         /**
100          * Id number
101          */
102         @Id
103         @GeneratedValue (strategy = GenerationType.IDENTITY)
104         @Column (name = "branch_id", length = 20, nullable = false, updatable = false)
105         private Long branchId;
106
107         /**
108          * Branch office's main phone number: +ccxxxxxxxxxx
109          */
110         @JoinColumn (name = "branch_phone_number_id")
111         @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
112         private DialableLandLineNumber branchPhoneNumber;
113
114         /**
115          * Branch office's store (if multiple-store building)
116          */
117         @Column (name = "branch_store", length = 3)
118         private Short branchStore;
119
120         /**
121          * Branch office's street name
122          */
123         @Basic (optional = false)
124         @Column (name = "branch_street", length = 100, nullable = false)
125         private String branchStreet;
126
127         /**
128          * Branch office's suite number (if applyable)
129          */
130         @Column (name = "branch_suite_number", length = 4)
131         private Short branchSuiteNumber;
132
133         /**
134          * Branch office's ZIP code
135          */
136         @Basic (optional = false)
137         @Column (name = "branch_zip_code", length = 6, nullable = false)
138         private Integer branchZipCode;
139
140         /**
141          * User owner instance
142          */
143         @JoinColumn (name = "branch_user_id", nullable = false, updatable = false)
144         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
145         private User branchUserOwner;
146
147         /**
148          * Timestamp when this entry has been created
149          */
150         @Basic (optional = false)
151         @Temporal (TemporalType.TIMESTAMP)
152         @Column (name = "branch_entry_created", nullable = false, updatable = false)
153         private Calendar branchCreated;
154
155         @Override
156         public String getBranchCity () {
157                 return this.branchCity;
158         }
159
160         @Override
161         public void setBranchCity (final String branchCity) {
162                 this.branchCity = branchCity;
163         }
164
165         @Override
166         public Long getBranchCompanyContact () {
167                 return this.branchCompanyContact;
168         }
169
170         @Override
171         public void setBranchCompanyContact (final Long branchCompanyContact) {
172                 this.branchCompanyContact = branchCompanyContact;
173         }
174
175         @Override
176         public Country getBranchCountry () {
177                 return this.branchCountry;
178         }
179
180         @Override
181         public void setBranchCountry (final Country branchCountry) {
182                 this.branchCountry = branchCountry;
183         }
184
185         @Override
186         public String getBranchEmailAddress () {
187                 return this.branchEmailAddress;
188         }
189
190         @Override
191         public void setBranchEmailAddress (final String branchEmailAddress) {
192                 this.branchEmailAddress = branchEmailAddress;
193         }
194
195         @Override
196         public DialableFaxNumber getBranchFaxNumber () {
197                 return this.branchFaxNumber;
198         }
199
200         @Override
201         public void setBranchFaxNumber (final DialableFaxNumber branchFaxNumber) {
202                 this.branchFaxNumber = branchFaxNumber;
203         }
204
205         @Override
206         public Short getBranchHouseNumber () {
207                 return this.branchHouseNumber;
208         }
209
210         @Override
211         public void setBranchHouseNumber (final Short branchHouseNumber) {
212                 this.branchHouseNumber = branchHouseNumber;
213         }
214
215         @Override
216         public Long getBranchId () {
217                 return this.branchId;
218         }
219
220         @Override
221         public void setBranchId (final Long branchId) {
222                 this.branchId = branchId;
223         }
224
225         @Override
226         public DialableLandLineNumber getBranchPhoneNumber () {
227                 return this.branchPhoneNumber;
228         }
229
230         @Override
231         public void setBranchPhoneNumber (final DialableLandLineNumber branchPhoneNumber) {
232                 this.branchPhoneNumber = branchPhoneNumber;
233         }
234
235         @Override
236         public Short getBranchStore () {
237                 return this.branchStore;
238         }
239
240         @Override
241         public void setBranchStore (final Short branchStore) {
242                 this.branchStore = branchStore;
243         }
244
245         @Override
246         public String getBranchStreet () {
247                 return this.branchStreet;
248         }
249
250         @Override
251         public void setBranchStreet (final String branchStreet) {
252                 this.branchStreet = branchStreet;
253         }
254
255         @Override
256         public Short getBranchSuiteNumber () {
257                 return this.branchSuiteNumber;
258         }
259
260         @Override
261         public void setBranchSuiteNumber (final Short branchSuiteNumber) {
262                 this.branchSuiteNumber = branchSuiteNumber;
263         }
264
265         @Override
266         public Integer getBranchZipCode () {
267                 return this.branchZipCode;
268         }
269
270         @Override
271         public void setBranchZipCode (final Integer branchZipCode) {
272                 this.branchZipCode = branchZipCode;
273         }
274
275         @Override
276         public Calendar getBranchCreated () {
277                 return this.branchCreated;
278         }
279
280         @Override
281         public void setBranchCreated (final Calendar branchCreated) {
282                 this.branchCreated = branchCreated;
283         }
284
285         @Override
286         public User getBranchUserOwner () {
287                 return this.branchUserOwner;
288         }
289
290         @Override
291         public void setBranchUserOwner (final User branchUserOwner) {
292                 this.branchUserOwner = branchUserOwner;
293         }
294
295         @Override
296         public int compareTo (final BranchOffice branchOffice) {
297                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
298         }
299
300         @Override
301         public boolean equals (final Object object) {
302                 if (object == null) {
303                         return false;
304                 } else if (getClass() != object.getClass()) {
305                         return false;
306                 }
307
308                 final BranchOffice other = (BranchOffice) object;
309
310                 if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) {
311                         return false;
312                 } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) {
313                         return false;
314                 } else if (!Objects.equals(this.getBranchHouseNumber(), other.getBranchHouseNumber())) {
315                         return false;
316                 } else if (!Objects.equals(this.getBranchStore(), other.getBranchStore())) {
317                         return false;
318                 } else if (!Objects.equals(this.getBranchStreet(), other.getBranchStreet())) {
319                         return false;
320                 } else if (!Objects.equals(this.getBranchSuiteNumber(), other.getBranchSuiteNumber())) {
321                         return false;
322                 } else if (!Objects.equals(this.getBranchZipCode(), other.getBranchZipCode())) {
323                         return false;
324                 }
325
326                 return true;
327         }
328
329         @Override
330         public int hashCode () {
331                 int hash = 7;
332                 hash = 53 * hash + Objects.hashCode(this.getBranchCity());
333                 hash = 53 * hash + Objects.hashCode(this.getBranchCountry());
334                 hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber());
335                 hash = 53 * hash + Objects.hashCode(this.getBranchStore());
336                 hash = 53 * hash + Objects.hashCode(this.getBranchStreet());
337                 hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber());
338                 hash = 53 * hash + Objects.hashCode(this.getBranchZipCode());
339                 return hash;
340         }
341 }