X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjshopcore%2Fmodel%2Fcategory%2FBaseCategory.java;h=6b2e8245e4df602d37f753322d7b9c7376960c2d;hb=e7a772f50e473e4ce0041d685eef9adc9e7a42c1;hp=493da9b615bff26de0ad1fc975cd1fc0711019ef;hpb=bf1e54a2964e53d7454565b3687a78dd41f9cc6c;p=jproduct-core.git diff --git a/src/org/mxchange/jshopcore/model/category/BaseCategory.java b/src/org/mxchange/jshopcore/model/category/BaseCategory.java index 493da9b..6b2e824 100644 --- a/src/org/mxchange/jshopcore/model/category/BaseCategory.java +++ b/src/org/mxchange/jshopcore/model/category/BaseCategory.java @@ -16,45 +16,61 @@ */ package org.mxchange.jshopcore.model.category; -import java.io.UnsupportedEncodingException; -import java.text.MessageFormat; import java.util.Objects; -import org.mxchange.jshopcore.BaseShopCore; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; /** * A general product category class * - * @author Roland Haeder + * @author Roland Haeder */ -public class BaseCategory extends BaseShopCore implements Category { +@Entity(name = "category") +@Table(name = "category") +public abstract class BaseCategory implements Category, Comparable { + + /** + * Serial number + */ + private static final long serialVersionUID = 38_472_937_685_901L; /** * Id number of category */ - private Long categoryId; + @Id + @GeneratedValue + @Column + private Long id; /** - * Parent category categoryId + * Parent category id */ + @Column(name = "parent_id", length = 20) private Long parentId; /** * Title of category */ + @Basic(optional = false) + @Column(length = 100, nullable = false, unique = true) private String title; /** * Constructor which accepts all database fields * - * @param categoryId Id number of database record + * @param id Id number of database record * @param title Category title - * @param parentId Parent categoryId + * @param parentId Parent id */ - protected BaseCategory (final Long categoryId, final String title, final Long parentId) { + protected BaseCategory (final Long id, final String title, final Long parentId) { // Set all here - this.setCategoryId(categoryId); - this.setTitle(title); - this.setParentId(parentId); + this.id = id; + this.title = title; + this.parentId = parentId; } /** @@ -71,81 +87,68 @@ public class BaseCategory extends BaseShopCore implements Category { */ @Override public int compareTo (final Category category) { - // Trace message - this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N - // category should not be null if (null == category) { throw new NullPointerException("category is null"); //NOI18N } - // Debug message - this.getLogger().debug(MessageFormat.format("this.id={0},category.id={1}", this.getCategoryId(), category.getCategoryId())); //NOI18N - - // Is the categoryId the same? - if (Objects.equals(this.getCategoryId(), category.getCategoryId())) { - // Same categoryId, means same category + // Is the id the same? + if (Objects.equals(this.getId(), category.getId())) { + // Same id, means same category return 0; - } else if (this.getCategoryId() > category.getCategoryId()) { - // This categoryId is larger than compared to + } else if (this.getId() > category.getId()) { + // This id is larger than compared to return -1; } - // The other categoryId is larger + // The other id is larger return 1; } - /** - * Decodes the UTF8-encoded title - * - * @return Decoded title - */ @Override - public final String getDecodedTitle () throws UnsupportedEncodingException { - // Get title - byte[] t = this.getTitle().getBytes(); - - // Decode it - return new String(t, "UTF-8"); //NOI18N + public void copyAll (final Category category) { + // Copy all data + this.setParentId(category.getParentId()); + this.setTitle(category.getTitle()); } /** * Id number of category * - * @return the categoryId + * @return the id */ @Override - public final Long getCategoryId () { - return this.categoryId; + public Long getId () { + return this.id; } /** * Id number of category * - * @param categoryId the categoryId to set + * @param id the id to set */ @Override - public final void setCategoryId (final Long categoryId) { - this.categoryId = categoryId; + public void setId (final Long id) { + this.id = id; } /** - * Parent category categoryId + * Parent category id * * @return the parentId */ @Override - public final Long getParentId () { + public Long getParentId () { return this.parentId; } /** - * Parent category categoryId + * Parent category id * * @param parentId the parentId to set */ @Override - public final void setParentId (final Long parentId) { + public void setParentId (final Long parentId) { this.parentId = parentId; } @@ -155,7 +158,7 @@ public class BaseCategory extends BaseShopCore implements Category { * @return the title */ @Override - public final String getTitle () { + public String getTitle () { return this.title; } @@ -165,7 +168,7 @@ public class BaseCategory extends BaseShopCore implements Category { * @param title the title to set */ @Override - public final void setTitle (final String title) { + public void setTitle (final String title) { this.title = title; } }