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.entry;
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;
45 * A POJO for address book entries
47 * @author Roland Haeder
49 @Entity (name = "addressbook_entries")
50 @Table (name = "addressbook_entries")
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")
56 public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
61 private static final long serialVersionUID = 178_581_768_581_960L;
64 * Connection to table "business_contacts" (commercial contacts)
66 @JoinColumn (name = "entry_business_contact_id", updatable = false)
67 @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
68 private BusinessContact addressbookEntryBusinessContact;
71 * When this address book entry has been created
73 @Basic (optional = false)
74 @Temporal (TemporalType.TIMESTAMP)
75 @Column (name = "entry_created", nullable = false, updatable = false)
76 private Calendar addressbookEntryCreated;
82 @GeneratedValue (strategy = GenerationType.IDENTITY)
83 @Column (name = "entry_id", nullable = false, updatable = false)
84 private Long addressbookEntryId;
87 * Connection to table "contacts" (private contacts)
89 @JoinColumn (name = "entry_private_contact_id", updatable = false)
90 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
91 private Contact addressbookEntryPrivateContact;
94 * Connection to table "users" (who has initially created this entry
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;
101 * Connection to table "users" (who has added this entry)
103 @JoinColumn (name = "entry_sharer_user_id", updatable = false)
104 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
105 private User addressbookEntryUserSharer;
108 * Connection to table "addressbooks"
110 @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
111 @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
112 private Addressbook addressbookId;
115 public int compareTo (final AddressbookEntry addressbookEntry) {
116 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
120 public boolean equals (final Object object) {
121 if (object == null) {
123 } else if (getClass() != object.getClass()) {
127 final AddressbookEntry other = (AddressbookEntry) object;
129 if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
131 } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
133 } else if (!Objects.equals(this.getAddressbookEntryUserOwner(), other.getAddressbookEntryUserOwner())) {
135 } else if (!Objects.equals(this.getAddressbookEntryUserSharer(), other.getAddressbookEntryUserSharer())) {
137 } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
145 public BusinessContact getAddressbookEntryBusinessContact () {
146 return this.addressbookEntryBusinessContact;
150 public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
151 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
155 public Calendar getAddressbookEntryCreated () {
156 return this.addressbookEntryCreated;
160 public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
161 this.addressbookEntryCreated = addressbookEntryCreated;
165 public Long getAddressbookEntryId () {
166 return this.addressbookEntryId;
170 public void setAddressbookEntryId (final Long addressbookEntryId) {
171 this.addressbookEntryId = addressbookEntryId;
175 public Contact getAddressbookEntryPrivateContact () {
176 return this.addressbookEntryPrivateContact;
180 public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
181 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
185 public User getAddressbookEntryUserSharer () {
186 return this.addressbookEntryUserSharer;
190 public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
191 this.addressbookEntryUserSharer = addressbookEntryUserSharer;
195 public User getAddressbookEntryUserOwner () {
196 return this.addressbookEntryUserOwner;
200 public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
201 this.addressbookEntryUserOwner = addressbookEntryUserOwner;
205 public Addressbook getAddressbookId () {
206 return this.addressbookId;
210 public void setAddressbookId (final Addressbook addressbookId) {
211 this.addressbookId = addressbookId;
215 public int hashCode () {
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());