]> git.mxchange.org Git - addressbook-lib.git/commitdiff
No more @OneToMany as this is confusing, better @OneToOne and easy named queries :)
authorRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 17:00:18 +0000 (19:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 17:00:18 +0000 (19:00 +0200)
src/org/mxchange/addressbook/model/addressbook/entry/AddressbookEntry.java
src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java

index 6984d6fe3b3da11e337788bf5fa151c3ec8d9b6f..930fbb342711c713933f4b74b39b061ad8657def 100644 (file)
@@ -18,7 +18,6 @@ package org.mxchange.addressbook.model.addressbook.entry;
 
 import java.io.Serializable;
 import java.util.Calendar;
-import java.util.List;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontactsbusiness.BusinessContact;
@@ -92,21 +91,21 @@ public interface AddressbookEntry extends Serializable {
         * <p>
         * @return User who has added this entry
         */
-       public List<User> getAddressbookEntryUserAddedList ();
+       public User getAddressbookEntryUserSharer ();
 
        /**
         * Setter for user who has added this entry to his/her addressbook
         * <p>
         * @param addressbookEntryUserAdded User who has added this entry
         */
-       public void setAddressbookEntryUserAddedList (final List<User> addressbookEntryUserAdded);
+       public void setAddressbookEntryUserSharer (final User addressbookEntryUserAdded);
 
        /**
         * Getter for user who has initially created the address book entry
         * <p>
         * @return User who has created initially this address book entry
         */
-       public List<User> getAddressbookEntryUserOriginList ();
+       public User getAddressbookEntryUserOwner ();
 
        /**
         * Setter for user who has initially created the address book entry
@@ -114,7 +113,7 @@ public interface AddressbookEntry extends Serializable {
         * @param addressbookEntryUserOrigin User who has created initially this
         * address book entry
         */
-       public void setAddressbookEntryUserOriginList (final List<User> addressbookEntryUserOrigin);
+       public void setAddressbookEntryUserOwner (final User addressbookEntryUserOrigin);
 
        /**
         * Getter for address book
index 4e39de3a120a216d3f666a03e0d56836aec65492..4ad8484b86d74b945d1b1e94a74c0ccaea928ec4 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.addressbook.model.addressbook.entry;
 
 import java.util.Calendar;
-import java.util.List;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -26,7 +25,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;
@@ -47,6 +47,11 @@ import org.mxchange.jusercore.model.user.User;
  */
 @Entity (name = "addressbook_entries")
 @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")
+)
 public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
 
        /**
@@ -55,12 +60,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.ALL)
+       private BusinessContact addressbookEntryBusinessContact;
 
        /**
         * When this address book entry has been created
@@ -71,39 +75,40 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
        private Calendar addressbookEntryCreated;
 
        /**
-        * Connection to table "addressbooks"
+        * Id number
         */
-       @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
-       private Addressbook addressbookId;
+       @Id
+       @GeneratedValue (strategy = GenerationType.IDENTITY)
+       @Column (name = "entry_id", nullable = false, updatable = false)
+       private Long addressbookEntryId;
 
        /**
-        * Connection to table "users" (who has initially created this entry
+        * Connection to table "contacts" (private contacts)
         */
-       @JoinColumn (name = "entry_origin_user_id", nullable = false, updatable = false)
-       @ManyToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
-       private List<User> addressbookEntryUserOriginList;
+       @JoinColumn (name = "entry_private_contact_id", updatable = false)
+       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
+       private Contact addressbookEntryPrivateContact;
 
        /**
-        * Connection to table "users" (who has added this entry)
+        * Connection to table "users" (who has initially created this entry
         */
-       @JoinColumn (name = "entry_added_user_id", updatable = false)
-       @ManyToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
-       private List<User> addressbookEntryUserAddedList;
+       @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 "contacts" (private contacts)
+        * Connection to table "users" (who has added this entry)
         */
-       @JoinColumn (name = "entry_private_contact_id", updatable = false)
-       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
-       private Contact addressbookEntryPrivateContact;
+       @JoinColumn (name = "entry_sharer_user_id", updatable = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
+       private User addressbookEntryUserSharer;
 
        /**
-        * 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 = "addressbook_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
+       private Addressbook addressbookId;
 
        @Override
        public int compareTo (final AddressbookEntry addressbookEntry) {
@@ -151,23 +156,23 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable<Addres
        }
 
        @Override
-       public List<User> getAddressbookEntryUserAddedList () {
-               return this.addressbookEntryUserAddedList;
+       public User getAddressbookEntryUserSharer () {
+               return this.addressbookEntryUserSharer;
        }
 
        @Override
-       public void setAddressbookEntryUserAddedList (final List<User> addressbookEntryUserAddedList) {
-               this.addressbookEntryUserAddedList = addressbookEntryUserAddedList;
+       public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
+               this.addressbookEntryUserSharer = addressbookEntryUserSharer;
        }
 
        @Override
-       public List<User> getAddressbookEntryUserOriginList () {
-               return this.addressbookEntryUserOriginList;
+       public User getAddressbookEntryUserOwner () {
+               return this.addressbookEntryUserOwner;
        }
 
        @Override
-       public void setAddressbookEntryUserOriginList (final List<User> addressbookEntryUserOriginList) {
-               this.addressbookEntryUserOriginList = addressbookEntryUserOriginList;
+       public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
+               this.addressbookEntryUserOwner = addressbookEntryUserOwner;
        }
 
        @Override