]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/category/ProductCategory.java
Cleanup:
[jproduct-core.git] / src / org / mxchange / jshopcore / model / category / ProductCategory.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
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.jshopcore.model.category;
18
19 import javax.persistence.Basic;
20 import javax.persistence.CascadeType;
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;
29
30 /**
31  * A product category
32  * <p>
33  * @author Roland Haeder<roland@mxchange.org>
34  */
35 @Entity (name = "category")
36 @Table (name = "category")
37 public class ProductCategory implements Category {
38
39         /**
40          * Serial number
41          */
42         private static final long serialVersionUID = 21_458_945_712_659L;
43
44         /**
45          * Id number of category
46          */
47         @Id
48         @GeneratedValue (strategy = GenerationType.IDENTITY)
49         @Column (name = "category_id", length = 20, nullable = false)
50         private Long categoryId;
51
52         /**
53          * Title of category
54          */
55         @Basic (optional = false)
56         @Column (name = "category_title", length = 100, nullable = false, unique = true)
57         private String categoryTitle;
58
59         /**
60          * Parent category
61          */
62         @JoinColumn (name = "parent_id")
63         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
64         private Category parentCategory;
65
66         /**
67          * Constructor which accepts all database fields
68          * <p>
69          * @param categoryId Id number of database record
70          * @param categoryTitle Category categoryTitle
71          * @param parentCategory Parent category
72          */
73         public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
74                 // Set all here
75                 this.categoryId = categoryId;
76                 this.categoryTitle = categoryTitle;
77                 this.parentCategory = parentCategory;
78         }
79
80         /**
81          * Default constructor
82          */
83         public ProductCategory () {
84         }
85
86         @Override
87         public void copyAll (final Category category) {
88                 // Copy all data
89                 this.setParentCategory(category.getParentCategory());
90                 this.setCategoryTitle(category.getCategoryTitle());
91         }
92
93         @Override
94         public Long getCategoryId () {
95                 return this.categoryId;
96         }
97
98         @Override
99         public void setCategoryId (final Long categoryId) {
100                 this.categoryId = categoryId;
101         }
102
103         @Override
104         public String getCategoryTitle () {
105                 return this.categoryTitle;
106         }
107
108         @Override
109         public void setCategoryTitle (final String categoryTitle) {
110                 this.categoryTitle = categoryTitle;
111         }
112
113         @Override
114         public Category getParentCategory () {
115                 return this.parentCategory;
116         }
117
118         @Override
119         public void setParentCategory (final Category parentCategory) {
120                 this.parentCategory = parentCategory;
121         }
122 }