]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 19 Apr 2017 19:05:14 +0000 (21:05 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 19 Apr 2017 19:07:23 +0000 (21:07 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/receipt/Receipt.java
src/org/mxchange/jfinancials/model/receipt/entry/ReceiptEntry.java

index 3edcd31858205c2b2f2e6cb14c054263d1c93ed9..9cf0d20f73a1f514ae3832c51cbd2b7cfb451a3e 100644 (file)
@@ -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
+        * <p>
+        * @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;
+       }
+
 }
index 44beaf6f91050fd1aa30988bdf691fa89b51a92b..77b0f8934a8003c4b3695cbc0cff50765c3ab2e1 100644 (file)
@@ -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
+        * <p>
+        * @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;
+       }
+
 }