2 * Copyright (C) 2016 Roland Haeder
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.jshopcore.model.category;
19 import java.util.Objects;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToOne;
29 import javax.persistence.Table;
34 * @author Roland Haeder<roland@mxchange.org>
36 @Entity (name = "category")
37 @Table (name = "category")
38 public class ProductCategory implements Category, Comparable<Category> {
43 private static final long serialVersionUID = 21_458_945_712_659L;
46 * Id number of category
49 @GeneratedValue (strategy = GenerationType.IDENTITY)
50 @Column (name = "category_id", length = 20, nullable = false)
51 private Long categoryId;
56 @Basic (optional = false)
57 @Column (name = "category_title", length = 100, nullable = false, unique = true)
58 private String categoryTitle;
63 @JoinColumn (name = "parent_id")
64 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
65 private Category parentCategory;
68 * Constructor which accepts all database fields
70 * @param categoryId Id number of database record
71 * @param categoryTitle Category categoryTitle
72 * @param parentCategory Parent category
74 public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
76 this.categoryId = categoryId;
77 this.categoryTitle = categoryTitle;
78 this.parentCategory = parentCategory;
84 public ProductCategory () {
88 public int compareTo (final Category category) {
89 // category should not be null
90 if (null == category) {
91 throw new NullPointerException("category is null"); //NOI18N
94 // Is the categoryId the same?
95 if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
96 // Same categoryId, means same category
98 } else if (this.getCategoryId() > category.getCategoryId()) {
99 // This categoryId is larger than compared to
103 // The other categoryId is larger
108 public void copyAll (final Category category) {
110 this.setParentCategory(category.getParentCategory());
111 this.setCategoryTitle(category.getCategoryTitle());
115 public Long getCategoryId () {
116 return this.categoryId;
120 public void setCategoryId (final Long categoryId) {
121 this.categoryId = categoryId;
125 public String getCategoryTitle () {
126 return this.categoryTitle;
130 public void setCategoryTitle (final String categoryTitle) {
131 this.categoryTitle = categoryTitle;
135 public Category getParentCategory () {
136 return this.parentCategory;
140 public void setParentCategory (final Category parentCategory) {
141 this.parentCategory = parentCategory;