]> git.mxchange.org Git - jbonuscard-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java
Continued:
[jbonuscard-lib.git] / src / org / mxchange / addressbook / model / addressbook / shared / AddressbookShare.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.model.addressbook.shared;
18
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;
33
34 /**
35  * A POJO for sharing address books with other users
36  * <p>
37  * @author Roland Haeder
38  */
39 @Entity (name = "addressbook_shares")
40 @Table (name = "addressbook_shares")
41 public class AddressbookShare implements ShareableAddressbook, Comparable<ShareableAddressbook> {
42
43         /**
44          * Serial number
45          */
46         private static final long serialVersionUID = 167_889_678_177_691_690L;
47
48         /**
49          * Id number
50          */
51         @Id
52         @GeneratedValue (strategy = GenerationType.IDENTITY)
53         @Column (name = "share_id", length = 20, nullable = false, updatable = false)
54         private Long shareId;
55
56         /**
57          * Address book this share is for
58          */
59         @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
60         @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.ALL, optional = false)
61         private Addressbook shareAddressbook;
62
63         /**
64          * User who is giving the share (for his/her address book)
65          */
66         @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
67         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, optional = false)
68         private User shareUserOwner;
69
70         /**
71          * User the address book is shared with
72          */
73         @JoinColumn (name = "share_sharee_id", nullable = false, updatable = false)
74         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, optional = false)
75         private User shareUserSharee;
76
77         @Override
78         public int compareTo (final ShareableAddressbook share) {
79                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
80         }
81
82         @Override
83         public boolean equals (final Object object) {
84                 if (object == null) {
85                         return false;
86                 } else if (getClass() != object.getClass()) {
87                         return false;
88                 }
89
90                 final ShareableAddressbook other = (ShareableAddressbook) object;
91
92                 if (!Objects.equals(this.getShareAddressbook(), other.getShareAddressbook())) {
93                         return false;
94                 } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
95                         return false;
96                 } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
97                         return false;
98                 }
99
100                 return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee());
101         }
102
103         @Override
104         public Addressbook getShareAddressbook () {
105                 return this.shareAddressbook;
106         }
107
108         @Override
109         public void setShareAddressbook (final Addressbook shareAddressbook) {
110                 this.shareAddressbook = shareAddressbook;
111         }
112
113         @Override
114         public Long getShareId () {
115                 return this.shareId;
116         }
117
118         @Override
119         public void setShareId (final Long shareId) {
120                 this.shareId = shareId;
121         }
122
123         @Override
124         public User getShareUserOwner () {
125                 return this.shareUserOwner;
126         }
127
128         @Override
129         public void setShareUserOwner (final User shareUserOwner) {
130                 this.shareUserOwner = shareUserOwner;
131         }
132
133         @Override
134         public User getShareUserSharee () {
135                 return this.shareUserSharee;
136         }
137
138         @Override
139         public void setShareUserSharee (final User shareUserSharee) {
140                 this.shareUserSharee = shareUserSharee;
141         }
142
143         @Override
144         public int hashCode () {
145                 int hash = 7;
146                 hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
147                 hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
148                 hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
149                 return hash;
150         }
151 }