From: Roland Häder Date: Sat, 14 Oct 2017 12:49:48 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=67e280617a5bcc782cb8b9d6c2f697ce9d15b693;p=jproduct-core.git Continued: - removed categoryId from constructor as this should *NEVER* be set from outside - @Deprecated added for noticing me to move out copyAll() methods to utility classes as entities should not have "complex" logic (they are basically data containers and equals/hashCode + some constructors is okay) Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jproduct/model/category/ProductCategory.java b/src/org/mxchange/jproduct/model/category/ProductCategory.java index 9348951..43c3ff5 100644 --- a/src/org/mxchange/jproduct/model/category/ProductCategory.java +++ b/src/org/mxchange/jproduct/model/category/ProductCategory.java @@ -34,8 +34,8 @@ import javax.persistence.Transient; *

* @author Roland Häder */ -@Entity (name = "category") -@Table (name = "category") +@Entity (name = "product_category") +@Table (name = "product_category") @SuppressWarnings ("PersistenceUnitPresent") public class ProductCategory implements Category { @@ -70,22 +70,20 @@ public class ProductCategory implements Category { /** * Parent category */ - @JoinColumn (name = "parent_id") + @JoinColumn (name = "category_parent_id", referencedColumnName = "category_id") @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH) private Category parentCategory; /** * Constructor which accepts all database fields *

- * @param categoryId Id number of database record * @param categoryTitle Category categoryTitle * @param parentCategory Parent category * @param categoryShownInStatistics Whether this category is shown in any * statistics */ - public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) { + public ProductCategory (final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) { // Set all here - this.categoryId = categoryId; this.categoryTitle = categoryTitle; this.parentCategory = parentCategory; this.categoryShownInStatistics = categoryShownInStatistics; @@ -98,6 +96,7 @@ public class ProductCategory implements Category { } @Override + @Deprecated public void copyAll (final Category category) { // Copy all data this.setParentCategory(category.getParentCategory()); diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index 1a6e51b..5b91d12 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -37,8 +37,8 @@ import org.mxchange.jproduct.model.category.ProductCategory; * @author Roland Häder * TODO: Find a better name */ -@Entity (name = "products") -@Table (name = "products") +@Entity (name = "generic_products") +@Table (name = "generic_products") @SuppressWarnings ("PersistenceUnitPresent") public class GenericProduct implements Product { @@ -51,13 +51,14 @@ public class GenericProduct implements Product { /** * Availability of product */ + @Basic (optional = false) @Column (name = "product_availability", nullable = false) private Boolean productAvailability; /** * Product productCategory */ - @JoinColumn (name = "category_id", nullable = false, updatable = false) + @JoinColumn (name = "product_category_id", referencedColumnName = "category_id", nullable = false, updatable = false) @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false) private Category productCategory; @@ -92,15 +93,13 @@ public class GenericProduct implements Product { /** * Constructor will all required data *

- * @param productId Id number of product * @param productTitle Name of product * @param productPrice Price * @param productCategory Category instance * @param productAvailability Availability (selectable by customer) */ - public GenericProduct (final Long productId, final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) { + public GenericProduct (final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) { // Set all here - this.productId = productId; this.productTitle = productTitle; this.productPrice = productPrice; this.productCategory = productCategory; @@ -108,6 +107,7 @@ public class GenericProduct implements Product { } @Override + @Deprecated public void copyAll (final Product product) { // Copy all this.setProductAvailability(product.getProductAvailability()); @@ -126,21 +126,17 @@ public class GenericProduct implements Product { return false; } - final Product other = (Product) object; + final Product product = (Product) object; - if (!Objects.equals(this.getProductTitle(), other.getProductTitle())) { + if (!Objects.equals(this.getProductId(), product.getProductId())) { + return false; + } else if (!Objects.equals(this.getProductPrice(), product.getProductPrice())) { + return false; + } else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) { return false; } - return Objects.equals(this.getProductId(), other.getProductId()); - } - - @Override - public int hashCode () { - int hash = 7; - hash = 23 * hash + Objects.hashCode(this.getProductId()); - hash = 23 * hash + Objects.hashCode(this.getProductTitle()); - return hash; + return true; } @Override @@ -193,4 +189,15 @@ public class GenericProduct implements Product { this.productTitle = productTitle; } + @Override + public int hashCode () { + int hash = 7; + + hash = 23 * hash + Objects.hashCode(this.getProductId()); + hash = 23 * hash + Objects.hashCode(this.getProductPrice()); + hash = 23 * hash + Objects.hashCode(this.getProductTitle()); + + return hash; + } + }