2 * Copyright (C) 2015 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.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.JoinColumn;
27 import javax.persistence.OneToOne;
28 import javax.persistence.Table;
33 * @author Roland Haeder<roland@mxchange.org>
35 @Entity (name = "category")
36 @Table (name = "category")
37 public class ProductCategory implements Category, Comparable<Category> {
42 private static final long serialVersionUID = 21_458_945_712_659L;
45 * Id number of category
48 @GeneratedValue (strategy = GenerationType.IDENTITY)
49 @Column (name = "category_id", length = 20, nullable = false)
50 private Long categoryId;
55 @JoinColumn (name = "parent_id")
56 @OneToOne (targetEntity = ProductCategory.class)
57 private Category parentCategory;
62 @Basic (optional = false)
63 @Column (name = "category_title", length = 100, nullable = false, unique = true)
64 private String categoryTitle;
67 * Constructor which accepts all database fields
69 * @param categoryId Id number of database record
70 * @param categoryTitle Category categoryTitle
71 * @param parentCategory Parent category
73 public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
75 this.categoryId = categoryId;
76 this.categoryTitle = categoryTitle;
77 this.parentCategory = parentCategory;
83 public ProductCategory () {
87 public int compareTo (final Category category) {
88 // category should not be null
89 if (null == category) {
90 throw new NullPointerException("category is null"); //NOI18N
93 // Is the categoryId the same?
94 if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
95 // Same categoryId, means same category
97 } else if (this.getCategoryId() > category.getCategoryId()) {
98 // This categoryId is larger than compared to
102 // The other categoryId is larger
107 public void copyAll (final Category category) {
109 this.setParentCategory(category.getParentCategory());
110 this.setCategoryTitle(category.getCategoryTitle());
114 public Long getCategoryId () {
115 return this.categoryId;
119 public void setCategoryId (final Long categoryId) {
120 this.categoryId = categoryId;
124 public Category getParentCategory () {
125 return this.parentCategory;
129 public void setParentCategory (final Category parentCategory) {
130 this.parentCategory = parentCategory;
134 public String getCategoryTitle () {
135 return this.categoryTitle;
139 public void setCategoryTitle (final String categoryTitle) {
140 this.categoryTitle = categoryTitle;