2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jcontactsbusiness.department;
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.ManyToOne;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import org.mxchange.jcontactsbusiness.BusinessContact;
36 import org.mxchange.jcontactsbusiness.CompanyContact;
37 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
38 import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice;
39 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
40 import org.mxchange.jcontactsbusiness.employee.Employee;
41 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
42 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
43 import org.mxchange.jusercore.model.user.LoginUser;
44 import org.mxchange.jusercore.model.user.User;
47 * A POJO for company departments
49 * @author Roland Haeder<roland@mxchange.org>
51 @Entity (name = "company_departments")
52 @Table (name = "company_departments")
53 public class CompanyDepartment implements Department, Comparable<Department> {
58 private static final long serialVersionUID = 94_835_918_958_717_660L;
61 * Where this department is located
63 @JoinColumn (name = "department_headquarters_id")
64 @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
65 private HeadQuartersData departentHeadquarters;
68 * Where this department is located
70 @JoinColumn (name = "department_branch_id")
71 @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
72 private BranchOffice departmentBranchOffice;
75 * Connection to company contact
77 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
78 @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
79 private BusinessContact departmentCompany;
82 * Timestamp when this entry has been created
84 @Basic (optional = false)
85 @Temporal (TemporalType.TIMESTAMP)
86 @Column (name = "department_entry_created", nullable = false, updatable = false)
87 private Calendar departmentCreated;
93 @GeneratedValue (strategy = GenerationType.IDENTITY)
94 @Column (name = "department_id", length = 20, nullable = false, updatable = false)
95 private Long departmentId;
98 * Department lead employee
100 @JoinColumn (name = "department_lead_id", nullable = false)
101 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
102 private Employee departmentLead;
107 @Basic (optional = false)
108 @Column (name = "department_name", length = 100, nullable = false)
109 private String departmentName;
112 * User owner instance
114 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
115 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
116 private User departmentUserOwner;
119 public int compareTo (final Department department) {
120 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
124 public boolean equals (final Object object) {
125 if (object == null) {
127 } else if (this.getClass() != object.getClass()) {
131 final Department other = (Department) object;
133 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
135 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
143 public int hashCode () {
145 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
146 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
151 public HeadQuartersData getDepartentHeadquarters () {
152 return this.departentHeadquarters;
156 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
157 this.departentHeadquarters = departentHeadquarters;
161 public BranchOffice getDepartmentBranchOffice () {
162 return this.departmentBranchOffice;
166 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
167 this.departmentBranchOffice = departmentBranchOffice;
171 public BusinessContact getDepartmentCompany () {
172 return this.departmentCompany;
176 public void setDepartmentCompany (final BusinessContact departmentCompany) {
177 this.departmentCompany = departmentCompany;
181 public Calendar getDepartmentCreated () {
182 return this.departmentCreated;
186 public void setDepartmentCreated (final Calendar departmentCreated) {
187 this.departmentCreated = departmentCreated;
191 public Long getDepartmentId () {
192 return this.departmentId;
196 public void setDepartmentId (final Long departmentId) {
197 this.departmentId = departmentId;
201 public Employee getDepartmentLead () {
202 return this.departmentLead;
206 public void setDepartmentLead (final Employee departmentLead) {
207 this.departmentLead = departmentLead;
211 public String getDepartmentName () {
212 return this.departmentName;
216 public void setDepartmentName (final String departmentName) {
217 this.departmentName = departmentName;
221 public User getDepartmentUserOwner () {
222 return this.departmentUserOwner;
226 public void setDepartmentUserOwner (final User departmentUserOwner) {
227 this.departmentUserOwner = departmentUserOwner;