2 * Copyright (C) 2016 Roland Haeder
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 Haeder<roland@mxchange.org>
43 @Entity (name = "orders")
44 @Table (name = "orders")
45 @SuppressWarnings ("PersistenceUnitPresent")
46 public class ShopOrder implements Orderable {
51 private static final long serialVersionUID = 19_728_938_459_834L;
56 @Basic (optional = false)
57 @Column (name = "access_key", length = 100, nullable = false, unique = true)
58 private String accessKey;
63 @JoinColumn (name = "customer_id", nullable = false, updatable = false)
64 @OneToOne (targetEntity = Customer.class, cascade = CascadeType.REFRESH, optional = false)
65 private Customer customer;
70 @Basic (optional = false)
71 @Temporal (TemporalType.TIMESTAMP)
72 @Column (name = "order_created", nullable = false)
73 private Calendar orderCreated;
79 @GeneratedValue (strategy = GenerationType.IDENTITY)
80 @Column (name = "order_id", length = 20)
84 * Item list, don't save this
87 private List<AddableBasketItem> orderedItems;
90 public boolean equals (final Object object) {
93 } else if (null == object) {
95 } else if (this.getClass() != object.getClass()) {
99 final Orderable other = (Orderable) object;
101 if (!Objects.equals(this.getAccessKey(), other.getAccessKey())) {
103 } else if (!Objects.equals(this.getCustomer(), other.getCustomer())) {
105 } else if (!Objects.equals(this.getOrderId(), other.getOrderId())) {
107 } else if (!Objects.equals(this.getOrderedItems(), other.getOrderedItems())) {
115 public int hashCode () {
117 hash = 61 * hash + Objects.hashCode(this.getAccessKey());
118 hash = 61 * hash + Objects.hashCode(this.getCustomer());
119 hash = 61 * hash + Objects.hashCode(this.getOrderId());
120 hash = 61 * hash + Objects.hashCode(this.getOrderedItems());
125 public String getAccessKey () {
126 return this.accessKey;
130 public void setAccessKey (final String accessKey) {
131 this.accessKey = accessKey;
135 public Customer getCustomer () {
136 return this.customer;
140 public void setCustomer (final Customer customer) {
141 this.customer = customer;
145 public Calendar getOrderCreated () {
146 return this.orderCreated;
150 public void setOrderCreated (final Calendar orderCreated) {
151 this.orderCreated = orderCreated;
155 public Long getOrderId () {
160 public void setOrderId (final Long orderId) {
161 this.orderId = orderId;
165 public List<AddableBasketItem> getOrderedItems () {
166 return this.orderedItems;
170 public void setOrderedItems (final List<AddableBasketItem> orderedItems) {
171 this.orderedItems = orderedItems;