/*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016 Roland Haeder
*
* 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
import java.util.Objects;
import javax.persistence.Basic;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
/**
* A product category
- *
+ * <p>
* @author Roland Haeder<roland@mxchange.org>
*/
@Entity (name = "category")
@Table (name = "category")
-public class ProductCategory implements Category, Comparable<Category> {
+public class ProductCategory implements Category {
/**
* Serial number
*/
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
- @Column (name = "category_id", length = 20, nullable = false)
+ @Column (name = "category_id", nullable = false)
private Long categoryId;
/**
- * Parent category categoryId
+ * Title of category
*/
- @JoinColumn (name = "parent_id")
- @OneToOne (targetEntity = ProductCategory.class)
- private Category parentCategory;
+ @Basic (optional = false)
+ @Column (name = "category_title", length = 100, nullable = false, unique = true)
+ private String categoryTitle;
/**
- * Title of category
+ * Parent category
*/
- @Basic (optional = false)
- @Column (name = "title", length = 100, nullable = false, unique = true)
- private String title;
+ @JoinColumn (name = "parent_id")
+ @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
+ private Category parentCategory;
/**
* Constructor which accepts all database fields
- *
- * @param categoryId Id number of database record
- * @param title Category title
+ * <p>
+ * @param categoryId Id number of database record
+ * @param categoryTitle Category categoryTitle
* @param parentCategory Parent category
*/
- public ProductCategory (final Long categoryId, final String title, final Category parentCategory) {
+ public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
// Set all here
this.categoryId = categoryId;
- this.title = title;
+ this.categoryTitle = categoryTitle;
this.parentCategory = parentCategory;
}
}
@Override
- public int compareTo (final Category category) {
- // category should not be null
- if (null == category) {
- throw new NullPointerException("category is null"); //NOI18N
+ public void copyAll (final Category category) {
+ // Copy all data
+ this.setParentCategory(category.getParentCategory());
+ this.setCategoryTitle(category.getCategoryTitle());
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (this == object) {
+ return true;
+ } else if (null == object) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
}
- // Is the categoryId the same?
- if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
- // Same categoryId, means same category
- return 0;
- } else if (this.getCategoryId() > category.getCategoryId()) {
- // This categoryId is larger than compared to
- return -1;
+ final Category other = (Category) object;
+
+ if (!Objects.equals(this.getCategoryTitle(), other.getCategoryTitle())) {
+ return false;
+ } else if (!Objects.equals(this.getCategoryId(), other.getCategoryId())) {
+ return false;
}
- // The other categoryId is larger
- return 1;
+ return true;
}
@Override
- public void copyAll (final Category category) {
- // Copy all data
- this.setParentCategory(category.getParentCategory());
- this.setTitle(category.getTitle());
+ public int hashCode () {
+ int hash = 7;
+ hash = 13 * hash + Objects.hashCode(this.getCategoryId());
+ hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());
+ return hash;
}
@Override
}
@Override
- public Category getParentCategory () {
- return this.parentCategory;
+ public String getCategoryTitle () {
+ return this.categoryTitle;
}
@Override
- public void setParentCategory (final Category parentCategory) {
- this.parentCategory = parentCategory;
+ public void setCategoryTitle (final String categoryTitle) {
+ this.categoryTitle = categoryTitle;
}
@Override
- public String getTitle () {
- return this.title;
+ public Category getParentCategory () {
+ return this.parentCategory;
}
@Override
- public void setTitle (final String title) {
- this.title = title;
+ public void setParentCategory (final Category parentCategory) {
+ this.parentCategory = parentCategory;
}
+
}