]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/CompanyContact.java
let's make sure that serial numbers of objects are never persisted (being ignored...
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / CompanyContact.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;
18
19 import java.util.Calendar;
20 import java.util.List;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
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 javax.persistence.Transient;
35 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
36 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
37 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
38 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
39 import org.mxchange.jcontactsbusiness.employee.Employee;
40 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
41 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
42 import org.mxchange.jusercore.model.user.LoginUser;
43 import org.mxchange.jusercore.model.user.User;
44
45 /**
46  * A POJO for business contacts
47  * <p>
48  * @author Roland Haeder<roland@mxchange.org>
49  */
50 @Entity (name = "company_contacts")
51 @Table (name = "company_contacts")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class CompanyContact implements BusinessContact {
54
55         /**
56          * Serial number
57          */
58         @Transient
59         private static final long serialVersionUID = 470_375_172_748_691L;
60
61         /**
62          * Reference to basic data
63          */
64         @JoinColumn (name = "company_basic_data_id", nullable = false, updatable = false)
65         @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
66         private BusinessBasicData basicBusinessData;
67
68         /**
69          * Reference to company branch offfices
70          */
71         @Transient
72         private List<BranchOffice> brancheOffices;
73
74         /**
75          * Reference to contact person
76          */
77         @JoinColumn (name = "company_contact_id")
78         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
79         private Employee companyContact;
80
81         /**
82          * Id number
83          */
84         @Id
85         @Column (name = "company_id", nullable = false, updatable = false)
86         @GeneratedValue (strategy = GenerationType.IDENTITY)
87         private Long companyContactId;
88
89         /**
90          * Reference to CEO "employee"
91          */
92         @JoinColumn (name = "company_founder_id")
93         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
94         private Employee companyFounder;
95
96         /**
97          * Timestamp when this entry has been created
98          */
99         @Basic (optional = false)
100         @Temporal (TemporalType.TIMESTAMP)
101         @Column (name = "company_entry_created", nullable = false, updatable = false)
102         private Calendar contactCreated;
103
104         /**
105          * User owner instance
106          */
107         @JoinColumn (name = "company_user_id", nullable = false, updatable = false)
108         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
109         private User contactUserOwner;
110
111         /**
112          * Reference to headquarters data
113          */
114         @JoinColumn (name = "company_headquarters_data_id", nullable = false, updatable = false)
115         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL, optional = false)
116         private HeadQuartersData headQuartersData;
117
118         @Override
119         public boolean equals (final Object object) {
120                 if (null == object) {
121                         return false;
122                 } else if (this.getClass() != object.getClass()) {
123                         return false;
124                 }
125
126                 final BusinessContact other = (BusinessContact) object;
127
128                 return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData());
129         }
130
131         @Override
132         public BusinessBasicData getBasicBusinessData () {
133                 return this.basicBusinessData;
134         }
135
136         @Override
137         public void setBasicBusinessData (final BusinessBasicData basicBusinessData) {
138                 this.basicBusinessData = basicBusinessData;
139         }
140
141         @Override
142         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
143         public List<BranchOffice> getBrancheOffices () {
144                 return this.brancheOffices;
145         }
146
147         @Override
148         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
149         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
150                 this.brancheOffices = brancheOffices;
151         }
152
153         @Override
154         public Employee getCompanyContact () {
155                 return this.companyContact;
156         }
157
158         @Override
159         public void setCompanyContact (final Employee companyContact) {
160                 this.companyContact = companyContact;
161         }
162
163         @Override
164         public Long getCompanyContactId () {
165                 return this.companyContactId;
166         }
167
168         @Override
169         public void setCompanyContactId (final Long companyContactId) {
170                 this.companyContactId = companyContactId;
171         }
172
173         @Override
174         public Employee getCompanyFounder () {
175                 return this.companyFounder;
176         }
177
178         @Override
179         public void setCompanyFounder (final Employee companyFounder) {
180                 this.companyFounder = companyFounder;
181         }
182
183         @Override
184         @SuppressWarnings ("ReturnOfDateField")
185         public Calendar getContactCreated () {
186                 return this.contactCreated;
187         }
188
189         @Override
190         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
191         public void setContactCreated (final Calendar contactCreated) {
192                 this.contactCreated = contactCreated;
193         }
194
195         @Override
196         public User getContactUserOwner () {
197                 return this.contactUserOwner;
198         }
199
200         @Override
201         public void setContactUserOwner (final User contactUserOwner) {
202                 this.contactUserOwner = contactUserOwner;
203         }
204
205         @Override
206         public HeadQuartersData getHeadQuartersData () {
207                 return this.headQuartersData;
208         }
209
210         @Override
211         public void setHeadQuartersData (final HeadQuartersData headQuartersData) {
212                 this.headQuartersData = headQuartersData;
213         }
214
215         @Override
216         public int hashCode () {
217                 int hash = 3;
218                 hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData());
219                 return hash;
220         }
221 }