]> git.mxchange.org Git - jfinancials-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/shared/AddressbookShare.java
Continued:
[jfinancials-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.getShareUserOwner(), other.getShareUserOwner())) {
93                         return false;
94                 } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
95                         return false;
96                 }
97
98                 return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee());
99         }
100
101         @Override
102         public Addressbook getShareAddressbook () {
103                 return this.shareAddressbook;
104         }
105
106         @Override
107         public void setShareAddressbook (final Addressbook shareAddressbook) {
108                 this.shareAddressbook = shareAddressbook;
109         }
110
111         @Override
112         public Long getShareId () {
113                 return this.shareId;
114         }
115
116         @Override
117         public void setShareId (final Long shareId) {
118                 this.shareId = shareId;
119         }
120
121         @Override
122         public User getShareUserOwner () {
123                 return this.shareUserOwner;
124         }
125
126         @Override
127         public void setShareUserOwner (final User shareUserOwner) {
128                 this.shareUserOwner = shareUserOwner;
129         }
130
131         @Override
132         public User getShareUserSharee () {
133                 return this.shareUserSharee;
134         }
135
136         @Override
137         public void setShareUserSharee (final User shareUserSharee) {
138                 this.shareUserSharee = shareUserSharee;
139         }
140
141         @Override
142         public int hashCode () {
143                 int hash = 7;
144                 hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
145                 hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
146                 hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
147                 return hash;
148         }
149 }