2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.jjobs.model.skill;
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.EnumType;
25 import javax.persistence.Enumerated;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.Table;
30 import javax.persistence.Temporal;
31 import javax.persistence.TemporalType;
32 import javax.persistence.Transient;
33 import org.apache.commons.lang3.StringUtils;
34 import org.mxchange.jcoreutils.comparable.ComparableUtils;
35 import org.mxchange.jcoreutils.enums.EnumUtils;
36 import org.mxchange.jjobs.model.skill.status.SkillStatus;
39 * A POJO entity for skills
41 * @author Roland Häder<roland@mxchange.org>
43 @Entity (name = "skills")
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class JobSkill implements Skillable {
54 private static final long serialVersionUID = 185435718692L;
57 * When this entry has been created
59 @Basic (optional = false)
60 @Column (name = "skill_created", nullable = false, updatable = false)
61 @Temporal (TemporalType.TIMESTAMP)
62 private Date skillCreated;
65 * Id number (primary key)
68 @GeneratedValue (strategy = GenerationType.IDENTITY)
69 @Column (name = "skill_id", nullable = false, updatable = false)
73 * When this entry has been last locked
75 @Column (name = "skill_last_locked", insertable = false)
76 @Temporal (TemporalType.TIMESTAMP)
77 private Date skillLastLocked;
82 @Basic (optional = false)
83 @Column (name = "skill_name", nullable = false, unique = true)
84 private String skillName;
89 @Basic (optional = false)
90 @Enumerated (EnumType.STRING)
91 @Column (name = "skill_status", nullable = false)
92 private SkillStatus skillStatus;
95 * When this entry has been updated
97 @Column (name = "skill_updated", insertable = false)
98 @Temporal (TemporalType.TIMESTAMP)
99 private Date skillUpdated;
102 * Default constructor, required for the JPA.
105 // Nothing to do here
109 * Constructor with required fields
111 * @param skillName Name of skill
112 * @param skillStatus Status
114 public JobSkill (final String skillName, final SkillStatus skillStatus) {
115 // Call default constructor (always and regardless)
118 // Validate parameter
119 if (null == skillName) {
121 throw new NullPointerException("skillName is null"); //NOI18N
122 } else if (skillName.isEmpty()) {
124 throw new IllegalArgumentException("skillName is empty"); //NOI18N
125 } else if (null == skillStatus) {
127 throw new NullPointerException("skillStatus is null"); //NOI18N
131 this.skillName = skillName;
132 this.skillStatus = skillStatus;
136 public int compareTo (final Skillable skill) {
137 // Checkparameter and return 0 if equal
140 throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
141 } else if (Objects.equals(this, skill)) {
147 final int comparitors[] = {
148 // First compare status
149 EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
151 StringUtils.compare(this.getSkillName(), skill.getSkillName())
155 final int comparison = ComparableUtils.checkAll(comparitors);
162 public boolean equals (final Object object) {
163 if (this == object) {
165 } else if (null == object) {
167 } else if (this.getClass() != object.getClass()) {
171 final Skillable skill = (Skillable) object;
173 if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
175 } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
177 } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
185 @SuppressWarnings ("ReturnOfDateField")
186 public Date getSkillCreated () {
187 return this.skillCreated;
191 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
192 public void setSkillCreated (final Date skillCreated) {
193 this.skillCreated = skillCreated;
197 public Long getSkillId () {
202 public void setSkillId (final Long skillId) {
203 this.skillId = skillId;
207 @SuppressWarnings ("ReturnOfDateField")
208 public Date getSkillLastLocked () {
209 return this.skillLastLocked;
213 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
214 public void setSkillLastLocked (final Date skillLastLocked) {
215 this.skillLastLocked = skillLastLocked;
219 public String getSkillName () {
220 return this.skillName;
224 public void setSkillName (final String skillName) {
225 this.skillName = skillName;
229 public SkillStatus getSkillStatus () {
230 return this.skillStatus;
234 public void setSkillStatus (final SkillStatus skillStatus) {
235 this.skillStatus = skillStatus;
239 @SuppressWarnings ("ReturnOfDateField")
240 public Date getSkillUpdated () {
241 return this.skillUpdated;
245 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
246 public void setSkillUpdated (final Date skillUpdated) {
247 this.skillUpdated = skillUpdated;
251 public int hashCode () {
254 hash = 97 * hash + Objects.hashCode(this.getSkillId());
255 hash = 97 * hash + Objects.hashCode(this.getSkillName());
256 hash = 97 * hash + Objects.hashCode(this.getSkillStatus());