]> git.mxchange.org Git - addressbook-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
Continued:
[addressbook-lib.git] / src / org / mxchange / addressbook / model / addressbook / entry / UserAddressbookEntry.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.entry;
18
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import org.mxchange.addressbook.model.addressbook.Addressbook;
36 import org.mxchange.addressbook.model.addressbook.UserAddressbook;
37 import org.mxchange.jcontacts.contact.Contact;
38 import org.mxchange.jcontacts.contact.UserContact;
39 import org.mxchange.jcontactsbusiness.BusinessContact;
40 import org.mxchange.jcontactsbusiness.CompanyContact;
41 import org.mxchange.jusercore.model.user.LoginUser;
42 import org.mxchange.jusercore.model.user.User;
43
44 /**
45  * A POJO for address book entries
46  * <p>
47  * @author Roland Haeder
48  */
49 @Entity (name = "addressbook_entries")
50 @Table (name = "addressbook_entries")
51 @NamedQueries (
52                 @NamedQuery (
53                                 name = "AllAddressbookEntries",
54                                 query = "SELECT e FROM addressbook_entries AS e WHERE e.addressbookId = :addressbook AND (e.addressbookEntryUserOwner = :owner OR e.addressbookEntryUserSharer = :sharer) ORDER BY e.addressbookEntryId ASC")
55 )
56 public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
57
58         /**
59          * Serial number
60          */
61         private static final long serialVersionUID = 178_581_768_581_960L;
62
63         /**
64          * Connection to table "business_contacts" (commercial contacts)
65          */
66         @JoinColumn (name = "entry_business_contact_id", updatable = false)
67         @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
68         private BusinessContact addressbookEntryBusinessContact;
69
70         /**
71          * When this address book entry has been created
72          */
73         @Basic (optional = false)
74         @Temporal (TemporalType.TIMESTAMP)
75         @Column (name = "entry_created", nullable = false, updatable = false)
76         private Calendar addressbookEntryCreated;
77
78         /**
79          * Id number
80          */
81         @Id
82         @GeneratedValue (strategy = GenerationType.IDENTITY)
83         @Column (name = "entry_id", nullable = false, updatable = false)
84         private Long addressbookEntryId;
85
86         /**
87          * Connection to table "contacts" (private contacts)
88          */
89         @JoinColumn (name = "entry_private_contact_id", updatable = false)
90         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
91         private Contact addressbookEntryPrivateContact;
92
93         /**
94          * Connection to table "users" (who has initially created this entry
95          */
96         @JoinColumn (name = "entry_owner_user_id", nullable = false, updatable = false)
97         @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
98         private User addressbookEntryUserOwner;
99
100         /**
101          * Connection to table "users" (who has added this entry)
102          */
103         @JoinColumn (name = "entry_sharer_user_id", updatable = false)
104         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
105         private User addressbookEntryUserSharer;
106
107         /**
108          * Connection to table "addressbooks"
109          */
110         @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
111         @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
112         private Addressbook addressbookId;
113
114         @Override
115         public int compareTo (final AddressbookEntry addressbookEntry) {
116                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
117         }
118
119         @Override
120         public boolean equals (final Object object) {
121                 if (object == null) {
122                         return false;
123                 } else if (getClass() != object.getClass()) {
124                         return false;
125                 }
126
127                 final AddressbookEntry other = (AddressbookEntry) object;
128
129                 if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
130                         return false;
131                 } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
132                         return false;
133                 } else if (!Objects.equals(this.getAddressbookEntryUserOwner(), other.getAddressbookEntryUserOwner())) {
134                         return false;
135                 } else if (!Objects.equals(this.getAddressbookEntryUserSharer(), other.getAddressbookEntryUserSharer())) {
136                         return false;
137                 } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
138                         return false;
139                 }
140
141                 return true;
142         }
143
144         @Override
145         public BusinessContact getAddressbookEntryBusinessContact () {
146                 return this.addressbookEntryBusinessContact;
147         }
148
149         @Override
150         public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
151                 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
152         }
153
154         @Override
155         public Calendar getAddressbookEntryCreated () {
156                 return this.addressbookEntryCreated;
157         }
158
159         @Override
160         public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
161                 this.addressbookEntryCreated = addressbookEntryCreated;
162         }
163
164         @Override
165         public Long getAddressbookEntryId () {
166                 return this.addressbookEntryId;
167         }
168
169         @Override
170         public void setAddressbookEntryId (final Long addressbookEntryId) {
171                 this.addressbookEntryId = addressbookEntryId;
172         }
173
174         @Override
175         public Contact getAddressbookEntryPrivateContact () {
176                 return this.addressbookEntryPrivateContact;
177         }
178
179         @Override
180         public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
181                 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
182         }
183
184         @Override
185         public User getAddressbookEntryUserSharer () {
186                 return this.addressbookEntryUserSharer;
187         }
188
189         @Override
190         public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
191                 this.addressbookEntryUserSharer = addressbookEntryUserSharer;
192         }
193
194         @Override
195         public User getAddressbookEntryUserOwner () {
196                 return this.addressbookEntryUserOwner;
197         }
198
199         @Override
200         public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
201                 this.addressbookEntryUserOwner = addressbookEntryUserOwner;
202         }
203
204         @Override
205         public Addressbook getAddressbookId () {
206                 return this.addressbookId;
207         }
208
209         @Override
210         public void setAddressbookId (final Addressbook addressbookId) {
211                 this.addressbookId = addressbookId;
212         }
213
214         @Override
215         public int hashCode () {
216                 int hash = 3;
217                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
218                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
219                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryUserOwner());
220                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryUserSharer());
221                 hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
222                 return hash;
223         }
224
225 }