2 * Copyright (C) 2016, 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jshopcore.model.order;
19 import java.util.Calendar;
20 import java.util.List;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jcustomercore.model.customer.Customer;
36 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
39 * An entity class for shop orders
41 * @author Roland Häder<roland@mxchange.org>
43 @Entity (name = "orders")
44 @Table (name = "orders")
45 @SuppressWarnings ("PersistenceUnitPresent")
46 public class ShopOrder implements Orderable {
52 private static final long serialVersionUID = 19_728_938_459_834L;
57 @Basic (optional = false)
58 @Column (name = "access_key", length = 100, nullable = false, unique = true)
59 private String accessKey;
64 @JoinColumn (name = "customer_id", nullable = false, updatable = false)
65 @OneToOne (targetEntity = Customer.class, cascade = CascadeType.REFRESH, optional = false)
66 private Customer customer;
71 @Basic (optional = false)
72 @Temporal (TemporalType.TIMESTAMP)
73 @Column (name = "order_created", nullable = false)
74 private Calendar orderCreated;
80 @GeneratedValue (strategy = GenerationType.IDENTITY)
81 @Column (name = "order_id", length = 20)
85 * Item list, don't save this
88 private List<AddableBasketItem> orderedItems;
91 public boolean equals (final Object object) {
94 } else if (null == object) {
96 } else if (this.getClass() != object.getClass()) {
100 final Orderable other = (Orderable) object;
102 if (!Objects.equals(this.getAccessKey(), other.getAccessKey())) {
104 } else if (!Objects.equals(this.getCustomer(), other.getCustomer())) {
106 } else if (!Objects.equals(this.getOrderId(), other.getOrderId())) {
108 } else if (!Objects.equals(this.getOrderedItems(), other.getOrderedItems())) {
116 public int hashCode () {
118 hash = 61 * hash + Objects.hashCode(this.getAccessKey());
119 hash = 61 * hash + Objects.hashCode(this.getCustomer());
120 hash = 61 * hash + Objects.hashCode(this.getOrderId());
121 hash = 61 * hash + Objects.hashCode(this.getOrderedItems());
126 public String getAccessKey () {
127 return this.accessKey;
131 public void setAccessKey (final String accessKey) {
132 this.accessKey = accessKey;
136 public Customer getCustomer () {
137 return this.customer;
141 public void setCustomer (final Customer customer) {
142 this.customer = customer;
146 public Calendar getOrderCreated () {
147 return this.orderCreated;
151 public void setOrderCreated (final Calendar orderCreated) {
152 this.orderCreated = orderCreated;
156 public Long getOrderId () {
161 public void setOrderId (final Long orderId) {
162 this.orderId = orderId;
166 public List<AddableBasketItem> getOrderedItems () {
167 return this.orderedItems;
171 public void setOrderedItems (final List<AddableBasketItem> orderedItems) {
172 this.orderedItems = orderedItems;