From e7a772f50e473e4ce0041d685eef9adc9e7a42c1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 23 Sep 2015 14:44:18 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20JPA:=20-=20added=20@OneToMany?= =?utf8?q?=20annotation=20-=20also=20call=20copyAll()=20to=20transfer=20pr?= =?utf8?q?operties=20from=20customer.contact=20to=20this.contact=20in=20Sh?= =?utf8?q?opCustomer=20class=20-=20added=20method=20copyAll()=20for=20Prod?= =?utf8?q?uct=20+=20implemented=20it=20-=20no=20need=20for=20length=3Dx=20?= =?utf8?q?on=20integers=20+=20renamed=20entity=20name=20to=20all=20lower-c?= =?utf8?q?ase=20-=20made=20BaseProduct=20to=20an=20entity=20-=20updated=20?= =?utf8?q?jcoreee.jar=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jcoreee.jar | Bin 19254 -> 19203 bytes .../model/category/BaseCategory.java | 4 +-- .../model/customer/ShopCustomer.java | 3 ++ .../jshopcore/model/order/ShopOrder.java | 2 ++ .../jshopcore/model/product/BaseProduct.java | 27 ++++++++++++++++++ .../jshopcore/model/product/Product.java | 8 ++++++ 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 93d401de39c53a2d93aaa31e42cad7b2ccac7bb9..ba35a455448e8374b4f25033d5ba05f5b6b7d3f1 100644 GIT binary patch delta 975 zcmY*YOH30{6g@NjPiDfWv?7JJ{Mt&ZEgDNjuNJEJi%abbe-zS|P)Ox~RPPS3e_UhkdfE860UW=)RS z>;~WlqPKgNt(YyskXf;*-N%r?ub2V~YAL}fEiHIY>l1vV^$R}GQ?yxhP_naz#&wTy z-X104W4p)XH)T+PJGB`jYjO{`h)LX;-?f z(;>m-=!P`96zcwF7sg7@yCqo49tcBALm4$x^kJwxCsr=01k|6)2;RvJ2)@eY1)amA zf-}Ptg0uMmZ4RH4_$9~Te0lz6^Oq{zl%Q3(Ab71XZB>mDZ53wZm*!$XCzIBEt@NLu;Xk$@hIO4?^5T|(_L zwU-iVqC24yNTs(2{&0jpHMRN=%P_7k?3@+xX4XX$Jzjb`T7I?d_W0u`{3)naZJ5j| N!~L<8^Zby?^bZPn&65BC delta 1012 zcmZvbOH31C5Xa}+UHVwJDMeerD%7G-+G1POiX^=3V+%yFc<@9Fno5FAYA|~7fP};Y z7lIRs7orC*TnwhBCK`>2iDKfx$BlTvlQBLno-xihTM12Uv)^xC|Jmv8bbeV>mWAug zsH*7z4uF@Jl1r|T`kc_StV-`gE8}-a0$W6!nHNdsg6L(w5d+K>C5~$uFP>H$?EfUc zKI`1Iqd%@Fr>eOjW`h0&Wmce-%8?000_& zNkt(qc}IwXSQmZ*;t?4N_~_J$05K|!LnB#+RRm4YOr8dNse!@`BIL^kJH$2)oM7Rs zr4&`ApVb2PQIGx5LWOdO7||NyF(_*ku!gYu4E=Y2RtQwZeN-)nb%raTMk=7yG&oL~ zQSRWgs;YxfJsf}_-?)wMc(7)j%J+?TybI-$cgf%vtp*R(u@UKb;bh}S{JX}+#<81L z@kIX?M{pw5Bi9k{rmPLyNX29&8tERUnI2>=q_fOV=@DiiGsc|BOfWxY^33+E<=@I$ z{zmp3$B&xhuA1dTG|zJ8o9S0x8<;m6aZTv>-e|_b9RCs=%lVZ%UQTWL+ORj*z=~%S z?hIDLZv2z$<8c45U&(iDH>%It@nOWXty-mYL!u`AYd8^*L#=Q50`2tol-B?~ */ -@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. * -- 2.39.5