]> git.mxchange.org Git - jcustomer-core.git/blobdiff - src/org/mxchange/jshopcore/model/category/ProductCategory.java
Continued:
[jcustomer-core.git] / src / org / mxchange / jshopcore / model / category / ProductCategory.java
index cfd56f8830b4934260327ec56d4e2dbf15d6fa46..3b0923e8f50cba5e749e604d3bf2ec70c262975a 100644 (file)
  */
 package org.mxchange.jshopcore.model.category;
 
-import org.mxchange.jshopcore.model.category.BaseCategory;
-import org.mxchange.jshopcore.model.category.BaseCategory;
+import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
 
 /**
  * A product category
- * @author Roland Haeder
+ *
+ * @author Roland Haeder<roland@mxchange.org>
  */
-public class ProductCategory extends BaseCategory {
+@Entity (name = "category")
+@Table (name = "category")
+public class ProductCategory implements Category, Comparable<Category> {
+
        /**
         * Serial number
         */
        private static final long serialVersionUID = 21_458_945_712_659L;
 
+       /**
+        * Id number of category
+        */
+       @Id
+       @GeneratedValue (strategy = GenerationType.IDENTITY)
+       @Column (name = "category_id", length = 20, nullable = false)
+       private Long categoryId;
+
+       /**
+        * Parent category categoryId
+        */
+       @JoinColumn (name = "parent_id")
+       @OneToOne (targetEntity = ProductCategory.class)
+       private Category parentCategory;
+
+       /**
+        * Title of category
+        */
+       @Basic (optional = false)
+       @Column (name = "category_title", length = 100, nullable = false, unique = true)
+       private String categoryTitle;
+
        /**
         * Constructor which accepts all database fields
-        * @param id Id number of database record
-        * @param title Category title
-        * @param parent Parent id
+        *
+        * @param categoryId Id number of database record
+        * @param categoryTitle Category categoryTitle
+        * @param parentCategory Parent category
         */
-       public ProductCategory (final Long id, final String title, final Long parent) {
-               // Call parent constructor
-               super(id, title, parent);
+       public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
+               // Set all here
+               this.categoryId = categoryId;
+               this.categoryTitle = categoryTitle;
+               this.parentCategory = parentCategory;
        }
 
        /**
@@ -45,4 +82,61 @@ public class ProductCategory extends BaseCategory {
         */
        public ProductCategory () {
        }
+
+       @Override
+       public int compareTo (final Category category) {
+               // category should not be null
+               if (null == category) {
+                       throw new NullPointerException("category is null"); //NOI18N
+               }
+
+               // Is the categoryId the same?
+               if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
+                       // Same categoryId, means same category
+                       return 0;
+               } else if (this.getCategoryId() > category.getCategoryId()) {
+                       // This categoryId is larger than compared to
+                       return -1;
+               }
+
+               // The other categoryId is larger
+               return 1;
+       }
+
+       @Override
+       public void copyAll (final Category category) {
+               // Copy all data
+               this.setParentCategory(category.getParentCategory());
+               this.setCategoryTitle(category.getCategoryTitle());
+       }
+
+       @Override
+       public Long getCategoryId () {
+               return this.categoryId;
+       }
+
+       @Override
+       public void setCategoryId (final Long categoryId) {
+               this.categoryId = categoryId;
+       }
+
+       @Override
+       public Category getParentCategory () {
+               return this.parentCategory;
+       }
+
+       @Override
+       public void setParentCategory (final Category parentCategory) {
+               this.parentCategory = parentCategory;
+       }
+
+       @Override
+       public String getCategoryTitle () {
+               return this.categoryTitle;
+       }
+
+       @Override
+       public void setCategoryTitle (final String categoryTitle) {
+               this.categoryTitle = categoryTitle;
+       }
 }