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.Id;
25 import javax.persistence.Table;
28 * A general product category class
30 * @author Roland Haeder<roland@mxchange.org>
32 @Entity(name = "category")
33 @Table(name = "category")
34 public abstract class BaseCategory implements Category, Comparable<Category> {
39 private static final long serialVersionUID = 38_472_937_685_901L;
42 * Id number of category
52 @Column(name = "parent_id", length = 20)
53 private Long parentId;
58 @Basic(optional = false)
59 @Column(length = 100, nullable = false, unique = true)
63 * Constructor which accepts all database fields
65 * @param id Id number of database record
66 * @param title Category title
67 * @param parentId Parent id
69 protected BaseCategory (final Long id, final String title, final Long parentId) {
73 this.parentId = parentId;
79 protected BaseCategory () {
83 * Compares two categories with each other
85 * @param category Category comparator
86 * @return Comparison value
89 public int compareTo (final Category category) {
90 // category should not be null
91 if (null == category) {
92 throw new NullPointerException("category is null"); //NOI18N
95 // Is the id the same?
96 if (Objects.equals(this.getId(), category.getId())) {
97 // Same id, means same category
99 } else if (this.getId() > category.getId()) {
100 // This id is larger than compared to
104 // The other id is larger
109 public void copyAll (final Category category) {
111 this.setParentId(category.getParentId());
112 this.setTitle(category.getTitle());
116 * Id number of category
121 public Long getId () {
126 * Id number of category
128 * @param id the id to set
131 public void setId (final Long id) {
138 * @return the parentId
141 public Long getParentId () {
142 return this.parentId;
148 * @param parentId the parentId to set
151 public void setParentId (final Long parentId) {
152 this.parentId = parentId;
161 public String getTitle () {
168 * @param title the title to set
171 public void setTitle (final String title) {