2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.model.addressbook.shared;
19 import java.util.Objects;
20 import javax.persistence.CascadeType;
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.JoinColumn;
27 import javax.persistence.OneToOne;
28 import javax.persistence.Table;
29 import org.mxchange.addressbook.model.addressbook.Addressbook;
30 import org.mxchange.addressbook.model.addressbook.UserAddressbook;
31 import org.mxchange.jusercore.model.user.LoginUser;
32 import org.mxchange.jusercore.model.user.User;
35 * A POJO for sharing address books with other users
37 * @author Roland Haeder
39 @Entity (name = "addressbook_shares")
40 @Table (name = "addressbook_shares")
41 public class AddressbookShare implements ShareableAddressbook, Comparable<ShareableAddressbook> {
46 private static final long serialVersionUID = 167_889_678_177_691_690L;
52 @GeneratedValue (strategy = GenerationType.IDENTITY)
53 @Column (name = "share_id", length = 20, nullable = false, updatable = false)
57 * Address book this share is for
59 @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
60 @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.ALL, optional = false)
61 private Addressbook shareAddressbook;
64 * User who is giving the share (for his/her address book)
66 @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
67 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, optional = false)
68 private User shareUserOwner;
71 * User the address book is shared with
73 @JoinColumn (name = "share_sharee_id", nullable = false, updatable = false)
74 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, optional = false)
75 private User shareUserSharee;
78 public int compareTo (final ShareableAddressbook share) {
79 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83 public boolean equals (final Object object) {
86 } else if (getClass() != object.getClass()) {
90 final ShareableAddressbook other = (ShareableAddressbook) object;
92 if (!Objects.equals(this.getShareAddressbook(), other.getShareAddressbook())) {
94 } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
96 } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
100 return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee());
104 public Addressbook getShareAddressbook () {
105 return this.shareAddressbook;
109 public void setShareAddressbook (final Addressbook shareAddressbook) {
110 this.shareAddressbook = shareAddressbook;
114 public Long getShareId () {
119 public void setShareId (final Long shareId) {
120 this.shareId = shareId;
124 public User getShareUserOwner () {
125 return this.shareUserOwner;
129 public void setShareUserOwner (final User shareUserOwner) {
130 this.shareUserOwner = shareUserOwner;
134 public User getShareUserSharee () {
135 return this.shareUserSharee;
139 public void setShareUserSharee (final User shareUserSharee) {
140 this.shareUserSharee = shareUserSharee;
144 public int hashCode () {
146 hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
147 hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
148 hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());