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.jcontactsbusiness.model.basicdata.BasicData;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
38 import org.mxchange.jproduct.model.category.Category;
39 import org.mxchange.jproduct.model.category.ProductCategory;
42 * Generic product class
44 * @author Roland Häder<roland@mxchange.org>
45 * TODO: Find a better name
47 @Entity (name = "generic_products")
48 @Table (name = "generic_products")
51 @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
52 @NamedQuery (name = "AllAvailableProducts", query = "SELECT p FROM generic_products AS p WHERE p.productAvailability=TRUE ORDER BY p.productId ASC")
55 @SuppressWarnings ("PersistenceUnitPresent")
56 public class GenericProduct implements Product {
62 private static final long serialVersionUID = 54_578_571_769_283L;
65 * Availability of product
67 @Basic (optional = false)
68 @Column (name = "product_availability", nullable = false)
69 private Boolean productAvailability;
72 * Product productCategory
74 @JoinColumn (name = "product_category_id", referencedColumnName = "category_id", nullable = false, updatable = false)
75 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
76 private Category productCategory;
79 * When this product has been created
81 @Basic (optional = false)
82 @Column (name = "product_created", nullable = false, updatable = false)
83 @Temporal (TemporalType.TIMESTAMP)
84 private Date productCreated;
87 * Currency code for both prices, like EUR or USD
89 @Basic (optional = false)
90 @Column (name = "product_currency_code", nullable = false, length = 3)
91 private String productCurrencyCode;
94 * Gross price of product
96 @Basic (optional = false)
97 @Column (name = "product_gross_price", nullable = false)
98 private Float productGrossPrice;
101 * I18n key of product
103 @Basic (optional = false)
104 @Column (name = "product_i18n_key", length = 100, nullable = false, unique = true)
105 private String productI18nKey;
108 * Id number of product
111 @GeneratedValue (strategy = GenerationType.IDENTITY)
112 @Column (name = "product_id", nullable = false, updatable = false)
113 private Long productId;
116 * The company that has manufactured/produced this product
118 @JoinColumn (name = "product_manufacturer_id", referencedColumnName = "company_data_id")
119 @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH)
120 private BasicData productManfacturer;
123 * Net price of product
125 @Column (name = "product_net_price")
126 private Float productNetPrice;
129 * Tax rate (0-1, by 1=100%)
131 @Column (name = "product_tax_rate")
132 private Float productTaxRate;
135 * Amount of this product (for example 1 for 1 liter)
137 @Column (name = "product_unit_amount")
138 private Float productUnitAmount;
141 * Unit type (for example liter)
143 @Column (name = "product_unit_type")
144 private String productUnitType;
147 * Default constructor
149 public GenericProduct () {
153 * Constructor will all required data
155 * @param productI18nKey I18n key of product
156 * @param productGrossPrice Product's gross price
157 * @param productCurrencyCode code for both prices
158 * @param productCategory Category instance
159 * @param productAvailability Availability (selectable by customer)
161 public GenericProduct (final String productI18nKey, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) {
163 this.productI18nKey = productI18nKey;
164 this.productGrossPrice = productGrossPrice;
165 this.productCurrencyCode = productCurrencyCode;
166 this.productCategory = productCategory;
167 this.productAvailability = productAvailability;
171 public boolean equals (final Object object) {
172 if (this == object) {
174 } else if (null == object) {
176 } else if (this.getClass() != object.getClass()) {
180 final Product product = (Product) object;
182 if (!Objects.equals(this.getProductId(), product.getProductId())) {
184 } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) {
192 public Boolean getProductAvailability () {
193 return this.productAvailability;
197 public void setProductAvailability (final Boolean productAvailability) {
198 this.productAvailability = productAvailability;
202 public Category getProductCategory () {
203 return this.productCategory;
207 public void setProductCategory (final Category productCategory) {
208 this.productCategory = productCategory;
212 @SuppressWarnings ("ReturnOfDateField")
213 public Date getProductCreated () {
214 return this.productCreated;
218 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
219 public void setProductCreated (final Date productCreated) {
220 this.productCreated = productCreated;
224 public String getProductCurrencyCode () {
225 return this.productCurrencyCode;
229 public void setProductCurrencyCode (final String productCurrencyCode) {
230 this.productCurrencyCode = productCurrencyCode;
234 public Float getProductGrossPrice () {
235 return this.productGrossPrice;
239 public void setProductGrossPrice (final Float productGrossPrice) {
240 this.productGrossPrice = productGrossPrice;
244 public String getProductI18nKey () {
245 return this.productI18nKey;
249 public void setProductI18nKey (final String productI18nKey) {
250 this.productI18nKey = productI18nKey;
254 public Long getProductId () {
255 return this.productId;
259 public void setProductId (final Long productId) {
260 this.productId = productId;
264 public BasicData getProductManfacturer () {
265 return this.productManfacturer;
269 public void setProductManfacturer (final BasicData productManfacturer) {
270 this.productManfacturer = productManfacturer;
274 public Float getProductNetPrice () {
275 return this.productNetPrice;
279 public void setProductNetPrice (final Float productNetPrice) {
280 this.productNetPrice = productNetPrice;
284 public Float getProductTaxRate () {
285 return this.productTaxRate;
289 public void setProductTaxRate (final Float productTaxRate) {
290 this.productTaxRate = productTaxRate;
294 public Float getProductUnitAmount () {
295 return this.productUnitAmount;
299 public void setProductUnitAmount (final Float productUnitAmount) {
300 this.productUnitAmount = productUnitAmount;
304 public String getProductUnitType () {
305 return this.productUnitType;
309 public void setProductUnitType (final String productUnitType) {
310 this.productUnitType = productUnitType;
314 public int hashCode () {
317 hash = 23 * hash + Objects.hashCode(this.getProductId());
318 hash = 23 * hash + Objects.hashCode(this.getProductI18nKey());