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 = "products")
41 @Table (name = "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 @Column (name = "product_availability", nullable = false)
55 private Boolean productAvailability;
58 * Product productCategory
60 @JoinColumn (name = "category_id", nullable = false, updatable = false)
61 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
62 private Category productCategory;
65 * Id number of product
68 @GeneratedValue (strategy = GenerationType.IDENTITY)
69 @Column (name = "product_id", nullable = false, updatable = false)
70 private Long productId;
75 @Basic (optional = false)
76 @Column (name = "product_price", nullable = false)
77 private Float productPrice;
82 @Basic (optional = false)
83 @Column (name = "product_title", length = 100, nullable = false)
84 private String productTitle;
89 public GenericProduct () {
93 * Constructor will all required data
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)
101 public GenericProduct (final Long productId, final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
103 this.productId = productId;
104 this.productTitle = productTitle;
105 this.productPrice = productPrice;
106 this.productCategory = productCategory;
107 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 other = (Product) object;
131 if (!Objects.equals(this.getProductTitle(), other.getProductTitle())) {
135 return Objects.equals(this.getProductId(), other.getProductId());
139 public int hashCode () {
141 hash = 23 * hash + Objects.hashCode(this.getProductId());
142 hash = 23 * hash + Objects.hashCode(this.getProductTitle());
147 public Boolean getProductAvailability () {
148 return this.productAvailability;
152 public void setProductAvailability (final Boolean productAvailability) {
153 this.productAvailability = productAvailability;
157 public Category getProductCategory () {
158 return this.productCategory;
162 public void setProductCategory (final Category productCategory) {
163 this.productCategory = productCategory;
167 public Long getProductId () {
168 return this.productId;
172 public void setProductId (final Long productId) {
173 this.productId = productId;
177 public Float getProductPrice () {
178 return this.productPrice;
182 public void setProductPrice (final Float productPrice) {
183 this.productPrice = productPrice;
187 public String getProductTitle () {
188 return this.productTitle;
192 public void setProductTitle (final String productTitle) {
193 this.productTitle = productTitle;