/*
- * Copyright (C) 2016 - 2020 Free Software Foundation
+ * Copyright (C) 2016 - 2024 Free Software Foundation
*
* 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
*/
package org.mxchange.jjobs.model.skill;
-import org.mxchange.jjobs.model.skill.status.SkillStatus;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.enums.EnumUtils;
+import org.mxchange.jjobs.model.skill.status.SkillStatus;
/**
* A POJO entity for skills
@Table (
name = "skills"
)
+@NamedQueries (
+ @NamedQuery (name = "AllSkills", query = "SELECT s FROM skills AS s ORDER BY s.skillId")
+)
@SuppressWarnings ("PersistenceUnitPresent")
public class JobSkill implements Skillable {
* Serial number
*/
@Transient
- private static final long serialVersionUID = 185435718692L;
+ private static final long serialVersionUID = 185_435_718_692L;
/**
* When this entry has been created
*/
@Basic (optional = false)
- @Column (name = "skill_created", nullable = false, updatable = false)
+ @Column (name = "skill_entry_created", nullable = false, updatable = false)
@Temporal (TemporalType.TIMESTAMP)
- private Date skillCreated;
+ private Date skillEntryCreated;
+
+ /**
+ * When this entry has been updated
+ */
+ @Column (name = "skill_entry_updated", insertable = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ private Date skillEntryUpdated;
/**
* Id number (primary key)
private SkillStatus skillStatus;
/**
- * When this entry has been updated
+ * Default constructor, required for the JPA.
*/
- @Column (name = "skill_updated", insertable = false)
- @Temporal (TemporalType.TIMESTAMP)
- private Date skillUpdated;
+ public JobSkill () {
+ // Nothing to do here
+ }
+
+ /**
+ * Constructor with required fields
+ * <p>
+ * @param skillName Name of skill
+ * @param skillStatus Status
+ */
+ public JobSkill (final String skillName, final SkillStatus skillStatus) {
+ // Call default constructor (always and regardless)
+ this();
+
+ // Validate parameter
+ if (null == skillName) {
+ // Throw NPE
+ throw new NullPointerException("skillName is null"); //NOI18N
+ } else if (skillName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("skillName is empty"); //NOI18N
+ } else if (null == skillStatus) {
+ // Throw NPE
+ throw new NullPointerException("skillStatus is null"); //NOI18N
+ }
+
+ // Set fields
+ this.skillName = skillName;
+ this.skillStatus = skillStatus;
+ }
+
+ @Override
+ public int compareTo (final Skillable skill) {
+ // Checkparameter and return 0 if equal
+ if (null == skill) {
+ // Should not happen
+ throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
+ } else if (Objects.equals(this, skill)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparitors
+ final int comparitors[] = {
+ // First compare status
+ EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
+ // ... next name
+ StringUtils.compare(this.getSkillName(), skill.getSkillName())
+ };
+
+ // Check all values
+ final int comparison = ComparableUtils.checkAll(comparitors);
+
+ // Return value
+ return comparison;
+ }
@Override
public boolean equals (final Object object) {
return false;
}
- final Skillable other = (Skillable) object;
+ final Skillable skill = (Skillable) object;
- if (!Objects.equals(this.getSkillName(), other.getSkillName())) {
+ if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
+ return false;
+ } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
return false;
- } else if (!Objects.equals(this.getSkillId(), other.getSkillId())) {
+ } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
return false;
}
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Date getSkillCreated () {
- return this.skillCreated;
+ public Date getSkillEntryCreated () {
+ return this.skillEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setSkillEntryCreated (final Date skillEntryCreated) {
+ this.skillEntryCreated = skillEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getSkillEntryUpdated () {
+ return this.skillEntryUpdated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setSkillCreated (final Date skillCreated) {
- this.skillCreated = skillCreated;
+ public void setSkillEntryUpdated (final Date skillEntryUpdated) {
+ this.skillEntryUpdated = skillEntryUpdated;
}
@Override
this.skillStatus = skillStatus;
}
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getSkillUpdated () {
- return this.skillUpdated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setSkillUpdated (final Date skillUpdated) {
- this.skillUpdated = skillUpdated;
- }
-
@Override
public int hashCode () {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.getSkillId());
hash = 97 * hash + Objects.hashCode(this.getSkillName());
+ hash = 97 * hash + Objects.hashCode(this.getSkillStatus());
return hash;
}