]> git.mxchange.org Git - jfinancials-lib.git/blobdiff - src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
Fixed getter calls, the new ones are more descriptive.
[jfinancials-lib.git] / src / org / mxchange / addressbook / model / addressbook / entry / UserAddressbookEntry.java
index 4e39de3a120a216d3f666a03e0d56836aec65492..8af65ce2213502c97b7e3774613fc15cc6094ac2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -17,7 +17,7 @@
 package org.mxchange.addressbook.model.addressbook.entry;
 
 import java.util.Calendar;
-import java.util.List;
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -26,7 +26,8 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
@@ -37,17 +38,20 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontactsbusiness.BusinessContact;
 import org.mxchange.jcontactsbusiness.CompanyContact;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
 
 /**
  * A POJO for address book entries
  * <p>
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 @Entity (name = "addressbook_entries")
 @Table (name = "addressbook_entries")
-public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
+@NamedQueries (
+               @NamedQuery (
+                               name = "SearchUsersAddressbookEntries",
+                               query = "SELECT e FROM addressbook_entries AS e INNER JOIN addressbooks AS a ON e.addressbookId = a WHERE e.addressbookId = :addressbook AND a.addressbookUser = :owner ORDER BY e.addressbookEntryId ASC")
+)
+public class UserAddressbookEntry implements AddressbookEntry {
 
        /**
         * Serial number
@@ -55,12 +59,11 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
        private static final long serialVersionUID = 178_581_768_581_960L;
 
        /**
-        * Id number
+        * Connection to table "business_contacts" (commercial contacts)
         */
-       @Id
-       @GeneratedValue (strategy = GenerationType.IDENTITY)
-       @Column (name = "entry_id", nullable = false, updatable = false)
-       private Long addressbookEntryId;
+       @JoinColumn (name = "entry_business_contact_id", updatable = false)
+       @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH)
+       private BusinessContact addressbookEntryBusinessContact;
 
        /**
         * When this address book entry has been created
@@ -71,43 +74,55 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
        private Calendar addressbookEntryCreated;
 
        /**
-        * Connection to table "addressbooks"
-        */
-       @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
-       private Addressbook addressbookId;
-
-       /**
-        * Connection to table "users" (who has initially created this entry
-        */
-       @JoinColumn (name = "entry_origin_user_id", nullable = false, updatable = false)
-       @ManyToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
-       private List<User> addressbookEntryUserOriginList;
-
-       /**
-        * Connection to table "users" (who has added this entry)
+        * Id number
         */
-       @JoinColumn (name = "entry_added_user_id", updatable = false)
-       @ManyToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
-       private List<User> addressbookEntryUserAddedList;
+       @Id
+       @GeneratedValue (strategy = GenerationType.IDENTITY)
+       @Column (name = "entry_id", nullable = false, updatable = false)
+       private Long addressbookEntryId;
 
        /**
         * Connection to table "contacts" (private contacts)
         */
        @JoinColumn (name = "entry_private_contact_id", updatable = false)
-       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
        private Contact addressbookEntryPrivateContact;
 
        /**
-        * Connection to table "business_contacts" (commercial contacts)
+        * Connection to table "addressbooks"
         */
-       @JoinColumn (name = "entry_business_contact_id", updatable = false)
-       @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
-       private BusinessContact addressbookEntryBusinessContact;
+       @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
+       private Addressbook addressbookId;
 
        @Override
-       public int compareTo (final AddressbookEntry addressbookEntry) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       public boolean equals (final Object object) {
+               if (null == object) {
+                       return false;
+               } else if (this.getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final AddressbookEntry other = (AddressbookEntry) object;
+
+               if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
+                       return false;
+               } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
+                       return false;
+               } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       @Override
+       public int hashCode () {
+               int hash = 3;
+               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
+               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
+               hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
+               return hash;
        }
 
        @Override
@@ -150,26 +165,6 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
                this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
        }
 
-       @Override
-       public List<User> getAddressbookEntryUserAddedList () {
-               return this.addressbookEntryUserAddedList;
-       }
-
-       @Override
-       public void setAddressbookEntryUserAddedList (final List<User> addressbookEntryUserAddedList) {
-               this.addressbookEntryUserAddedList = addressbookEntryUserAddedList;
-       }
-
-       @Override
-       public List<User> getAddressbookEntryUserOriginList () {
-               return this.addressbookEntryUserOriginList;
-       }
-
-       @Override
-       public void setAddressbookEntryUserOriginList (final List<User> addressbookEntryUserOriginList) {
-               this.addressbookEntryUserOriginList = addressbookEntryUserOriginList;
-       }
-
        @Override
        public Addressbook getAddressbookId () {
                return this.addressbookId;