]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/model/product/GenericProduct.java
Continued:
[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 = "generic_products")
41 @Table (name = "generic_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         @Basic (optional = false)
55         @Column (name = "product_availability", nullable = false)
56         private Boolean productAvailability;
57
58         /**
59          * Product productCategory
60          */
61         @JoinColumn (name = "product_category_id", referencedColumnName = "category_id", nullable = false, updatable = false)
62         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
63         private Category productCategory;
64
65         /**
66          * Id number of product
67          */
68         @Id
69         @GeneratedValue (strategy = GenerationType.IDENTITY)
70         @Column (name = "product_id", nullable = false, updatable = false)
71         private Long productId;
72
73         /**
74          * Price of product
75          */
76         @Basic (optional = false)
77         @Column (name = "product_price", nullable = false)
78         private Float productPrice;
79
80         /**
81          * Title of product
82          */
83         @Basic (optional = false)
84         @Column (name = "product_title", length = 100, nullable = false)
85         private String productTitle;
86
87         /**
88          * Default constructor
89          */
90         public GenericProduct () {
91         }
92
93         /**
94          * Constructor will all required data
95          * <p>
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 String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
102                 // Set all here
103                 this.productTitle = productTitle;
104                 this.productPrice = productPrice;
105                 this.productCategory = productCategory;
106                 this.productAvailability = productAvailability;
107         }
108
109         @Override
110         @Deprecated
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 product = (Product) object;
130
131                 if (!Objects.equals(this.getProductId(), product.getProductId())) {
132                         return false;
133                 } else if (!Objects.equals(this.getProductPrice(), product.getProductPrice())) {
134                         return false;
135                 } else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) {
136                         return false;
137                 }
138
139                 return true;
140         }
141
142         @Override
143         public Boolean getProductAvailability () {
144                 return this.productAvailability;
145         }
146
147         @Override
148         public void setProductAvailability (final Boolean productAvailability) {
149                 this.productAvailability = productAvailability;
150         }
151
152         @Override
153         public Category getProductCategory () {
154                 return this.productCategory;
155         }
156
157         @Override
158         public void setProductCategory (final Category productCategory) {
159                 this.productCategory = productCategory;
160         }
161
162         @Override
163         public Long getProductId () {
164                 return this.productId;
165         }
166
167         @Override
168         public void setProductId (final Long productId) {
169                 this.productId = productId;
170         }
171
172         @Override
173         public Float getProductPrice () {
174                 return this.productPrice;
175         }
176
177         @Override
178         public void setProductPrice (final Float productPrice) {
179                 this.productPrice = productPrice;
180         }
181
182         @Override
183         public String getProductTitle () {
184                 return this.productTitle;
185         }
186
187         @Override
188         public void setProductTitle (final String productTitle) {
189                 this.productTitle = productTitle;
190         }
191
192         @Override
193         public int hashCode () {
194                 int hash = 7;
195
196                 hash = 23 * hash + Objects.hashCode(this.getProductId());
197                 hash = 23 * hash + Objects.hashCode(this.getProductPrice());
198                 hash = 23 * hash + Objects.hashCode(this.getProductTitle());
199
200                 return hash;
201         }
202
203 }