]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 23 Oct 2017 20:47:31 +0000 (22:47 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 23 Oct 2017 21:21:30 +0000 (23:21 +0200)
- added created timestamps for category and product
- removed deprecated copyAll() methods, as "complex" methods should be
  implemented outside the entity's class

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jproduct/model/category/Category.java
src/org/mxchange/jproduct/model/category/ProductCategory.java
src/org/mxchange/jproduct/model/product/GenericProduct.java
src/org/mxchange/jproduct/model/product/Product.java

index 51553f76bfa565c98e44dd29cfea545d9452d563..f77dc971d2d3ce09d4c157e2e1a8e9304345d586 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jproduct.model.category;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * An interface for categories
@@ -26,11 +27,18 @@ import java.io.Serializable;
 public interface Category extends Serializable {
 
        /**
-        * Copies all properties from other category to this
+        * Getter for created timestamp
         * <p>
-        * @param category Source category instance
+        * @return Created timestamp
         */
-       void copyAll (final Category category);
+       Date getCategoryCreated ();
+
+       /**
+        * Setter for created timestamp
+        * <p>
+        * @param categoryCreated Created timestamp
+        */
+       void setCategoryCreated (final Date categoryCreated);
 
        /**
         * Id number of category
index 43c3ff5ea6e9bca2c064e3f3d7308f3b18b9904c..029d6f880f5e066b408bfe5c4d71a6ab1a4be084 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jproduct.model.category;
 
+import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
@@ -25,8 +26,12 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 
 /**
@@ -36,6 +41,11 @@ import javax.persistence.Transient;
  */
 @Entity (name = "product_category")
 @Table (name = "product_category")
+@NamedQueries (
+               {
+                       @NamedQuery (name = "AllProductCategories", query = "SELECT pc FROM product_category AS pc ORDER BY pc.categoryId ASC")
+               }
+)
 @SuppressWarnings ("PersistenceUnitPresent")
 public class ProductCategory implements Category {
 
@@ -45,6 +55,14 @@ public class ProductCategory implements Category {
        @Transient
        private static final long serialVersionUID = 21_458_945_712_659L;
 
+       /**
+        * When this entry has been created
+        */
+       @Basic (optional = false)
+       @Column (name = "category_created", updatable = false, nullable = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       private Date categoryCreated;
+
        /**
         * Id number of category
         */
@@ -83,6 +101,9 @@ public class ProductCategory implements Category {
         *                                  statistics
         */
        public ProductCategory (final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) {
+               // Call other constructor
+               this();
+
                // Set all here
                this.categoryTitle = categoryTitle;
                this.parentCategory = parentCategory;
@@ -95,15 +116,6 @@ public class ProductCategory implements Category {
        public ProductCategory () {
        }
 
-       @Override
-       @Deprecated
-       public void copyAll (final Category category) {
-               // Copy all data
-               this.setParentCategory(category.getParentCategory());
-               this.setCategoryTitle(category.getCategoryTitle());
-               this.setCategoryShownInStatistics(category.getCategoryShownInStatistics());
-       }
-
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -114,19 +126,29 @@ public class ProductCategory implements Category {
                        return false;
                }
 
-               final Category other = (Category) object;
+               final Category category = (Category) object;
 
-               if (!Objects.equals(this.getCategoryTitle(), other.getCategoryTitle())) {
+               if (!Objects.equals(this.getCategoryTitle(), category.getCategoryTitle())) {
                        return false;
-               } else if (!Objects.equals(this.getCategoryId(), other.getCategoryId())) {
-                       return false;
-               } else if (!Objects.equals(this.getCategoryShownInStatistics(), other.getCategoryShownInStatistics())) {
+               } else if (!Objects.equals(this.getCategoryId(), category.getCategoryId())) {
                        return false;
                }
 
                return true;
        }
 
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getCategoryCreated () {
+               return this.categoryCreated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setCategoryCreated (final Date categoryCreated) {
+               this.categoryCreated = categoryCreated;
+       }
+
        @Override
        public Long getCategoryId () {
                return this.categoryId;
@@ -170,8 +192,10 @@ public class ProductCategory implements Category {
        @Override
        public int hashCode () {
                int hash = 7;
+
                hash = 13 * hash + Objects.hashCode(this.getCategoryId());
                hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());
+
                return hash;
        }
 
index 5b91d123b05696a9065d1e03c4cefed5cf69a017..2cd7d5e3640beb050a2f2b383dcbf0496044f58f 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jproduct.model.product;
 
+import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
@@ -25,8 +26,12 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.category.ProductCategory;
@@ -39,6 +44,12 @@ import org.mxchange.jproduct.model.category.ProductCategory;
  */
 @Entity (name = "generic_products")
 @Table (name = "generic_products")
+@NamedQueries (
+               {
+                       @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
+                       @NamedQuery (name = "AllAvailableProducts", query = "SELECT p FROM generic_products AS p WHERE p.productAvailability=TRUE ORDER BY p.productId ASC")
+               }
+)
 @SuppressWarnings ("PersistenceUnitPresent")
 public class GenericProduct implements Product {
 
@@ -62,6 +73,14 @@ public class GenericProduct implements Product {
        @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
        private Category productCategory;
 
+       /**
+        * When this product has been created
+        */
+       @Basic(optional = false)
+       @Column(name = "product_created", nullable = false, updatable = false)
+       @Temporal(TemporalType.TIMESTAMP)
+       private Date productCreated;
+
        /**
         * Id number of product
         */
@@ -81,7 +100,7 @@ public class GenericProduct implements Product {
         * Title of product
         */
        @Basic (optional = false)
-       @Column (name = "product_title", length = 100, nullable = false)
+       @Column (name = "product_title", length = 100, nullable = false, unique = true)
        private String productTitle;
 
        /**
@@ -106,16 +125,6 @@ public class GenericProduct implements Product {
                this.productAvailability = productAvailability;
        }
 
-       @Override
-       @Deprecated
-       public void copyAll (final Product product) {
-               // Copy all
-               this.setProductAvailability(product.getProductAvailability());
-               this.setProductCategory(product.getProductCategory());
-               this.setProductPrice(product.getProductPrice());
-               this.setProductTitle(product.getProductTitle());
-       }
-
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -130,8 +139,6 @@ public class GenericProduct implements Product {
 
                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;
                }
@@ -159,6 +166,18 @@ public class GenericProduct implements Product {
                this.productCategory = productCategory;
        }
 
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getProductCreated () {
+               return this.productCreated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setProductCreated (final Date productCreated) {
+               this.productCreated = productCreated;
+       }
+
        @Override
        public Long getProductId () {
                return this.productId;
@@ -194,7 +213,6 @@ public class GenericProduct implements Product {
                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;
index feb532bd8ca06b6a8889e49e690cfd95843b2fa4..b07b2ad70896c462016a513687fd4186004046f8 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jproduct.model.product;
 
 import java.io.Serializable;
+import java.util.Date;
 import org.mxchange.jproduct.model.category.Category;
 
 /**
@@ -27,11 +28,18 @@ import org.mxchange.jproduct.model.category.Category;
 public interface Product extends Serializable {
 
        /**
-        * Copies all properties from source product to this.
+        * Getter for created timestamp
         * <p>
-        * @param product Source product
+        * @return Created timestamp
         */
-       void copyAll (final Product product);
+       Date getProductCreated ();
+
+       /**
+        * Setter for created timestamp
+        * <p>
+        * @param productCreated Created timestamp
+        */
+       void setProductCreated (final Date productCreated);
 
        /**
         * Getter for product availability