]> git.mxchange.org Git - addressbook-lib.git/blobdiff - src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
Updated copyright year
[addressbook-lib.git] / src / org / mxchange / addressbook / model / addressbook / entry / UserAddressbookEntry.java
index 4ad8484b86d74b945d1b1e94a74c0ccaea928ec4..e9a8072ef9fc5b5ab6aaaf13770107ab1f8146a7 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,6 +17,7 @@
 package org.mxchange.addressbook.model.addressbook.entry;
 
 import java.util.Calendar;
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -37,8 +38,6 @@ 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
@@ -49,8 +48,8 @@ import org.mxchange.jusercore.model.user.User;
 @Table (name = "addressbook_entries")
 @NamedQueries (
                @NamedQuery (
-                               name = "AllAddressbookEntries",
-                               query = "SELECT e FROM addressbook_entries AS e WHERE e.addressbookId = :addressbook AND (e.addressbookEntryUserOwner = :owner OR e.addressbookEntryUserSharer = :sharer) ORDER BY e.addressbookEntryId ASC")
+                               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, Comparable<AddressbookEntry> {
 
@@ -63,7 +62,7 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
         * Connection to table "business_contacts" (commercial contacts)
         */
        @JoinColumn (name = "entry_business_contact_id", updatable = false)
-       @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.MERGE)
        private BusinessContact addressbookEntryBusinessContact;
 
        /**
@@ -86,28 +85,14 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
         * 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.MERGE)
        private Contact addressbookEntryPrivateContact;
 
-       /**
-        * Connection to table "users" (who has initially created this entry
-        */
-       @JoinColumn (name = "entry_owner_user_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
-       private User addressbookEntryUserOwner;
-
-       /**
-        * Connection to table "users" (who has added this entry)
-        */
-       @JoinColumn (name = "entry_sharer_user_id", updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
-       private User addressbookEntryUserSharer;
-
        /**
         * Connection to table "addressbooks"
         */
-       @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
+       @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.MERGE)
        private Addressbook addressbookId;
 
        @Override
@@ -115,6 +100,27 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (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 BusinessContact getAddressbookEntryBusinessContact () {
                return this.addressbookEntryBusinessContact;
@@ -155,26 +161,6 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
                this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
        }
 
-       @Override
-       public User getAddressbookEntryUserSharer () {
-               return this.addressbookEntryUserSharer;
-       }
-
-       @Override
-       public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
-               this.addressbookEntryUserSharer = addressbookEntryUserSharer;
-       }
-
-       @Override
-       public User getAddressbookEntryUserOwner () {
-               return this.addressbookEntryUserOwner;
-       }
-
-       @Override
-       public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
-               this.addressbookEntryUserOwner = addressbookEntryUserOwner;
-       }
-
        @Override
        public Addressbook getAddressbookId () {
                return this.addressbookId;
@@ -185,4 +171,13 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
                this.addressbookId = addressbookId;
        }
 
+       @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;
+       }
+
 }