]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
added connection from department to headquarters and branch offices
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / department / CompanyDepartment.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.department;
18
19 import java.util.Objects;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.FetchType;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
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.employee.CompanyEmployee;
37 import org.mxchange.jcontactsbusiness.employee.Employee;
38 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
39 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
40
41 /**
42  * A POJO for company departments
43  * <p>
44  * @author Roland Haeder
45  */
46 @Entity (name = "company_departments")
47 @Table (name = "company_departments")
48 public class CompanyDepartment implements Department, Comparable<Department> {
49
50         /**
51          * Serial number
52          */
53         private static final long serialVersionUID = 94_835_918_958_717_660L;
54
55         /**
56          * Connection to company contact
57          */
58         @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
59         @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
60         private BusinessContact departmentCompany;
61
62         /**
63          * Where this department is located
64          */
65         @JoinColumn (name = "department_branch_id")
66         @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
67         private BranchOffice departmentBranchOffice;
68
69         /**
70          * Where this department is located
71          */
72         @JoinColumn (name = "department_headquarters_id")
73         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
74         private HeadQuartersData departentHeadquarters;
75
76         /**
77          * Id number
78          */
79         @Id
80         @GeneratedValue (strategy = GenerationType.IDENTITY)
81         @Column (name = "department_id", length = 20, nullable = false, updatable = false)
82         private Long departmentId;
83
84         /**
85          * Department lead employee
86          */
87         @JoinColumn (name = "department_lead_id", nullable = false)
88         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
89         private Employee departmentLead;
90
91         /**
92          * Department name
93          */
94         @Basic (optional = false)
95         @Column (name = "department_name", length = 100, nullable = false)
96         private String departmentName;
97
98         @Override
99         public int compareTo (final Department department) {
100                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
101         }
102
103         @Override
104         public boolean equals (final Object object) {
105                 if (object == null) {
106                         return false;
107                 } else if (getClass() != object.getClass()) {
108                         return false;
109                 }
110
111                 final Department other = (Department) object;
112
113                 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
114                         return false;
115                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
116                         return false;
117                 }
118
119                 return true;
120         }
121
122         @Override
123         public HeadQuartersData getDepartentHeadquarters () {
124                 return this.departentHeadquarters;
125         }
126
127         @Override
128         public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
129                 this.departentHeadquarters = departentHeadquarters;
130         }
131
132         @Override
133         public BranchOffice getDepartmentBranchOffice () {
134                 return this.departmentBranchOffice;
135         }
136
137         @Override
138         public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
139                 this.departmentBranchOffice = departmentBranchOffice;
140         }
141
142         @Override
143         public BusinessContact getDepartmentCompany () {
144                 return this.departmentCompany;
145         }
146
147         @Override
148         public void setDepartmentCompany (final BusinessContact departmentCompany) {
149                 this.departmentCompany = departmentCompany;
150         }
151
152         @Override
153         public Long getDepartmentId () {
154                 return this.departmentId;
155         }
156
157         @Override
158         public void setDepartmentId (final Long departmentId) {
159                 this.departmentId = departmentId;
160         }
161
162         @Override
163         public Employee getDepartmentLead () {
164                 return this.departmentLead;
165         }
166
167         @Override
168         public void setDepartmentLead (final Employee departmentLead) {
169                 this.departmentLead = departmentLead;
170         }
171
172         @Override
173         public String getDepartmentName () {
174                 return this.departmentName;
175         }
176
177         @Override
178         public void setDepartmentName (final String departmentName) {
179                 this.departmentName = departmentName;
180         }
181
182         @Override
183         public int hashCode () {
184                 int hash = 5;
185                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
186                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
187                 return hash;
188         }
189 }