]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 14 Oct 2017 12:49:48 +0000 (14:49 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 14 Oct 2017 13:19:30 +0000 (15:19 +0200)
- 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 <roland@mxchange.org>
src/org/mxchange/jproduct/model/category/ProductCategory.java
src/org/mxchange/jproduct/model/product/GenericProduct.java

index 9348951a2bef7d69569c47c5add2091e3b8f90f1..43c3ff5ea6e9bca2c064e3f3d7308f3b18b9904c 100644 (file)
@@ -34,8 +34,8 @@ import javax.persistence.Transient;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@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
         * <p>
-        * @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());
index 1a6e51b7e5dd509e6dab0cf0af39cceb5e7ff6c0..5b91d123b05696a9065d1e03c4cefed5cf69a017 100644 (file)
@@ -37,8 +37,8 @@ import org.mxchange.jproduct.model.category.ProductCategory;
  * @author Roland Häder<roland@mxchange.org>
  * 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
         * <p>
-        * @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;
+       }
+
 }