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.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.apache.commons.lang3.StringUtils;
36 import org.mxchange.jcoreutils.comparable.ComparableUtils;
37 import org.mxchange.jcoreutils.enums.EnumUtils;
38 import org.mxchange.jjobs.model.skill.status.SkillStatus;
41 * A POJO entity for skills
43 * @author Roland Häder<roland@mxchange.org>
45 @Entity (name = "skills")
50 @NamedQuery (name = "AllSkills", query = "SELECT s FROM skills AS s ORDER BY s.skillId")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class JobSkill implements Skillable {
59 private static final long serialVersionUID = 185435718692L;
62 * When this entry has been created
64 @Basic (optional = false)
65 @Column (name = "skill_entry_created", nullable = false, updatable = false)
66 @Temporal (TemporalType.TIMESTAMP)
67 private Date skillEntryCreated;
70 * When this entry has been updated
72 @Column (name = "skill_entry_updated", insertable = false)
73 @Temporal (TemporalType.TIMESTAMP)
74 private Date skillEntryUpdated;
77 * Id number (primary key)
80 @GeneratedValue (strategy = GenerationType.IDENTITY)
81 @Column (name = "skill_id", nullable = false, updatable = false)
85 * When this entry has been last locked
87 @Column (name = "skill_last_locked", insertable = false)
88 @Temporal (TemporalType.TIMESTAMP)
89 private Date skillLastLocked;
94 @Basic (optional = false)
95 @Column (name = "skill_name", nullable = false, unique = true)
96 private String skillName;
101 @Basic (optional = false)
102 @Enumerated (EnumType.STRING)
103 @Column (name = "skill_status", nullable = false)
104 private SkillStatus skillStatus;
107 * Default constructor, required for the JPA.
110 // Nothing to do here
114 * Constructor with required fields
116 * @param skillName Name of skill
117 * @param skillStatus Status
119 public JobSkill (final String skillName, final SkillStatus skillStatus) {
120 // Call default constructor (always and regardless)
123 // Validate parameter
124 if (null == skillName) {
126 throw new NullPointerException("skillName is null"); //NOI18N
127 } else if (skillName.isEmpty()) {
129 throw new IllegalArgumentException("skillName is empty"); //NOI18N
130 } else if (null == skillStatus) {
132 throw new NullPointerException("skillStatus is null"); //NOI18N
136 this.skillName = skillName;
137 this.skillStatus = skillStatus;
141 public int compareTo (final Skillable skill) {
142 // Checkparameter and return 0 if equal
145 throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
146 } else if (Objects.equals(this, skill)) {
152 final int comparitors[] = {
153 // First compare status
154 EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
156 StringUtils.compare(this.getSkillName(), skill.getSkillName())
160 final int comparison = ComparableUtils.checkAll(comparitors);
167 public boolean equals (final Object object) {
168 if (this == object) {
170 } else if (null == object) {
172 } else if (this.getClass() != object.getClass()) {
176 final Skillable skill = (Skillable) object;
178 if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
180 } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
182 } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
190 @SuppressWarnings ("ReturnOfDateField")
191 public Date getSkillEntryCreated () {
192 return this.skillEntryCreated;
196 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
197 public void setSkillEntryCreated (final Date skillEntryCreated) {
198 this.skillEntryCreated = skillEntryCreated;
202 @SuppressWarnings ("ReturnOfDateField")
203 public Date getSkillEntryUpdated () {
204 return this.skillEntryUpdated;
208 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
209 public void setSkillEntryUpdated (final Date skillEntryUpdated) {
210 this.skillEntryUpdated = skillEntryUpdated;
214 public Long getSkillId () {
219 public void setSkillId (final Long skillId) {
220 this.skillId = skillId;
224 @SuppressWarnings ("ReturnOfDateField")
225 public Date getSkillLastLocked () {
226 return this.skillLastLocked;
230 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
231 public void setSkillLastLocked (final Date skillLastLocked) {
232 this.skillLastLocked = skillLastLocked;
236 public String getSkillName () {
237 return this.skillName;
241 public void setSkillName (final String skillName) {
242 this.skillName = skillName;
246 public SkillStatus getSkillStatus () {
247 return this.skillStatus;
251 public void setSkillStatus (final SkillStatus skillStatus) {
252 this.skillStatus = skillStatus;
256 public int hashCode () {
259 hash = 97 * hash + Objects.hashCode(this.getSkillId());
260 hash = 97 * hash + Objects.hashCode(this.getSkillName());
261 hash = 97 * hash + Objects.hashCode(this.getSkillStatus());