2 * Copyright (C) 2016 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;
43 * A POJO for address book entries
45 * @author Roland Haeder<roland@mxchange.org>
47 @Entity (name = "addressbook_entries")
48 @Table (name = "addressbook_entries")
51 name = "SearchUsersAddressbookEntries",
52 query = "SELECT e FROM addressbook_entries AS e INNER JOIN addressbooks AS a ON e.addressbookId = a WHERE e.addressbookId = :addressbook AND a.addressbookUser = :owner ORDER BY e.addressbookEntryId ASC")
54 public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
59 private static final long serialVersionUID = 178_581_768_581_960L;
62 * Connection to table "business_contacts" (commercial contacts)
64 @JoinColumn (name = "entry_business_contact_id", updatable = false)
65 @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH)
66 private BusinessContact addressbookEntryBusinessContact;
69 * When this address book entry has been created
71 @Basic (optional = false)
72 @Temporal (TemporalType.TIMESTAMP)
73 @Column (name = "entry_created", nullable = false, updatable = false)
74 private Calendar addressbookEntryCreated;
80 @GeneratedValue (strategy = GenerationType.IDENTITY)
81 @Column (name = "entry_id", nullable = false, updatable = false)
82 private Long addressbookEntryId;
85 * Connection to table "contacts" (private contacts)
87 @JoinColumn (name = "entry_private_contact_id", updatable = false)
88 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
89 private Contact addressbookEntryPrivateContact;
92 * Connection to table "addressbooks"
94 @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
95 @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.REFRESH)
96 private Addressbook addressbookId;
99 public int compareTo (final AddressbookEntry addressbookEntry) {
100 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
104 public boolean equals (final Object object) {
105 if (object == null) {
107 } else if (this.getClass() != object.getClass()) {
111 final AddressbookEntry other = (AddressbookEntry) object;
113 if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
115 } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
117 } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
125 public int hashCode () {
127 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
128 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
129 hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
134 public BusinessContact getAddressbookEntryBusinessContact () {
135 return this.addressbookEntryBusinessContact;
139 public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
140 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
144 public Calendar getAddressbookEntryCreated () {
145 return this.addressbookEntryCreated;
149 public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
150 this.addressbookEntryCreated = addressbookEntryCreated;
154 public Long getAddressbookEntryId () {
155 return this.addressbookEntryId;
159 public void setAddressbookEntryId (final Long addressbookEntryId) {
160 this.addressbookEntryId = addressbookEntryId;
164 public Contact getAddressbookEntryPrivateContact () {
165 return this.addressbookEntryPrivateContact;
169 public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
170 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
174 public Addressbook getAddressbookId () {
175 return this.addressbookId;
179 public void setAddressbookId (final Addressbook addressbookId) {
180 this.addressbookId = addressbookId;