]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java
A @OneToMany annotation always causes that in the target entity's table the column...
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / employee / CompanyEmployee.java
1 /*
2  * Copyright (C) 2015 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.employee;
18
19 import java.util.Objects;
20 import javax.persistence.CascadeType;
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.FetchType;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToOne;
29 import javax.persistence.Table;
30 import org.mxchange.jcontacts.contact.Contact;
31 import org.mxchange.jcontacts.contact.UserContact;
32 import org.mxchange.jcontactsbusiness.BusinessContact;
33 import org.mxchange.jcontactsbusiness.CompanyContact;
34 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
35 import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice;
36 import org.mxchange.jcontactsbusiness.department.CompanyDepartment;
37 import org.mxchange.jcontactsbusiness.department.Department;
38 import org.mxchange.jcontactsbusiness.jobposition.EmployeePosition;
39 import org.mxchange.jcontactsbusiness.jobposition.JobPosition;
40 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
41 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
42
43 /**
44  * A POJO for company employees (including CEO)
45  * <p>
46  * @author Roland Haeder
47  */
48 @Entity (name = "company_employees")
49 @Table (name = "company_employees")
50 public class CompanyEmployee implements Employee, Comparable<Employee> {
51
52         /**
53          * Serial number
54          */
55         private static final long serialVersionUID = 48_959_819_859_812_076L;
56
57         /**
58          * Branch office the employee works at
59          */
60         @JoinColumn (name = "employee_branch_id")
61         @OneToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
62         private BranchOffice employeeBranchOffice;
63
64         /**
65          * Company the employee is working at
66          */
67         @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
68         @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false)
69         private BusinessContact employeeCompany;
70
71         /**
72          * Department the employee works at
73          */
74         @JoinColumn (name = "employee_department_id")
75         @OneToOne (targetEntity = CompanyDepartment.class, cascade = CascadeType.ALL)
76         private Department employeeDepartment;
77
78         /**
79          * Employee's email address
80          */
81         @Column (name = "employee_email_address", length = 30)
82         private String employeeEmailAddress;
83
84         /**
85          * Id number
86          */
87         @Id
88         @Column (name = "employee_id", length = 20, nullable = false, updatable = false)
89         @GeneratedValue (strategy = GenerationType.IDENTITY)
90         private Long employeeId;
91
92         /**
93          * Employee's business mobile number
94          */
95         @JoinColumn (name = "employee_mobile_number_id")
96         @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL)
97         private DialableCellphoneNumber employeeMobileNumber;
98
99         /**
100          * Employee's number
101          */
102         @Column (name = "employee_number", length = 20)
103         private String employeeNumber;
104
105         /**
106          * Employee's personal data
107          */
108         @JoinColumn (name = "employee_personal_data_id", nullable = false, updatable = false)
109         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
110         private Contact employeePersonalData;
111
112         /**
113          * Employee's phone extension (or number if different)
114          */
115         @Column (name = "employee_phone_extension", length = 10)
116         private Integer employeePhoneExtension;
117
118         /**
119          * Employee's position (example: CEO)
120          */
121         @JoinColumn (name = "employee_position_id")
122         @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
123         private JobPosition employeePosition;
124
125         @Override
126         public int compareTo (final Employee employee) {
127                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
128         }
129
130         @Override
131         public boolean equals (final Object object) {
132                 if (object == null) {
133                         return false;
134                 } else if (getClass() != object.getClass()) {
135                         return false;
136                 }
137
138                 final Employee other = (Employee) object;
139
140                 if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) {
141                         return false;
142                 } else if (!Objects.equals(this.getEmployeeNumber(), other.getEmployeeNumber())) {
143                         return false;
144                 } else if (!Objects.equals(this.getEmployeePersonalData(), other.getEmployeePersonalData())) {
145                         return false;
146                 }
147
148                 return true;
149         }
150
151         @Override
152         public BranchOffice getEmployeeBranchOffice () {
153                 return this.employeeBranchOffice;
154         }
155
156         @Override
157         public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
158                 this.employeeBranchOffice = employeeBranchOffice;
159         }
160
161         @Override
162         public BusinessContact getEmployeeCompany () {
163                 return this.employeeCompany;
164         }
165
166         @Override
167         public void setEmployeeCompany (final BusinessContact employeeCompany) {
168                 this.employeeCompany = employeeCompany;
169         }
170
171         @Override
172         public Department getEmployeeDepartment () {
173                 return this.employeeDepartment;
174         }
175
176         @Override
177         public void setEmployeeDepartment (final Department employeeDepartment) {
178                 this.employeeDepartment = employeeDepartment;
179         }
180
181         @Override
182         public String getEmployeeEmailAddress () {
183                 return this.employeeEmailAddress;
184         }
185
186         @Override
187         public void setEmployeeEmailAddress (final String employeeEmailAddress) {
188                 this.employeeEmailAddress = employeeEmailAddress;
189         }
190
191         @Override
192         public Long getEmployeeId () {
193                 return this.employeeId;
194         }
195
196         @Override
197         public void setEmployeeId (final Long employeeId) {
198                 this.employeeId = employeeId;
199         }
200
201         @Override
202         public DialableCellphoneNumber getEmployeeMobileNumber () {
203                 return this.employeeMobileNumber;
204         }
205
206         @Override
207         public void setEmployeeMobileNumber (final DialableCellphoneNumber employeeMobileNumber) {
208                 this.employeeMobileNumber = employeeMobileNumber;
209         }
210
211         @Override
212         public String getEmployeeNumber () {
213                 return this.employeeNumber;
214         }
215
216         @Override
217         public void setEmployeeNumber (final String employeeNumber) {
218                 this.employeeNumber = employeeNumber;
219         }
220
221         @Override
222         public Contact getEmployeePersonalData () {
223                 return this.employeePersonalData;
224         }
225
226         @Override
227         public void setEmployeePersonalData (final Contact employeePersonalData) {
228                 this.employeePersonalData = employeePersonalData;
229         }
230
231         @Override
232         public Integer getEmployeePhoneExtension () {
233                 return this.employeePhoneExtension;
234         }
235
236         @Override
237         public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
238                 this.employeePhoneExtension = employeePhoneExtension;
239         }
240
241         @Override
242         public JobPosition getEmployeePosition () {
243                 return this.employeePosition;
244         }
245
246         @Override
247         public void setEmployeePosition (final JobPosition employeePosition) {
248                 this.employeePosition = employeePosition;
249         }
250
251         @Override
252         public int hashCode () {
253                 int hash = 3;
254                 hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany());
255                 hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
256                 hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());
257                 return hash;
258         }
259 }