]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/model/category/ProductCategory.java
Continued:
[jproduct-core.git] / src / org / mxchange / jproduct / model / category / ProductCategory.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jproduct.model.category;
18
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;
36
37 /**
38  * A product category
39  * <p>
40  * @author Roland Häder<roland@mxchange.org>
41  */
42 @Entity (name = "product_category")
43 @Table (name = "product_category")
44 @NamedQueries (
45                 {
46                         @NamedQuery (name = "AllProductCategories", query = "SELECT pc FROM product_category AS pc ORDER BY pc.categoryId ASC")
47                 }
48 )
49 @SuppressWarnings ("PersistenceUnitPresent")
50 public class ProductCategory implements Category {
51
52         /**
53          * Serial number
54          */
55         @Transient
56         private static final long serialVersionUID = 21_458_945_712_659L;
57
58         /**
59          * When this entry has been created
60          */
61         @Basic (optional = false)
62         @Column (name = "category_created", updatable = false, nullable = false)
63         @Temporal (TemporalType.TIMESTAMP)
64         private Date categoryCreated;
65
66         /**
67          * Id number of category
68          */
69         @Id
70         @GeneratedValue (strategy = GenerationType.IDENTITY)
71         @Column (name = "category_id", nullable = false)
72         private Long categoryId;
73
74         /**
75          * Whether this category is shown in any statistics
76          */
77         @Basic (optional = false)
78         @Column (name = "category_in_statistics", nullable = false)
79         private Boolean categoryShownInStatistics;
80
81         /**
82          * Title of category
83          */
84         @Basic (optional = false)
85         @Column (name = "category_title", length = 100, nullable = false, unique = true)
86         private String categoryTitle;
87
88         /**
89          * Parent category
90          */
91         @JoinColumn (name = "category_parent_id", referencedColumnName = "category_id")
92         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
93         private Category parentCategory;
94
95         /**
96          * Constructor which accepts all database fields
97          * <p>
98          * @param categoryTitle             Category categoryTitle
99          * @param parentCategory            Parent category
100          * @param categoryShownInStatistics Whether this category is shown in any
101          *                                  statistics
102          */
103         public ProductCategory (final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) {
104                 // Call other constructor
105                 this();
106
107                 // Set all here
108                 this.categoryTitle = categoryTitle;
109                 this.parentCategory = parentCategory;
110                 this.categoryShownInStatistics = categoryShownInStatistics;
111         }
112
113         /**
114          * Default constructor
115          */
116         public ProductCategory () {
117         }
118
119         @Override
120         public boolean equals (final Object object) {
121                 if (this == object) {
122                         return true;
123                 } else if (null == object) {
124                         return false;
125                 } else if (this.getClass() != object.getClass()) {
126                         return false;
127                 }
128
129                 final Category category = (Category) object;
130
131                 if (!Objects.equals(this.getCategoryTitle(), category.getCategoryTitle())) {
132                         return false;
133                 } else if (!Objects.equals(this.getCategoryId(), category.getCategoryId())) {
134                         return false;
135                 }
136
137                 return true;
138         }
139
140         @Override
141         @SuppressWarnings ("ReturnOfDateField")
142         public Date getCategoryCreated () {
143                 return this.categoryCreated;
144         }
145
146         @Override
147         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
148         public void setCategoryCreated (final Date categoryCreated) {
149                 this.categoryCreated = categoryCreated;
150         }
151
152         @Override
153         public Long getCategoryId () {
154                 return this.categoryId;
155         }
156
157         @Override
158         public void setCategoryId (final Long categoryId) {
159                 this.categoryId = categoryId;
160         }
161
162         @Override
163         public Boolean getCategoryShownInStatistics () {
164                 return this.categoryShownInStatistics;
165         }
166
167         @Override
168         public void setCategoryShownInStatistics (final Boolean categoryShownInStatistics) {
169                 this.categoryShownInStatistics = categoryShownInStatistics;
170         }
171
172         @Override
173         public String getCategoryTitle () {
174                 return this.categoryTitle;
175         }
176
177         @Override
178         public void setCategoryTitle (final String categoryTitle) {
179                 this.categoryTitle = categoryTitle;
180         }
181
182         @Override
183         public Category getParentCategory () {
184                 return this.parentCategory;
185         }
186
187         @Override
188         public void setParentCategory (final Category parentCategory) {
189                 this.parentCategory = parentCategory;
190         }
191
192         @Override
193         public int hashCode () {
194                 int hash = 7;
195
196                 hash = 13 * hash + Objects.hashCode(this.getCategoryId());
197                 hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());
198
199                 return hash;
200         }
201
202 }