]> git.mxchange.org Git - jcustomer-core.git/commitdiff
Continued with JPA:
authorRoland Haeder <roland@mxchange.org>
Wed, 23 Sep 2015 12:44:18 +0000 (14:44 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 23 Sep 2015 12:44:18 +0000 (14:44 +0200)
- added @OneToMany annotation
- also call copyAll() to transfer properties from customer.contact to this.contact in ShopCustomer class
- added method copyAll() for Product + implemented it
- no need for length=x on integers + renamed entity name to all lower-case
- made BaseProduct to an entity
- updated jcoreee.jar
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcoreee.jar
src/org/mxchange/jshopcore/model/category/BaseCategory.java
src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
src/org/mxchange/jshopcore/model/order/ShopOrder.java
src/org/mxchange/jshopcore/model/product/BaseProduct.java
src/org/mxchange/jshopcore/model/product/Product.java

index 93d401de39c53a2d93aaa31e42cad7b2ccac7bb9..ba35a455448e8374b4f25033d5ba05f5b6b7d3f1 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
index aa2757b7c357619f829ed934e9456fa7c85a1808..6b2e8245e4df602d37f753322d7b9c7376960c2d 100644 (file)
@@ -29,7 +29,7 @@ import javax.persistence.Table;
  *
  * @author Roland Haeder<roland@mxchange.org>
  */
-@Entity(name = "Category")
+@Entity(name = "category")
 @Table(name = "category")
 public abstract class BaseCategory implements Category, Comparable<Category> {
 
@@ -43,7 +43,7 @@ public abstract class BaseCategory implements Category, Comparable<Category> {
         */
        @Id
        @GeneratedValue
-       @Column(length = 20)
+       @Column
        private Long id;
 
        /**
index 66953563fc7f36d1eb453a4573b9b07e4c22c966..bf3c2b58de84cea72a8bde51c0e2639b91d59d45 100644 (file)
@@ -102,6 +102,9 @@ public class ShopCustomer implements Customer {
 
        @Override
        public void copyAll (final Customer customer) {
+               // Copy also contact data
+               this.getContact().copyAll(customer.getContact());
+
                // Copy other data
                this.setCustomerConfirmKey(customer.getCustomerConfirmKey());
                this.setCustomerNumber(customer.getCustomerNumber());
index 1af471aad4ed2cf582195f73b63844617f5870f9..814d8ab779185ce87495ce1db380b4d154d5f28d 100644 (file)
@@ -25,6 +25,7 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
@@ -57,6 +58,7 @@ public class ShopOrder implements Orderable {
         * Customer instance
         */
        @Basic (optional = false)
+       @OneToMany
        @JoinColumn (name = "customer_id", nullable = false, updatable = false)
        private Customer customer;
 
index 1120636d7952848ff8d3aeb3c7bbdf70b4bbd74f..2b3d81cb4d521dc3741970e8b1275b0a699f6d4d 100644 (file)
@@ -6,12 +6,20 @@
 package org.mxchange.jshopcore.model.product;
 
 import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
 
 /**
  * A general product class
  *
  * @author Roland Haeder<roland@mxchange.org>
  */
+@Entity(name = "product")
+@Table (name = "products")
 public abstract class BaseProduct implements Product, Comparable<Product> {
 
        /**
@@ -22,26 +30,36 @@ public abstract class BaseProduct implements Product, Comparable<Product> {
        /**
         * Availability of product
         */
+       @Column
        private Boolean available;
 
        /**
         * Product category
         */
+       @Basic(optional = false)
+       @Column(name = "category_id", length = 20, nullable = false)
        private Long categoryId;
 
        /**
         * Id number of product
         */
+       @Id
+       @GeneratedValue
+       @Column
        private Long id;
 
        /**
         * Price of product
         */
+       @Basic(optional = false)
+       @Column(nullable = false)
        private Float price;
 
        /**
         * Title of product
         */
+       @Basic(optional = false)
+       @Column(length = 100, nullable = false)
        private String title;
 
        @Override
@@ -64,6 +82,15 @@ public abstract class BaseProduct implements Product, Comparable<Product> {
                return -1;
        }
 
+       @Override
+       public void copyAll (final Product product) {
+               // Copy all
+               this.setAvailable(product.getAvailable());
+               this.setCategoryId(product.getCategoryId());
+               this.setPrice(product.getPrice());
+               this.setTitle(product.getTitle());
+       }
+
        @Override
        public Boolean getAvailable () {
                return this.available;
index 79b94f98dfe4c7c3a12c6f1509434fd0ce2d4a10..a48499da1c2dd19c9e30592f54bd498290d1285a 100644 (file)
@@ -24,6 +24,14 @@ import java.io.Serializable;
  * @author Roland Haeder<roland@mxchange.org>
  */
 public interface Product extends Serializable {
+
+       /**
+        * Copies all properties from source product to this.
+        *
+        * @param product Source product
+        */
+       public void copyAll (final Product product);
+
        /**
         * Getter for id number, suitable for form fields.
         *