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.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jproduct.model.category.Category;
37 import org.mxchange.jproduct.model.category.ProductCategory;
40 * Generic product class
42 * @author Roland Häder<roland@mxchange.org>
43 * TODO: Find a better name
45 @Entity (name = "generic_products")
46 @Table (name = "generic_products")
49 @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
50 @NamedQuery (name = "AllAvailableProducts", query = "SELECT p FROM generic_products AS p WHERE p.productAvailability=TRUE ORDER BY p.productId ASC")
53 @SuppressWarnings ("PersistenceUnitPresent")
54 public class GenericProduct implements Product {
60 private static final long serialVersionUID = 54_578_571_769_283L;
63 * Availability of product
65 @Basic (optional = false)
66 @Column (name = "product_availability", nullable = false)
67 private Boolean productAvailability;
70 * Product productCategory
72 @JoinColumn (name = "product_category_id", referencedColumnName = "category_id", nullable = false, updatable = false)
73 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
74 private Category productCategory;
77 * When this product has been created
79 @Basic (optional = false)
80 @Column (name = "product_created", nullable = false, updatable = false)
81 @Temporal (TemporalType.TIMESTAMP)
82 private Date productCreated;
85 * Gross price of product
87 @Basic (optional = false)
88 @Column (name = "product_gross_price", nullable = false)
89 private Float productGrossPrice;
92 * Id number of product
95 @GeneratedValue (strategy = GenerationType.IDENTITY)
96 @Column (name = "product_id", nullable = false, updatable = false)
97 private Long productId;
100 * Net price of product
102 @Column (name = "product_net_price")
103 private Float productNetPrice;
106 * Tax rate (0-1, by 1=100%)
108 @Column (name = "product_gross_price")
109 private Float productTaxRate;
114 @Basic (optional = false)
115 @Column (name = "product_title", length = 100, nullable = false, unique = true)
116 private String productTitle;
119 * Currency code for both prices
121 private String productCurrencyCode;
124 * Default constructor
126 public GenericProduct () {
130 * Constructor will all required data
132 * @param productTitle Name of product
133 * @param productGrossPrice Product's gross price
134 * @param productCurrencyCode code for both prices
135 * @param productCategory Category instance
136 * @param productAvailability Availability (selectable by customer)
138 public GenericProduct (final String productTitle, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) {
140 this.productTitle = productTitle;
141 this.productGrossPrice = productGrossPrice;
142 this.productCurrencyCode = productCurrencyCode;
143 this.productCategory = productCategory;
144 this.productAvailability = productAvailability;
148 public boolean equals (final Object object) {
149 if (this == object) {
151 } else if (null == object) {
153 } else if (this.getClass() != object.getClass()) {
157 final Product product = (Product) object;
159 if (!Objects.equals(this.getProductId(), product.getProductId())) {
161 } else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) {
169 public Boolean getProductAvailability () {
170 return this.productAvailability;
174 public void setProductAvailability (final Boolean productAvailability) {
175 this.productAvailability = productAvailability;
179 public Category getProductCategory () {
180 return this.productCategory;
184 public void setProductCategory (final Category productCategory) {
185 this.productCategory = productCategory;
189 @SuppressWarnings ("ReturnOfDateField")
190 public Date getProductCreated () {
191 return this.productCreated;
195 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
196 public void setProductCreated (final Date productCreated) {
197 this.productCreated = productCreated;
201 public String getProductCurrencyCode () {
202 return this.productCurrencyCode;
206 public void setProductCurrencyCode (final String productCurrencyCode) {
207 this.productCurrencyCode = productCurrencyCode;
211 public Float getProductGrossPrice () {
212 return this.productGrossPrice;
216 public void setProductGrossPrice (final Float productGrossPrice) {
217 this.productGrossPrice = productGrossPrice;
221 public Long getProductId () {
222 return this.productId;
226 public void setProductId (final Long productId) {
227 this.productId = productId;
231 public Float getProductNetPrice () {
232 return this.productNetPrice;
236 public void setProductNetPrice (final Float productNetPrice) {
237 this.productNetPrice = productNetPrice;
241 public Float getProductTaxRate () {
242 return this.productTaxRate;
246 public void setProductTaxRate (final Float productTaxRate) {
247 this.productTaxRate = productTaxRate;
251 public String getProductTitle () {
252 return this.productTitle;
256 public void setProductTitle (final String productTitle) {
257 this.productTitle = productTitle;
261 public int hashCode () {
264 hash = 23 * hash + Objects.hashCode(this.getProductId());
265 hash = 23 * hash + Objects.hashCode(this.getProductTitle());