2 * Copyright (C) 2016, 2017 Roland Häder
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.jproduct.model.category;
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
40 * @author Roland Häder<roland@mxchange.org>
42 @Entity (name = "product_category")
43 @Table (name = "product_category")
46 @NamedQuery (name = "AllProductCategories", query = "SELECT pc FROM product_category AS pc ORDER BY pc.categoryId ASC")
49 @SuppressWarnings ("PersistenceUnitPresent")
50 public class ProductCategory implements Category {
56 private static final long serialVersionUID = 21_458_945_712_659L;
59 * When this entry has been created
61 @Basic (optional = false)
62 @Column (name = "category_created", updatable = false, nullable = false)
63 @Temporal (TemporalType.TIMESTAMP)
64 private Date categoryCreated;
67 * Id number of category
70 @GeneratedValue (strategy = GenerationType.IDENTITY)
71 @Column (name = "category_id", nullable = false)
72 private Long categoryId;
75 * Whether this category is shown in any statistics
77 @Basic (optional = false)
78 @Column (name = "category_in_statistics", nullable = false)
79 private Boolean categoryShownInStatistics;
84 @Basic (optional = false)
85 @Column (name = "category_title", length = 100, nullable = false, unique = true)
86 private String categoryTitle;
91 @JoinColumn (name = "category_parent_id", referencedColumnName = "category_id")
92 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
93 private Category parentCategory;
96 * Constructor which accepts all database fields
98 * @param categoryTitle Category categoryTitle
99 * @param parentCategory Parent category
100 * @param categoryShownInStatistics Whether this category is shown in any
103 public ProductCategory (final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) {
104 // Call other constructor
108 this.categoryTitle = categoryTitle;
109 this.parentCategory = parentCategory;
110 this.categoryShownInStatistics = categoryShownInStatistics;
114 * Default constructor
116 public ProductCategory () {
120 public boolean equals (final Object object) {
121 if (this == object) {
123 } else if (null == object) {
125 } else if (this.getClass() != object.getClass()) {
129 final Category category = (Category) object;
131 if (!Objects.equals(this.getCategoryTitle(), category.getCategoryTitle())) {
133 } else if (!Objects.equals(this.getCategoryId(), category.getCategoryId())) {
141 @SuppressWarnings ("ReturnOfDateField")
142 public Date getCategoryCreated () {
143 return this.categoryCreated;
147 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
148 public void setCategoryCreated (final Date categoryCreated) {
149 this.categoryCreated = categoryCreated;
153 public Long getCategoryId () {
154 return this.categoryId;
158 public void setCategoryId (final Long categoryId) {
159 this.categoryId = categoryId;
163 public Boolean getCategoryShownInStatistics () {
164 return this.categoryShownInStatistics;
168 public void setCategoryShownInStatistics (final Boolean categoryShownInStatistics) {
169 this.categoryShownInStatistics = categoryShownInStatistics;
173 public String getCategoryTitle () {
174 return this.categoryTitle;
178 public void setCategoryTitle (final String categoryTitle) {
179 this.categoryTitle = categoryTitle;
183 public Category getParentCategory () {
184 return this.parentCategory;
188 public void setParentCategory (final Category parentCategory) {
189 this.parentCategory = parentCategory;
193 public int hashCode () {
196 hash = 13 * hash + Objects.hashCode(this.getCategoryId());
197 hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());