From: Roland Haeder Date: Wed, 23 Sep 2015 12:44:18 +0000 (+0200) Subject: Continued with JPA: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e7a772f50e473e4ce0041d685eef9adc9e7a42c1;p=jproduct-core.git Continued with JPA: - 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 --- diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 93d401d..ba35a45 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/src/org/mxchange/jshopcore/model/category/BaseCategory.java b/src/org/mxchange/jshopcore/model/category/BaseCategory.java index aa2757b..6b2e824 100644 --- a/src/org/mxchange/jshopcore/model/category/BaseCategory.java +++ b/src/org/mxchange/jshopcore/model/category/BaseCategory.java @@ -29,7 +29,7 @@ import javax.persistence.Table; * * @author Roland Haeder */ -@Entity(name = "Category") +@Entity(name = "category") @Table(name = "category") public abstract class BaseCategory implements Category, Comparable { @@ -43,7 +43,7 @@ public abstract class BaseCategory implements Category, Comparable { */ @Id @GeneratedValue - @Column(length = 20) + @Column private Long id; /** diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 6695356..bf3c2b5 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -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()); diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index 1af471a..814d8ab 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -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; diff --git a/src/org/mxchange/jshopcore/model/product/BaseProduct.java b/src/org/mxchange/jshopcore/model/product/BaseProduct.java index 1120636..2b3d81c 100644 --- a/src/org/mxchange/jshopcore/model/product/BaseProduct.java +++ b/src/org/mxchange/jshopcore/model/product/BaseProduct.java @@ -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 */ +@Entity(name = "product") +@Table (name = "products") public abstract class BaseProduct implements Product, Comparable { /** @@ -22,26 +30,36 @@ public abstract class BaseProduct implements Product, Comparable { /** * 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 { 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; diff --git a/src/org/mxchange/jshopcore/model/product/Product.java b/src/org/mxchange/jshopcore/model/product/Product.java index 79b94f9..a48499d 100644 --- a/src/org/mxchange/jshopcore/model/product/Product.java +++ b/src/org/mxchange/jshopcore/model/product/Product.java @@ -24,6 +24,14 @@ import java.io.Serializable; * @author Roland Haeder */ 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. *