From 097b362a8912bdc9b0735624175e31cbd918fb50 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 19 Apr 2017 21:05:14 +0200 Subject: [PATCH] Continued a bit: - opps, really need to have at least a default constructor, hashCode() and equals() around, else the JPA generates a SEQUENCE table which you don't want (usually not). - added constructor with all fields, except primary key and created-timestamp - you have to set those timestamps by yourself MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jfinancials/model/receipt/Receipt.java | 62 ++++++++++++++++++ .../model/receipt/entry/ReceiptEntry.java | 65 +++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/src/org/mxchange/jfinancials/model/receipt/Receipt.java b/src/org/mxchange/jfinancials/model/receipt/Receipt.java index 3edcd31..9cf0d20 100644 --- a/src/org/mxchange/jfinancials/model/receipt/Receipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/Receipt.java @@ -17,6 +17,7 @@ package org.mxchange.jfinancials.model.receipt; import java.util.Calendar; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -93,6 +94,55 @@ public class Receipt implements Billable { @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false) private User receiptUser; + /** + * Default constructor + */ + public Receipt () { + } + + /** + * Constructor with payment type, seller and user + *

+ * @param receiptPaymentType Payment type + * @param receiptSeller Seller instance + * @param receiptUser User instance + */ + public Receipt (final PaymentType receiptPaymentType, final BusinessContact receiptSeller, final User receiptUser) { + // Call other constructor first + this(); + + // Set all + this.receiptPaymentType = receiptPaymentType; + this.receiptSeller = receiptSeller; + this.receiptUser = receiptUser; + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } + if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final Billable receipt = (Billable) object; + + if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) { + return false; + } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) { + return false; + } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) { + return false; + } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) { + return false; + } + + return true; + } + @Override @SuppressWarnings ("ReturnOfDateField") public Calendar getReceiptCreated () { @@ -145,4 +195,16 @@ public class Receipt implements Billable { this.receiptUser = receiptUser; } + @Override + public int hashCode () { + int hash = 5; + + hash = 89 * hash + Objects.hashCode(this.getReceiptId()); + hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType()); + hash = 89 * hash + Objects.hashCode(this.getReceiptSeller()); + hash = 89 * hash + Objects.hashCode(this.getReceiptUser()); + + return hash; + } + } diff --git a/src/org/mxchange/jfinancials/model/receipt/entry/ReceiptEntry.java b/src/org/mxchange/jfinancials/model/receipt/entry/ReceiptEntry.java index 44beaf6..77b0f89 100644 --- a/src/org/mxchange/jfinancials/model/receipt/entry/ReceiptEntry.java +++ b/src/org/mxchange/jfinancials/model/receipt/entry/ReceiptEntry.java @@ -17,6 +17,8 @@ package org.mxchange.jfinancials.model.receipt.entry; import java.util.Calendar; +import java.util.Objects; +import java.util.logging.Logger; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -51,6 +53,8 @@ import org.mxchange.jproduct.model.product.Product; @SuppressWarnings ("PersistenceUnitPresent") public class ReceiptEntry implements BillableReceiptEntry { + private static final Logger LOG = Logger.getLogger(ReceiptEntry.class.getName()); + /** * Serial number */ @@ -101,6 +105,54 @@ public class ReceiptEntry implements BillableReceiptEntry { @OneToOne (targetEntity = Receipt.class, cascade = CascadeType.REFRESH, optional = false) private Billable entryReceipt; + /** + * Default constructor + */ + public ReceiptEntry () { + } + + /** + * Constructor with product, price, quantity and receipt instance + *

+ * @param entryProduct Product instance + * @param entryProductPrice Product price (copied) + * @param entryProductQuantity Product quantity + * @param entryReceipt Receipt instance + */ + public ReceiptEntry (final Product entryProduct, final Float entryProductPrice, final Long entryProductQuantity, final Billable entryReceipt) { + this.entryProduct = entryProduct; + this.entryProductPrice = entryProductPrice; + this.entryProductQuantity = entryProductQuantity; + this.entryReceipt = entryReceipt; + } + + @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 BillableReceiptEntry receiptEntry = (BillableReceiptEntry) object; + + if (!Objects.equals(this.getEntryId(), receiptEntry.getEntryId())) { + return false; + } else if (!Objects.equals(this.getEntryProduct(), receiptEntry.getEntryProduct())) { + return false; + } else if (!Objects.equals(this.getEntryProductPrice(), receiptEntry.getEntryProductPrice())) { + return false; + } else if (!Objects.equals(this.getEntryProductQuantity(), receiptEntry.getEntryProductQuantity())) { + return false; + } else if (!Objects.equals(this.getEntryReceipt(), receiptEntry.getEntryReceipt())) { + return false; + } + + return true; + } + @Override @SuppressWarnings ("ReturnOfDateField") public Calendar getEntryCreated () { @@ -163,4 +215,17 @@ public class ReceiptEntry implements BillableReceiptEntry { this.entryReceipt = entryReceipt; } + @Override + public int hashCode () { + int hash = 5; + + hash = 53 * hash + Objects.hashCode(this.getEntryId()); + hash = 53 * hash + Objects.hashCode(this.getEntryProduct()); + hash = 53 * hash + Objects.hashCode(this.getEntryProductPrice()); + hash = 53 * hash + Objects.hashCode(this.getEntryProductQuantity()); + hash = 53 * hash + Objects.hashCode(this.getEntryReceipt()); + + return hash; + } + } -- 2.39.5