]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/model/product/GenericProduct.java
1a6e51b7e5dd509e6dab0cf0af39cceb5e7ff6c0
[jproduct-core.git] / src / org / mxchange / jproduct / model / product / GenericProduct.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.product;
18
19 import java.util.Objects;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToOne;
29 import javax.persistence.Table;
30 import javax.persistence.Transient;
31 import org.mxchange.jproduct.model.category.Category;
32 import org.mxchange.jproduct.model.category.ProductCategory;
33
34 /**
35  * Generic product class
36  * <p>
37  * @author Roland Häder<roland@mxchange.org>
38  * TODO: Find a better name
39  */
40 @Entity (name = "products")
41 @Table (name = "products")
42 @SuppressWarnings ("PersistenceUnitPresent")
43 public class GenericProduct implements Product {
44
45         /**
46          * Serial number
47          */
48         @Transient
49         private static final long serialVersionUID = 54_578_571_769_283L;
50
51         /**
52          * Availability of product
53          */
54         @Column (name = "product_availability", nullable = false)
55         private Boolean productAvailability;
56
57         /**
58          * Product productCategory
59          */
60         @JoinColumn (name = "category_id", nullable = false, updatable = false)
61         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
62         private Category productCategory;
63
64         /**
65          * Id number of product
66          */
67         @Id
68         @GeneratedValue (strategy = GenerationType.IDENTITY)
69         @Column (name = "product_id", nullable = false, updatable = false)
70         private Long productId;
71
72         /**
73          * Price of product
74          */
75         @Basic (optional = false)
76         @Column (name = "product_price", nullable = false)
77         private Float productPrice;
78
79         /**
80          * Title of product
81          */
82         @Basic (optional = false)
83         @Column (name = "product_title", length = 100, nullable = false)
84         private String productTitle;
85
86         /**
87          * Default constructor
88          */
89         public GenericProduct () {
90         }
91
92         /**
93          * Constructor will all required data
94          * <p>
95          * @param productId           Id number of product
96          * @param productTitle        Name of product
97          * @param productPrice        Price
98          * @param productCategory     Category instance
99          * @param productAvailability Availability (selectable by customer)
100          */
101         public GenericProduct (final Long productId, final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
102                 // Set all here
103                 this.productId = productId;
104                 this.productTitle = productTitle;
105                 this.productPrice = productPrice;
106                 this.productCategory = productCategory;
107                 this.productAvailability = productAvailability;
108         }
109
110         @Override
111         public void copyAll (final Product product) {
112                 // Copy all
113                 this.setProductAvailability(product.getProductAvailability());
114                 this.setProductCategory(product.getProductCategory());
115                 this.setProductPrice(product.getProductPrice());
116                 this.setProductTitle(product.getProductTitle());
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 Product other = (Product) object;
130
131                 if (!Objects.equals(this.getProductTitle(), other.getProductTitle())) {
132                         return false;
133                 }
134
135                 return Objects.equals(this.getProductId(), other.getProductId());
136         }
137
138         @Override
139         public int hashCode () {
140                 int hash = 7;
141                 hash = 23 * hash + Objects.hashCode(this.getProductId());
142                 hash = 23 * hash + Objects.hashCode(this.getProductTitle());
143                 return hash;
144         }
145
146         @Override
147         public Boolean getProductAvailability () {
148                 return this.productAvailability;
149         }
150
151         @Override
152         public void setProductAvailability (final Boolean productAvailability) {
153                 this.productAvailability = productAvailability;
154         }
155
156         @Override
157         public Category getProductCategory () {
158                 return this.productCategory;
159         }
160
161         @Override
162         public void setProductCategory (final Category productCategory) {
163                 this.productCategory = productCategory;
164         }
165
166         @Override
167         public Long getProductId () {
168                 return this.productId;
169         }
170
171         @Override
172         public void setProductId (final Long productId) {
173                 this.productId = productId;
174         }
175
176         @Override
177         public Float getProductPrice () {
178                 return this.productPrice;
179         }
180
181         @Override
182         public void setProductPrice (final Float productPrice) {
183                 this.productPrice = productPrice;
184         }
185
186         @Override
187         public String getProductTitle () {
188                 return this.productTitle;
189         }
190
191         @Override
192         public void setProductTitle (final String productTitle) {
193                 this.productTitle = productTitle;
194         }
195
196 }