From: Roland Häder Date: Sat, 18 Nov 2017 14:27:10 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=44e34bd8334604d6ee37699ce700600b5208bc8b;p=jproduct-core.git Continued: - added product size, like for shoes or clothing - made combination of i18n key, age group and size unique - added AgeGroup enumeration to product entity Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index 508360a..bdbcc0e 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -23,9 +23,12 @@ import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -38,6 +41,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.category.ProductCategory; +import org.mxchange.jproduct.model.product.agegroup.AgeGroup; /** * Generic product class @@ -46,7 +50,16 @@ import org.mxchange.jproduct.model.category.ProductCategory; * TODO: Find a better name */ @Entity (name = "generic_products") -@Table (name = "generic_products") +@Table ( + name = "generic_products", + indexes = { + @Index ( + name = "idx_i18n_age_size", + columnList = "product_i18n_key,product_age_group,product_size", + unique = true + ) + } +) @NamedQueries ( { @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"), @@ -62,6 +75,13 @@ public class GenericProduct implements Product { @Transient private static final long serialVersionUID = 54_578_571_769_283L; + /** + * Product's age group (if any) + */ + @Column (name = "product_age_group") + @Enumerated (EnumType.STRING) + private AgeGroup productAgeGroup; + /** * Availability of product */ @@ -102,7 +122,7 @@ public class GenericProduct implements Product { * I18n key of product */ @Basic (optional = false) - @Column (name = "product_i18n_key", length = 100, nullable = false, unique = true) + @Column (name = "product_i18n_key", length = 100, nullable = false) private String productI18nKey; /** @@ -132,6 +152,12 @@ public class GenericProduct implements Product { @Column (name = "product_number") private Long productNumber; + /** + * Product size (like for shoes, clothing) + */ + @Column (name = "product_size", length = 10) + private String productSize; + /** * Tax rate (0-1, by 1=100%) */ @@ -248,11 +274,25 @@ public class GenericProduct implements Product { return false; } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) { return false; + } else if (!Objects.equals(this.getProductAgeGroup(), product.getProductAgeGroup())) { + return false; + } else if (!Objects.equals(this.getProductSize(), product.getProductSize())) { + return false; } return true; } + @Override + public AgeGroup getProductAgeGroup () { + return this.productAgeGroup; + } + + @Override + public void setProductAgeGroup (final AgeGroup productAgeGroup) { + this.productAgeGroup = productAgeGroup; + } + @Override public Boolean getProductAvailability () { return this.productAvailability; @@ -355,6 +395,16 @@ public class GenericProduct implements Product { this.productNumber = productNumber; } + @Override + public String getProductSize () { + return this.productSize; + } + + @Override + public void setProductSize (final String productSize) { + this.productSize = productSize; + } + @Override public Float getProductTaxRate () { return this.productTaxRate; @@ -391,6 +441,8 @@ public class GenericProduct implements Product { hash = 23 * hash + Objects.hashCode(this.getProductId()); hash = 23 * hash + Objects.hashCode(this.getProductI18nKey()); + hash = 23 * hash + Objects.hashCode(this.getProductAgeGroup()); + hash = 23 * hash + Objects.hashCode(this.getProductSize()); return hash; } diff --git a/src/org/mxchange/jproduct/model/product/Product.java b/src/org/mxchange/jproduct/model/product/Product.java index dce0e96..474b5d3 100644 --- a/src/org/mxchange/jproduct/model/product/Product.java +++ b/src/org/mxchange/jproduct/model/product/Product.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Date; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jproduct.model.category.Category; +import org.mxchange.jproduct.model.product.agegroup.AgeGroup; /** * An interface for in database storable products @@ -210,6 +211,34 @@ public interface Product extends Serializable { */ void setProductNumber (final Long productNumber); + /** + * Getter for product's size + *

+ * @return Product's size + */ + String getProductSize (); + + /** + * Setter for product's size + *

+ * @param productSize Product's size + */ + void setProductSize (final String productSize); + + /** + * Getter for product's age group + *

+ * @return Product's age group + */ + AgeGroup getProductAgeGroup (); + + /** + * Setter for product's age group + *

+ * @param productAgeGroup Product's age group + */ + void setProductAgeGroup (final AgeGroup productAgeGroup); + @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java b/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java new file mode 100644 index 0000000..673e945 --- /dev/null +++ b/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jproduct.model.product.agegroup; + +/** + * An enumeration for age classes + *

+ * @author Roland Haeder + */ +public enum AgeGroup { + + /** + * Age group "new born" + */ + AGE_GROUP_NEWBORN("AGE_GROUP_NEWBORN"), //NOI18N + /** + * Age group "baby" + */ + AGE_GROUP_BABY("AGE_GROUP_BABY"), //NOI18N + /** + * Age group "child" + */ + AGE_GROUP_CHILD("AGE_GROUP_CHILD"), //NOI18N + /** + * Age group "youth" + */ + AGE_GROUP_YOUTH("AGE_GROUP_YOUTH"), //NOI18N + /** + * Age group "adult" + */ + AGE_GROUP_ADULT("AGE_GROUP_ADULT"), //NOI18N + /** + * Age group "senior" + */ + AGE_GROUP_SENIOR("AGE_GROUP_SENIOR"); //NOI18N//NOI18N + + /** + * I18n key for age group/class + */ + private final String i18nKey; + + /** + * Constructor with all enumeration fields + *

+ * @param i18nKey I18n key for age class + */ + private AgeGroup (final String i18nKey) { + // Set all values + this.i18nKey = i18nKey; + } + + /** + * Getter for age group's i18n key + *

+ * @return Age group's i18n key + */ + public String getI18nKey () { + return this.i18nKey; + } + +}