From: Roland Haeder Date: Tue, 22 Sep 2015 14:06:15 +0000 (+0200) Subject: JPA started X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e3ec2da66bc09d08c0ad866c8476d8d00feee647;p=jcustomer-core.git JPA started Signed-off-by:Roland Häder --- diff --git a/lib/jcore.jar b/lib/jcore.jar index 12190be..ead5916 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index e0c8236..93d401d 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java b/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java index ae77abe..eb93d49 100644 --- a/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java +++ b/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java @@ -37,6 +37,6 @@ public class CustomerAlreadyRegisteredException extends Exception { */ public CustomerAlreadyRegisteredException (final Customer customer) { // Call super contructor - super(MessageFormat.format("Customer {0} already registered with number {1} at record id {2}. Maybe forgot to call isRegistered(customer) ?", customer, customer.getCustomerNumber(), customer.getId())); + super(MessageFormat.format("Customer {0} already registered with number {1} at record id {2}. Maybe forgot to call isRegistered(customer) ?", customer, customer.getCustomerNumber(), customer.getCustomerId())); } } diff --git a/src/org/mxchange/jshopcore/model/customer/Customer.java b/src/org/mxchange/jshopcore/model/customer/Customer.java index 792d639..d3a1620 100644 --- a/src/org/mxchange/jshopcore/model/customer/Customer.java +++ b/src/org/mxchange/jshopcore/model/customer/Customer.java @@ -123,4 +123,18 @@ public interface Customer extends Contact { * @param customerStatus Account status */ public void setCustomerStatus (final String customerStatus); + + /** + * Getter for customer id number + * + * @return Customer id number + */ + public Long getCustomerId (); + + /** + * Settte for customer id number + * + * @param customerId Customer id number + */ + public void setCustomerId (final Long customerId); } diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 509c06c..9b8331b 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -17,6 +17,17 @@ package org.mxchange.jshopcore.model.customer; import java.sql.Timestamp; +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; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import org.mxchange.jcore.model.contact.BaseContact; /** @@ -24,45 +35,68 @@ import org.mxchange.jcore.model.contact.BaseContact; * * @author Roland Haeder */ +@Entity (name = "Customer") +@Table (name = "customer") public class ShopCustomer extends BaseContact implements Customer { + + /** + * Serial number + */ + private static final long serialVersionUID = 4_328_454_581_751L; + /** - * Id number from "contact" table + * Customer id */ + @Id + @Column (name = "id", nullable = false, length = 20) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long customerId; + + /** + * Id number from "contacts" table + */ + @JoinColumn (table = "contacts", unique = true) + @OneToOne (optional = false, targetEntity = BaseContact.class, orphanRemoval = true) + @Column (name = "customer_contact_id", nullable = false, length = 20) private long contactId; /** * Confirmation key */ + @Column (name = "customer_confirm_key", length = 50) private String customerConfirmKey; /** * "created" timestamp */ + @Basic(optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "customer_created", nullable = false) private Timestamp customerCreated; /** * "locked" timestamp */ + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "customer_locked") private Timestamp customerLocked; /** - * Customer number, this is different to the database entry id. + * Customer number, this is different to the database entry customerId. */ + @Column (name = "customer_number", nullable = false, length = 20) private String customerNumber; - /** - * Serial number - */ - private static final long serialVersionUID = 4_328_454_581_751L; - /** * Password hash */ + @Column (name = "customer_password_hash") private String customerPasswordHash; /** * Account status */ + @Column (name = "customer_status", nullable = false) private String customerStatus; @Override @@ -134,4 +168,14 @@ public class ShopCustomer extends BaseContact implements Customer { public void setCustomerStatus (final String customerStatus) { this.customerStatus = customerStatus; } + + @Override + public Long getCustomerId () { + return this.customerId; + } + + @Override + public void setCustomerId (final Long customerId) { + this.customerId = customerId; + } } diff --git a/src/org/mxchange/jshopcore/model/order/Orderable.java b/src/org/mxchange/jshopcore/model/order/Orderable.java new file mode 100644 index 0000000..93f75ff --- /dev/null +++ b/src/org/mxchange/jshopcore/model/order/Orderable.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jshopcore.model.order; + +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * An interface for customer orders + * + * @author Roland Haeder + */ +public interface Orderable extends Serializable { + + /** + * Getter for order id + * + * @return Order id + */ + public Long getId (); + + /** + * Setter for order id + * + * @param id Order id + */ + public void setId (final Long id); + + /** + * Getter for customer id + * + * @return Customer id + */ + public Long getCustomerId (); + + /** + * Setter for customer id + * + * @param customerId Customer id + */ + public void setCustomerId (final Long customerId); + + /** + * Getter for created timestamp + * + * @return Created timestamp + */ + public Timestamp getCreated (); + + /** + * Setter for created timestamp + * + * @param created Created timestamp + */ + public void setCreated (final Timestamp created); +} diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java new file mode 100644 index 0000000..65361ee --- /dev/null +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jshopcore.model.order; + +import java.sql.Timestamp; +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.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/** + * An entity class for shop orders + * + * @author Roland Haeder + */ +@Entity (name = "Orders") +@Table (name = "orders") +public class ShopOrder implements Orderable { + + /** + * Serial number + */ + private static final long serialVersionUID = 19_728_938_459_834L; + + /** + * Order id + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long id; + + /** + * Customer id + */ + @Basic (optional = false) + @Column (name = "customer_id", length = 20, nullable = false) + private Long customerId; + + /** + * Access key + */ + @Basic (optional = false) + @Column (name = "access_key", length = 100, nullable = false, unique = true) + private String accessKey; + + /** + * Created timestamp + */ + @Basic (optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (nullable = false) + private Timestamp created; + + @Override + public Timestamp getCreated () { + return this.created; + } + + @Override + public void setCreated (final Timestamp created) { + this.created = created; + } + + @Override + public Long getCustomerId () { + return this.customerId; + } + + @Override + public void setCustomerId (final Long customerId) { + this.customerId = customerId; + } + + @Override + public Long getId () { + return this.id; + } + + @Override + public void setId (final Long id) { + this.id = id; + } +}