]> git.mxchange.org Git - addressbook-lib.git/blobdiff - src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java
Some cascade/fetch cleanups:
[addressbook-lib.git] / src / org / mxchange / addressbook / model / addressbook / shared / AddressbookShare.java
index 450c8a64a08ca2dfb665db068e666de1c92749eb..4373faebb2fc6181ecba775a975ca5f5f5f17487 100644 (file)
@@ -42,7 +42,7 @@ import org.mxchange.jusercore.model.user.User;
 /**
  * A POJO for sharing address books with other users
  * <p>
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 @Entity (name = "addressbook_shares")
 @Table (name = "addressbook_shares")
@@ -65,6 +65,21 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
         */
        private static final long serialVersionUID = 167_889_678_177_691_690L;
 
+       /**
+        * Address book this share is for
+        */
+       @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
+       private Addressbook shareAddressbook;
+
+       /**
+        * When this share has been created
+        */
+       @Basic (optional = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "share_created", nullable = false, updatable = false)
+       private Calendar shareCreated;
+
        /**
         * Id number
         */
@@ -73,41 +88,20 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
        @Column (name = "share_id", length = 20, nullable = false, updatable = false)
        private Long shareId;
 
-       /**
-        * Address book this share is for
-        */
-       @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.MERGE, optional = false)
-       private Addressbook shareAddressbook;
-
        /**
         * User who is owning the share
         */
        @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
        private User shareUserOwner;
 
        /**
         * User the address book is shared with
         */
        @JoinColumn (name = "share_sharee_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
        private User shareUserSharee;
 
-       /**
-        * When this share has been created
-        */
-       @Basic (optional = false)
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "share_created", nullable = false, updatable = false)
-       private Calendar shareCreated;
-
-       /**
-        * Default constructor for entity manager
-        */
-       protected AddressbookShare () {
-       }
-
        /**
         * Constructor with address book and sharee instance. Both parameters must
         * not be null, their id numbers must be set and the adress book's user
@@ -117,7 +111,7 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
         * @param sharee User sharee instance
         */
        public AddressbookShare (final Addressbook addressbook, final User sharee) {
-               // Call protected constructor
+               // Call default constructor
                this();
 
                // Check all conditions
@@ -151,6 +145,12 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
                this.shareCreated = new GregorianCalendar();
        }
 
+       /**
+        * Default constructor
+        */
+       public AddressbookShare () {
+       }
+
        @Override
        public int compareTo (final ShareableAddressbook share) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
@@ -160,7 +160,7 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
        public boolean equals (final Object object) {
                if (object == null) {
                        return false;
-               } else if (getClass() != object.getClass()) {
+               } else if (this.getClass() != object.getClass()) {
                        return false;
                }
 
@@ -177,6 +177,15 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
                return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee());
        }
 
+       @Override
+       public int hashCode () {
+               int hash = 7;
+               hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
+               hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
+               hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
+               return hash;
+       }
+
        @Override
        public Addressbook getShareAddressbook () {
                return this.shareAddressbook;
@@ -227,12 +236,4 @@ public class AddressbookShare implements ShareableAddressbook, Comparable<Sharea
                this.shareUserSharee = shareUserSharee;
        }
 
-       @Override
-       public int hashCode () {
-               int hash = 7;
-               hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
-               hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
-               hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
-               return hash;
-       }
 }