]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
used interface for target entities (much better)
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / department / CompanyDepartment.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.department;
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.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 javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import org.mxchange.jcontactsbusiness.BusinessContact;
35 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
36 import org.mxchange.jcontactsbusiness.employee.Employee;
37 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
38 import org.mxchange.jusercore.model.user.User;
39
40 /**
41  * A POJO for company departments
42  * <p>
43  * @author Roland Haeder<roland@mxchange.org>
44  */
45 @Entity (name = "company_departments")
46 @Table (name = "company_departments")
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class CompanyDepartment implements Department {
49
50         /**
51          * Serial number
52          */
53         private static final long serialVersionUID = 94_835_918_958_717_660L;
54
55         /**
56          * Where this department is located
57          */
58         @JoinColumn (name = "department_headquarters_id")
59         @OneToOne (targetEntity = HeadQuartersData.class, cascade = CascadeType.ALL)
60         private HeadQuartersData departentHeadquarters;
61
62         /**
63          * Where this department is located
64          */
65         @JoinColumn (name = "department_branch_id")
66         @ManyToOne (targetEntity = BranchOffice.class, cascade = CascadeType.ALL)
67         private BranchOffice departmentBranchOffice;
68
69         /**
70          * Connection to company contact
71          */
72         @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
73         @ManyToOne (targetEntity = BusinessContact.class, cascade = CascadeType.ALL, optional = false)
74         private BusinessContact departmentCompany;
75
76         /**
77          * Timestamp when this entry has been created
78          */
79         @Basic (optional = false)
80         @Temporal (TemporalType.TIMESTAMP)
81         @Column (name = "department_entry_created", nullable = false, updatable = false)
82         private Calendar departmentCreated;
83
84         /**
85          * Id number
86          */
87         @Id
88         @GeneratedValue (strategy = GenerationType.IDENTITY)
89         @Column (name = "department_id", nullable = false, updatable = false)
90         private Long departmentId;
91
92         /**
93          * Department lead employee
94          */
95         @JoinColumn (name = "department_lead_id", nullable = false)
96         @OneToOne (targetEntity = Employee.class, cascade = CascadeType.ALL)
97         private Employee departmentLead;
98
99         /**
100          * Department name
101          */
102         @Basic (optional = false)
103         @Column (name = "department_name", length = 100, nullable = false)
104         private String departmentName;
105
106         /**
107          * User owner instance
108          */
109         @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
110         @OneToOne (targetEntity = User.class, cascade = CascadeType.REFRESH, optional = false)
111         private User departmentUserOwner;
112
113         @Override
114         public boolean equals (final Object object) {
115                 if (null == object) {
116                         return false;
117                 } else if (this.getClass() != object.getClass()) {
118                         return false;
119                 }
120
121                 final Department other = (Department) object;
122
123                 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
124                         return false;
125                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
126                         return false;
127                 }
128
129                 return true;
130         }
131
132         @Override
133         public int hashCode () {
134                 int hash = 5;
135                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
136                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
137                 return hash;
138         }
139
140         @Override
141         public HeadQuartersData getDepartentHeadquarters () {
142                 return this.departentHeadquarters;
143         }
144
145         @Override
146         public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
147                 this.departentHeadquarters = departentHeadquarters;
148         }
149
150         @Override
151         public BranchOffice getDepartmentBranchOffice () {
152                 return this.departmentBranchOffice;
153         }
154
155         @Override
156         public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
157                 this.departmentBranchOffice = departmentBranchOffice;
158         }
159
160         @Override
161         public BusinessContact getDepartmentCompany () {
162                 return this.departmentCompany;
163         }
164
165         @Override
166         public void setDepartmentCompany (final BusinessContact departmentCompany) {
167                 this.departmentCompany = departmentCompany;
168         }
169
170         @Override
171         @SuppressWarnings ("ReturnOfDateField")
172         public Calendar getDepartmentCreated () {
173                 return this.departmentCreated;
174         }
175
176         @Override
177         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
178         public void setDepartmentCreated (final Calendar departmentCreated) {
179                 this.departmentCreated = departmentCreated;
180         }
181
182         @Override
183         public Long getDepartmentId () {
184                 return this.departmentId;
185         }
186
187         @Override
188         public void setDepartmentId (final Long departmentId) {
189                 this.departmentId = departmentId;
190         }
191
192         @Override
193         public Employee getDepartmentLead () {
194                 return this.departmentLead;
195         }
196
197         @Override
198         public void setDepartmentLead (final Employee departmentLead) {
199                 this.departmentLead = departmentLead;
200         }
201
202         @Override
203         public String getDepartmentName () {
204                 return this.departmentName;
205         }
206
207         @Override
208         public void setDepartmentName (final String departmentName) {
209                 this.departmentName = departmentName;
210         }
211
212         @Override
213         public User getDepartmentUserOwner () {
214                 return this.departmentUserOwner;
215         }
216
217         @Override
218         public void setDepartmentUserOwner (final User departmentUserOwner) {
219                 this.departmentUserOwner = departmentUserOwner;
220         }
221
222 }