/*
- * Copyright (C) 2015 Roland Haeder
+ * 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
*/
package org.mxchange.jshopcore.model.customer;
-import org.mxchange.jcore.model.contact.BaseContact;
+import java.util.Calendar;
+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.jshopcore.model.customer.status.CustomerAccountStatus;
/**
* A shop customer class.
- *
+ * <p>
* @author Roland Haeder<roland@mxchange.org>
*/
-public class ShopCustomer extends BaseContact implements Customer {
+@Entity (name = "customer")
+@Table (name = "customer")
+public class ShopCustomer implements Customer, Comparable<Customer> {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 4_328_454_581_751L;
+
+ /**
+ * 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 contact;
+
+ /**
+ * 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;
+
+ /**
+ * "created" timestamp
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "customer_created", nullable = false)
+ private Calendar customerCreated;
+
/**
- * Id number from "contact" table
+ * Customer id
*/
- private long contactId;
+ @Id
+ @Column (name = "customer_id", nullable = false, length = 20, updatable = false)
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ private Long customerId;
/**
- * Customer number, this is different to the database entry id.
+ * "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;
/**
- * Serial number
+ * Password hash
*/
- private static final long serialVersionUID = 4_328_454_581_751L;
+ @Column (name = "customer_password_hash")
+ private String customerPasswordHash;
+
+ /**
+ * Default constructor
+ */
+ public ShopCustomer () {
+ }
+
+ @Override
+ public int compareTo (Customer customer) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @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());
+ this.setCustomerPasswordHash(customer.getCustomerPasswordHash());
+ this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
+ this.setCustomerCreated(customer.getCustomerCreated());
+ this.setCustomerLocked(customer.getCustomerLocked());
+ }
+
+ @Override
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ @Override
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ @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 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 long getContactId () {
- return this.contactId;
+ public Calendar getCustomerLocked () {
+ return this.customerLocked;
}
@Override
- public void setContactId (final long contactId) {
- this.contactId = contactId;
+ public void setCustomerLocked (final Calendar customerLocked) {
+ this.customerLocked = customerLocked;
}
@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;
+ }
+
}