2 * Copyright (C) 2015 Roland Haeder
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.jshopcore.model.product;
19 import java.util.Objects;
20 import javax.persistence.Basic;
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 import org.mxchange.jshopcore.model.category.Category;
30 import org.mxchange.jshopcore.model.category.ProductCategory;
33 * Generic product class
35 * @author Roland Haeder<roland@mxchange.org>
36 * TODO: Find a better name
38 @Entity (name = "products")
39 @Table (name = "products")
40 public class GenericProduct implements Product, Comparable<Product> {
45 private static final long serialVersionUID = 54_578_571_769_283L;
48 * Availability of product
50 @Column (name = "product_availability", nullable = false)
51 private Boolean productAvailability;
54 * Product productCategory
56 @JoinColumn (name = "category_id", nullable = false, updatable = false)
57 @OneToOne (targetEntity = ProductCategory.class, optional = false)
58 private Category productCategory;
61 * Id number of product
64 @GeneratedValue (strategy = GenerationType.IDENTITY)
65 @Column (name = "product_id", length = 20, nullable = false, updatable = false)
66 private Long productId;
71 @Basic (optional = false)
72 @Column (name = "product_price", nullable = false)
73 private Float productPrice;
78 @Basic (optional = false)
79 @Column (name = "product_title", length = 100, nullable = false)
80 private String productTitle;
85 public GenericProduct () {
89 * Constructor will all required data
91 * @param productId Id number of product
92 * @param productTitle Name of product
93 * @param productPrice Price
94 * @param productCategory Category instance
95 * @param productAvailability Availability (selectable by customer)
97 public GenericProduct (final Long productId, final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
99 this.productId = productId;
100 this.productTitle = productTitle;
101 this.productPrice = productPrice;
102 this.productCategory = productCategory;
103 this.productAvailability = productAvailability;
107 public int compareTo (final Product product) {
108 // productCategory should not be null
109 if (null == product) {
110 throw new NullPointerException("product is null"); //NOI18N
113 // Is the productId the same?
114 if (Objects.equals(this.getProductId(), product.getProductId())) {
115 // Same productId, means same productCategory
117 } else if (this.getProductId() > product.getProductId()) {
118 // This productId is larger than compared to
122 // The other productId is larger
127 public void copyAll (final Product product) {
129 this.setProductAvailability(product.getProductAvailability());
130 this.setProductCategory(product.getProductCategory());
131 this.setProductPrice(product.getProductPrice());
132 this.setProductTitle(product.getProductTitle());
136 public Boolean getProductAvailability () {
137 return this.productAvailability;
141 public void setProductAvailability (final Boolean productAvailability) {
142 this.productAvailability = productAvailability;
146 public Category getProductCategory () {
147 return this.productCategory;
151 public void setProductCategory (final Category productCategory) {
152 this.productCategory = productCategory;
156 public Long getProductId () {
157 return this.productId;
161 public void setProductId (final Long productId) {
162 this.productId = productId;
166 public Float getProductPrice () {
167 return this.productPrice;
171 public void setProductPrice (final Float productPrice) {
172 this.productPrice = productPrice;
176 public String getProductTitle () {
177 return this.productTitle;
181 public void setProductTitle (final String productTitle) {
182 this.productTitle = productTitle;