]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/CompanyContact.java
added missing headquarters entity relationship
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / CompanyContact.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;
18
19 import java.util.List;
20 import java.util.Objects;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToMany;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Transient;
32 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
33 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
34 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
35 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
36 import org.mxchange.jcontactsbusiness.employee.Employee;
37 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
38 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
39
40 /**
41  * A POJO for business contacts
42  * <p>
43  * @author Roland Haeder
44  */
45 @Entity (name = "company_contacts")
46 @Table (name = "company_contacts")
47 public class CompanyContact implements BusinessContact, Comparable<BusinessContact> {
48
49         /**
50          * Serial number
51          */
52         private static final long serialVersionUID = 478_378_178_748_691L;
53
54         /**
55          * Reference to basic data
56          */
57         @JoinColumn (name = "company_basic_data_id", nullable = false, updatable = false)
58         @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
59         private BusinessBasicData basicBusinessData;
60
61         /**
62          * Reference to company branch offfices
63          */
64         @Transient
65         private List<BranchOffice> brancheOffices;
66
67         /**
68          * Reference to contact person
69          */
70         @JoinColumn (name = "company_contact_id")
71         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
72         private Employee companyContact;
73
74         /**
75          * Id number
76          */
77         @Id
78         @Column (name = "company_id", length = 20, nullable = false, updatable = false)
79         @GeneratedValue (strategy = GenerationType.IDENTITY)
80         private Long companyContactId;
81
82         /**
83          * Reference to CEO "employee"
84          */
85         @JoinColumn (name = "company_founder_id")
86         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
87         private Employee companyFounder;
88
89         /**
90          * Reference to employee list
91          */
92         @JoinColumn (name = "company_employees_id", nullable = false, updatable = false)
93         @OneToMany (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
94         private List<Employee> employees;
95
96         /**
97          * Reference to headquarters data
98          */
99         @JoinColumn (name = "company_headquarters_data_id", nullable = false, updatable = false)
100         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL, optional = false)
101         private HeadQuartersData headQuartersData;
102
103         @Override
104         public int compareTo (final BusinessContact businessContact) {
105                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
106         }
107
108         @Override
109         public boolean equals (final Object object) {
110                 if (object == null) {
111                         return false;
112                 } else if (getClass() != object.getClass()) {
113                         return false;
114                 }
115
116                 final BusinessContact other = (BusinessContact) object;
117
118                 return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData());
119         }
120
121         @Override
122         public BusinessBasicData getBasicBusinessData () {
123                 return this.basicBusinessData;
124         }
125
126         @Override
127         public void setBasicBusinessData (final BusinessBasicData basicBusinessData) {
128                 this.basicBusinessData = basicBusinessData;
129         }
130
131         @Override
132         public List<BranchOffice> getBrancheOffices () {
133                 return this.brancheOffices;
134         }
135
136         @Override
137         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
138                 this.brancheOffices = brancheOffices;
139         }
140
141         @Override
142         public Employee getCompanyContact () {
143                 return this.companyContact;
144         }
145
146         @Override
147         public void setCompanyContact (final Employee companyContact) {
148                 this.companyContact = companyContact;
149         }
150
151         @Override
152         public Long getCompanyContactId () {
153                 return this.companyContactId;
154         }
155
156         @Override
157         public void setCompanyContactId (final Long companyContactId) {
158                 this.companyContactId = companyContactId;
159         }
160
161         @Override
162         public Employee getCompanyFounder () {
163                 return this.companyFounder;
164         }
165
166         @Override
167         public void setCompanyFounder (final Employee companyFounder) {
168                 this.companyFounder = companyFounder;
169         }
170
171         @Override
172         public List<Employee> getEmployees () {
173                 return this.employees;
174         }
175
176         @Override
177         public void setEmployees (final List<Employee> employees) {
178                 this.employees = employees;
179         }
180
181         @Override
182         public HeadQuartersData getHeadQuartersData () {
183                 return this.headQuartersData;
184         }
185
186         @Override
187         public void setHeadQuartersData (final HeadQuartersData headQuartersData) {
188                 this.headQuartersData = headQuartersData;
189         }
190
191         @Override
192         public int hashCode () {
193                 int hash = 3;
194                 hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData());
195                 return hash;
196         }
197 }