]> git.mxchange.org Git - jcontacts-business-core.git/blobdiff - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
Having basic data and "business contact" which is really no contact in general
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / department / CompanyDepartment.java
index 6056d097046964c45a951e18afa3da94b646d177..6e567056b4521406df894a681b312249119580c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@ import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
-import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -32,8 +31,8 @@ import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
-import org.mxchange.jcontactsbusiness.BusinessContact;
-import org.mxchange.jcontactsbusiness.CompanyContact;
+import javax.persistence.Transient;
+import org.mxchange.jcontactsbusiness.CompanyBasicData;
 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
 import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice;
 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
@@ -42,27 +41,30 @@ import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jcontactsbusiness.BusinessBasicData;
 
 /**
  * A POJO for company departments
  * <p>
- * @author Roland Haeder
+ * @author Roland Häder<roland@mxchange.org>
  */
 @Entity (name = "company_departments")
 @Table (name = "company_departments")
-public class CompanyDepartment implements Department, Comparable<Department> {
+@SuppressWarnings ("PersistenceUnitPresent")
+public class CompanyDepartment implements Department {
 
        /**
         * Serial number
         */
+       @Transient
        private static final long serialVersionUID = 94_835_918_958_717_660L;
 
        /**
-        * Connection to company contact
+        * Where this department is located
         */
-       @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
-       @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
-       private BusinessContact departmentCompany;
+       @JoinColumn (name = "department_headquarters_id")
+       @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
+       private HeadQuartersData departentHeadquarters;
 
        /**
         * Where this department is located
@@ -72,25 +74,33 @@ public class CompanyDepartment implements Department, Comparable<Department> {
        private BranchOffice departmentBranchOffice;
 
        /**
-        * Where this department is located
+        * Connection to company contact
         */
-       @JoinColumn (name = "department_headquarters_id")
-       @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
-       private HeadQuartersData departentHeadquarters;
+       @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
+       @ManyToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
+       private BusinessBasicData departmentCompany;
+
+       /**
+        * Timestamp when this entry has been created
+        */
+       @Basic (optional = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "department_entry_created", nullable = false, updatable = false)
+       private Calendar departmentCreated;
 
        /**
         * Id number
         */
        @Id
        @GeneratedValue (strategy = GenerationType.IDENTITY)
-       @Column (name = "department_id", length = 20, nullable = false, updatable = false)
+       @Column (name = "department_id", nullable = false, updatable = false)
        private Long departmentId;
 
        /**
         * Department lead employee
         */
        @JoinColumn (name = "department_lead_id", nullable = false)
-       @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+       @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
        private Employee departmentLead;
 
        /**
@@ -104,16 +114,29 @@ public class CompanyDepartment implements Department, Comparable<Department> {
         * User owner instance
         */
        @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
        private User departmentUserOwner;
 
-       /**
-        * Timestamp when this entry has been created
-        */
-       @Basic (optional = false)
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "department_entry_created", nullable = false, updatable = false)
-       private Calendar departmentCreated;
+       @Override
+       public boolean equals (final Object object) {
+               if (null == object) {
+                       return false;
+               } else if (this.getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final Department other = (Department) object;
+
+               if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) {
+                       return false;
+               } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
+                       return false;
+               } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
+                       return false;
+               }
+
+               return true;
+       }
 
        @Override
        public HeadQuartersData getDepartentHeadquarters () {
@@ -136,15 +159,27 @@ public class CompanyDepartment implements Department, Comparable<Department> {
        }
 
        @Override
-       public BusinessContact getDepartmentCompany () {
+       public BusinessBasicData getDepartmentCompany () {
                return this.departmentCompany;
        }
 
        @Override
-       public void setDepartmentCompany (final BusinessContact departmentCompany) {
+       public void setDepartmentCompany (final BusinessBasicData departmentCompany) {
                this.departmentCompany = departmentCompany;
        }
 
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Calendar getDepartmentCreated () {
+               return this.departmentCreated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setDepartmentCreated (final Calendar departmentCreated) {
+               this.departmentCreated = departmentCreated;
+       }
+
        @Override
        public Long getDepartmentId () {
                return this.departmentId;
@@ -175,16 +210,6 @@ public class CompanyDepartment implements Department, Comparable<Department> {
                this.departmentName = departmentName;
        }
 
-       @Override
-       public Calendar getDepartmentCreated () {
-               return this.departmentCreated;
-       }
-
-       @Override
-       public void setDepartmentCreated (final Calendar departmentCreated) {
-               this.departmentCreated = departmentCreated;
-       }
-
        @Override
        public User getDepartmentUserOwner () {
                return this.departmentUserOwner;
@@ -195,35 +220,15 @@ public class CompanyDepartment implements Department, Comparable<Department> {
                this.departmentUserOwner = departmentUserOwner;
        }
 
-       @Override
-       public int compareTo (final Department department) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-       }
-
-       @Override
-       public boolean equals (final Object object) {
-               if (object == null) {
-                       return false;
-               } else if (getClass() != object.getClass()) {
-                       return false;
-               }
-
-               final Department other = (Department) object;
-
-               if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
-                       return false;
-               } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
-                       return false;
-               }
-
-               return true;
-       }
-
        @Override
        public int hashCode () {
                int hash = 5;
+
+               hash = 53 * hash + Objects.hashCode(this.getDepartmentId());
                hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
                hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
+
                return hash;
        }
+
 }