From: Roland Haeder Date: Thu, 28 Apr 2016 17:46:50 +0000 (+0200) Subject: ShopCustomer is to generic, better project-specific. And this is now interface-based... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0784118cf9f86329efaf0dc7f0b9a289b5f683b1;p=jproduct-core.git ShopCustomer is to generic, better project-specific. And this is now interface-based (more flexible again) --- diff --git a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java index 6a9950a..7245a9e 100644 --- a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java +++ b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java @@ -127,7 +127,7 @@ public class CustomerUtils extends BaseFrameworkSystem { // Try it try { // Get instance - Customer customer = em.getReference(ShopCustomer.class, customerNumber); + Customer customer = em.getReference(Customer.class, customerNumber); } catch (final EntityNotFoundException ex) { // Not found isFound = false; diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java deleted file mode 100644 index 3fac843..0000000 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2016 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.customer; - -import java.util.Calendar; -import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -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.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcustomercore.model.customer.Customer; -import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus; - -/** - * A shop customer class. - *

- * @author Roland Haeder - */ -@Entity (name = "customer") -@Table (name = "customer") -@SuppressWarnings ("PersistenceUnitPresent") -public class ShopCustomer implements Customer { - - /** - * Serial number - */ - private static final long serialVersionUID = 4_328_454_581_751L; - - /** - * Account status - */ - @Basic (optional = false) - @Column (name = "customer_account_status", nullable = false) - @Enumerated (EnumType.STRING) - private CustomerAccountStatus customerAccountStatus; - - /** - * Confirmation key - */ - @Column (name = "customer_confirm_key", length = 50) - private String customerConfirmKey; - - /** - * Id number from "contacts" table - */ - @JoinColumn (name = "contact_id", nullable = false, updatable = false, unique = true) - @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false) - private Contact customerContact; - - /** - * "created" timestamp - */ - @Basic (optional = false) - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "customer_created", nullable = false) - private Calendar customerCreated; - - /** - * Customer id - */ - @Id - @Column (name = "customer_id", nullable = false, length = 20, updatable = false) - @GeneratedValue (strategy = GenerationType.IDENTITY) - private Long customerId; - - /** - * "locked" timestamp - */ - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "customer_locked_timestamp") - private Calendar customerLocked; - - /** - * Customer number, this is different to the database entry customerId. - */ - @Column (name = "customer_number", nullable = false, length = 20) - private String customerNumber; - - /** - * Password hash - */ - @Column (name = "customer_password_hash") - private String customerPasswordHash; - - /** - * Default constructor - */ - public ShopCustomer () { - } - - @Override - public void copyAll (final Customer customer) { - // Copy also customerContact data - this.getCustomerContact().copyAll(customer.getCustomerContact()); - - // Copy other data - this.setCustomerConfirmKey(customer.getCustomerConfirmKey()); - this.setCustomerNumber(customer.getCustomerNumber()); - this.setCustomerPasswordHash(customer.getCustomerPasswordHash()); - this.setCustomerAccountStatus(customer.getCustomerAccountStatus()); - this.setCustomerCreated(customer.getCustomerCreated()); - this.setCustomerLocked(customer.getCustomerLocked()); - } - - @Override - public boolean equals (final Object object) { - if (this == object) { - return true; - } else if (null == object) { - return false; - } else if (this.getClass() != object.getClass()) { - return false; - } - - final Customer other = (Customer) object; - - if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) { - return false; - } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) { - return false; - } - - return Objects.equals(this.getCustomerContact(), other.getCustomerContact()); - } - - @Override - public int hashCode () { - int hash = 3; - hash = 17 * hash + Objects.hashCode(this.getCustomerContact()); - hash = 17 * hash + Objects.hashCode(this.getCustomerId()); - hash = 17 * hash + Objects.hashCode(this.getCustomerNumber()); - return hash; - } - - @Override - public CustomerAccountStatus getCustomerAccountStatus () { - return this.customerAccountStatus; - } - - @Override - public void setCustomerAccountStatus (final CustomerAccountStatus customerAccountStatus) { - this.customerAccountStatus = customerAccountStatus; - } - - @Override - public String getCustomerConfirmKey () { - return this.customerConfirmKey; - } - - @Override - public void setCustomerConfirmKey (final String customerConfirmKey) { - this.customerConfirmKey = customerConfirmKey; - } - - @Override - public Contact getCustomerContact () { - return this.customerContact; - } - - @Override - public void setCustomerContact (final Contact customerContact) { - this.customerContact = customerContact; - } - - @Override - public Calendar getCustomerCreated () { - return this.customerCreated; - } - - @Override - public void setCustomerCreated (final Calendar customerCreated) { - this.customerCreated = customerCreated; - } - - @Override - public Long getCustomerId () { - return this.customerId; - } - - @Override - public void setCustomerId (final Long customerId) { - this.customerId = customerId; - } - - @Override - public Calendar getCustomerLocked () { - return this.customerLocked; - } - - @Override - public void setCustomerLocked (final Calendar customerLocked) { - this.customerLocked = customerLocked; - } - - @Override - public String getCustomerNumber () { - return this.customerNumber; - } - - @Override - public void setCustomerNumber (final String customerNumber) { - this.customerNumber = customerNumber; - } - - @Override - public String getCustomerPasswordHash () { - return this.customerPasswordHash; - } - - @Override - public void setCustomerPasswordHash (final String customerPasswordHash) { - this.customerPasswordHash = customerPasswordHash; - } - -} diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index 904cd97..ce6d88f 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -34,7 +34,6 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcustomercore.model.customer.Customer; import org.mxchange.jshopcore.model.basket.AddableBasketItem; -import org.mxchange.jshopcore.model.customer.ShopCustomer; /** * An entity class for shop orders @@ -43,6 +42,7 @@ import org.mxchange.jshopcore.model.customer.ShopCustomer; */ @Entity (name = "orders") @Table (name = "orders") +@SuppressWarnings ("PersistenceUnitPresent") public class ShopOrder implements Orderable { /** @@ -61,7 +61,7 @@ public class ShopOrder implements Orderable { * Customer instance */ @JoinColumn (name = "customer_id", nullable = false, updatable = false) - @OneToOne (targetEntity = ShopCustomer.class, cascade = CascadeType.REFRESH, optional = false) + @OneToOne (targetEntity = Customer.class, cascade = CascadeType.REFRESH, optional = false) private Customer customer; /**