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.product;
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;
35 * Generic product class
37 * @author Roland Häder<roland@mxchange.org>
38 * TODO: Find a better name
40 @Entity (name = "generic_products")
41 @Table (name = "generic_products")
42 @SuppressWarnings ("PersistenceUnitPresent")
43 public class GenericProduct implements Product {
49 private static final long serialVersionUID = 54_578_571_769_283L;
52 * Availability of product
54 @Basic (optional = false)
55 @Column (name = "product_availability", nullable = false)
56 private Boolean productAvailability;
59 * Product productCategory
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;
66 * Id number of product
69 @GeneratedValue (strategy = GenerationType.IDENTITY)
70 @Column (name = "product_id", nullable = false, updatable = false)
71 private Long productId;
76 @Basic (optional = false)
77 @Column (name = "product_price", nullable = false)
78 private Float productPrice;
83 @Basic (optional = false)
84 @Column (name = "product_title", length = 100, nullable = false)
85 private String productTitle;
90 public GenericProduct () {
94 * Constructor will all required data
96 * @param productTitle Name of product
97 * @param productPrice Price
98 * @param productCategory Category instance
99 * @param productAvailability Availability (selectable by customer)
101 public GenericProduct (final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
103 this.productTitle = productTitle;
104 this.productPrice = productPrice;
105 this.productCategory = productCategory;
106 this.productAvailability = productAvailability;
111 public void copyAll (final Product product) {
113 this.setProductAvailability(product.getProductAvailability());
114 this.setProductCategory(product.getProductCategory());
115 this.setProductPrice(product.getProductPrice());
116 this.setProductTitle(product.getProductTitle());
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 Product product = (Product) object;
131 if (!Objects.equals(this.getProductId(), product.getProductId())) {
133 } else if (!Objects.equals(this.getProductPrice(), product.getProductPrice())) {
135 } else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) {
143 public Boolean getProductAvailability () {
144 return this.productAvailability;
148 public void setProductAvailability (final Boolean productAvailability) {
149 this.productAvailability = productAvailability;
153 public Category getProductCategory () {
154 return this.productCategory;
158 public void setProductCategory (final Category productCategory) {
159 this.productCategory = productCategory;
163 public Long getProductId () {
164 return this.productId;
168 public void setProductId (final Long productId) {
169 this.productId = productId;
173 public Float getProductPrice () {
174 return this.productPrice;
178 public void setProductPrice (final Float productPrice) {
179 this.productPrice = productPrice;
183 public String getProductTitle () {
184 return this.productTitle;
188 public void setProductTitle (final String productTitle) {
189 this.productTitle = productTitle;
193 public int hashCode () {
196 hash = 23 * hash + Objects.hashCode(this.getProductId());
197 hash = 23 * hash + Objects.hashCode(this.getProductPrice());
198 hash = 23 * hash + Objects.hashCode(this.getProductTitle());