]> 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 d89077f6711436beb9a50cd74305a7eda95fc997..65a40c8bf26959643e4a0562e56a23e79217e8a7 100644 (file)
  */
 package org.mxchange.jshopcore.model.category;
 
+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<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 = "title", length = 100, nullable = false, unique = true)
+       private String title;
+
        /**
         * Constructor which accepts all database fields
         *
-        * @param id Id number of database record
+        * @param categoryId Id number of database record
         * @param title Category title
-        * @param parent Parent id
+        * @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 title, final Category parentCategory) {
+               // Set all here
+               this.categoryId = categoryId;
+               this.title = title;
+               this.parentCategory = parentCategory;
        }
 
        /**
@@ -43,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.setTitle(category.getTitle());
+       }
+
+       @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 getTitle () {
+               return this.title;
+       }
+
+       @Override
+       public void setTitle (final String title) {
+               this.title = title;
+       }
 }