]> git.mxchange.org Git - addressbook-lib.git/blobdiff - src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java
Continued:
[addressbook-lib.git] / src / org / mxchange / addressbook / model / addressbook / shared / AddressbookShare.java
diff --git a/src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java b/src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java
new file mode 100644 (file)
index 0000000..8777d91
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2015 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.model.addressbook.shared;
+
+import java.util.Objects;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import org.mxchange.addressbook.model.addressbook.Addressbook;
+import org.mxchange.addressbook.model.addressbook.UserAddressbook;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A POJO for sharing address books with other users
+ * <p>
+ * @author Roland Haeder
+ */
+@Entity (name = "addressbook_shares")
+@Table (name = "addressbook_shares")
+public class AddressbookShare implements ShareableAddressbook, Comparable<ShareableAddressbook> {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 167_889_678_177_691_690L;
+
+       /**
+        * Id number
+        */
+       @Id
+       @GeneratedValue (strategy = GenerationType.IDENTITY)
+       @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.ALL, optional = false)
+       private Addressbook shareAddressbook;
+
+       /**
+        * User who is giving the share (for his/her address book)
+        */
+       @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, 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.ALL, optional = false)
+       private User shareUserSharee;
+
+       @Override
+       public int compareTo (final ShareableAddressbook share) {
+               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 ShareableAddressbook other = (ShareableAddressbook) object;
+
+               if (!Objects.equals(this.getShareAddressbook(), other.getShareAddressbook())) {
+                       return false;
+               } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
+                       return false;
+               } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
+                       return false;
+               }
+
+               return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee());
+       }
+
+       @Override
+       public Addressbook getShareAddressbook () {
+               return this.shareAddressbook;
+       }
+
+       @Override
+       public void setShareAddressbook (final Addressbook shareAddressbook) {
+               this.shareAddressbook = shareAddressbook;
+       }
+
+       @Override
+       public Long getShareId () {
+               return this.shareId;
+       }
+
+       @Override
+       public void setShareId (final Long shareId) {
+               this.shareId = shareId;
+       }
+
+       @Override
+       public User getShareUserOwner () {
+               return this.shareUserOwner;
+       }
+
+       @Override
+       public void setShareUserOwner (final User shareUserOwner) {
+               this.shareUserOwner = shareUserOwner;
+       }
+
+       @Override
+       public User getShareUserSharee () {
+               return this.shareUserSharee;
+       }
+
+       @Override
+       public void setShareUserSharee (final User shareUserSharee) {
+               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;
+       }
+}