From: Roland Häder Date: Thu, 19 Jan 2023 04:24:42 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=737ef830fc1ec12af2755120713fc0e4cb45595d;p=jjobs-core.git Continued: - added event class and interface when an administrator adds a new skill - added exception when a skill wasn't found - renamed skill_ to skill_entry_* - added named query AllSkills --- diff --git a/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java new file mode 100644 index 0000000..d364627 --- /dev/null +++ b/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.events.skill.add; + +import java.text.MessageFormat; +import org.mxchange.jjobs.model.skill.Skillable; + +/** + * An event being fired when an administrator has added a new skill + *

+ * @author Roland Häder + */ +public class AdminAddedSkillEvent implements ObservableAdminAddedSkillEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 14_785_787_174_600_001L; + + /** + * Instance of added skillable + */ + private final Skillable skillable; + + /** + * Constrcutor with skill instance + *

+ * @param skillable An instance of a Skillable class + */ + public AdminAddedSkillEvent (final Skillable skillable) { + // Validate parameter + if (null == skillable) { + // Throw NPE + throw new NullPointerException("Parameter 'skillable' is null"); //NOI18N + } else if (skillable.getSkillId() == null) { + // Throw it again + throw new NullPointerException("skillable.skillId is null"); //NOI18N + } else if (skillable.getSkillId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("skillable.skillId={0} is invalid", skillable.getSkillId())); //NOI18N + } + + // Set it here + this.skillable = skillable; + } + + @Override + public Skillable getSkillable () { + return this.skillable; + } +} diff --git a/src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java new file mode 100644 index 0000000..851bc83 --- /dev/null +++ b/src/org/mxchange/jjobs/events/skill/add/ObservableAdminAddedSkillEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2023 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.events.skill.add; + +import java.io.Serializable; +import org.mxchange.jjobs.model.skill.Skillable; + +/** + * An interface for events being fired when an administrator has added a skill + *

+ * @author Roland Häder + */ +public interface ObservableAdminAddedSkillEvent extends Serializable { + + /** + * Getter for Skillable class field + *

+ * @return An instance of a Skillable class + */ + Skillable getSkillable (); + +} diff --git a/src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java b/src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java new file mode 100644 index 0000000..1cf8687 --- /dev/null +++ b/src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.model.exceptions; + +import java.text.MessageFormat; + +/** + * An exception thrown when a Skillable instance wasn't found + *

+ * @author Roland Häder + */ +public class SkillNotFoundException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 42_895_928_956_700_001L; + + /** + * Constructor with primary key + *

+ * @param skillId Primary key + */ + public SkillNotFoundException (final Long skillId) { + super(MessageFormat.format("Skill id {0} not found.", skillId)); //NOI18N + } + +} diff --git a/src/org/mxchange/jjobs/model/skill/JobSkill.java b/src/org/mxchange/jjobs/model/skill/JobSkill.java index f479d10..26e18cd 100644 --- a/src/org/mxchange/jjobs/model/skill/JobSkill.java +++ b/src/org/mxchange/jjobs/model/skill/JobSkill.java @@ -26,6 +26,8 @@ import javax.persistence.Enumerated; 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; @@ -44,6 +46,9 @@ import org.mxchange.jjobs.model.skill.status.SkillStatus; @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 { @@ -57,9 +62,16 @@ public class JobSkill implements Skillable { * 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) @@ -91,13 +103,6 @@ public class JobSkill implements Skillable { @Column (name = "skill_status", nullable = false) private SkillStatus skillStatus; - /** - * When this entry has been updated - */ - @Column (name = "skill_updated", insertable = false) - @Temporal (TemporalType.TIMESTAMP) - private Date skillUpdated; - /** * Default constructor, required for the JPA. */ @@ -183,14 +188,26 @@ public class JobSkill implements Skillable { @Override @SuppressWarnings ("ReturnOfDateField") - public Date getSkillCreated () { - return this.skillCreated; + public Date getSkillEntryCreated () { + return this.skillEntryCreated; } @Override @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setSkillCreated (final Date skillCreated) { - this.skillCreated = skillCreated; + public void setSkillEntryCreated (final Date skillEntryCreated) { + this.skillEntryCreated = skillEntryCreated; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Date getSkillEntryUpdated () { + return this.skillEntryUpdated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setSkillEntryUpdated (final Date skillEntryUpdated) { + this.skillEntryUpdated = skillEntryUpdated; } @Override @@ -235,18 +252,6 @@ public class JobSkill implements Skillable { 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; diff --git a/src/org/mxchange/jjobs/model/skill/Skillable.java b/src/org/mxchange/jjobs/model/skill/Skillable.java index 3ebc780..a51a538 100644 --- a/src/org/mxchange/jjobs/model/skill/Skillable.java +++ b/src/org/mxchange/jjobs/model/skill/Skillable.java @@ -60,28 +60,28 @@ public interface Skillable extends Comparable, Serializable { *

* @return Skill created timestamp */ - Date getSkillCreated (); + Date getSkillEntryCreated (); /** * Setter for skill created timestamp *

* @param skillCreated Skill created timestamp */ - void setSkillCreated (final Date skillCreated); + void setSkillEntryCreated (final Date skillCreated); /** * Getter for skill updated timestamp *

* @return Skill updated timestamp */ - Date getSkillUpdated (); + Date getSkillEntryUpdated (); /** * Setter for skill updated timestamp *

* @param skillUpdated Skill updated timestamp */ - void setSkillUpdated (final Date skillUpdated); + void setSkillEntryUpdated (final Date skillUpdated); /** * Getter for skill last locked timestamp