]> git.mxchange.org Git - jaddressbook-core.git/blob - src/org/mxchange/jaddressbookcore/model/addressbook/entry/UserAddressbookEntry.java
No, was not working ... :-(
[jaddressbook-core.git] / src / org / mxchange / jaddressbookcore / model / addressbook / entry / UserAddressbookEntry.java
1 /*
2  * Copyright (C) 2016 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.jaddressbookcore.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.jaddressbookcore.model.addressbook.Addressbook;
36 import org.mxchange.jaddressbookcore.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
42 /**
43  * A POJO for address book entries
44  * <p>
45  * @author Roland Haeder<roland@mxchange.org>
46  */
47 @Entity (name = "addressbook_entries")
48 @Table (name = "addressbook_entries")
49 @NamedQueries (
50                 @NamedQuery (
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")
53 )
54 @SuppressWarnings ("PersistenceUnitPresent")
55 public class UserAddressbookEntry implements AddressbookEntry {
56
57         /**
58          * Serial number
59          */
60         private static final long serialVersionUID = 178_581_768_581_960L;
61
62         /**
63          * Connection to table "business_contacts" (commercial contacts)
64          */
65         @JoinColumn (name = "entry_business_contact_id", updatable = false)
66         @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH)
67         private BusinessContact addressbookEntryBusinessContact;
68
69         /**
70          * When this address book entry has been created
71          */
72         @Basic (optional = false)
73         @Temporal (TemporalType.TIMESTAMP)
74         @Column (name = "entry_created", nullable = false, updatable = false)
75         private Calendar addressbookEntryCreated;
76
77         /**
78          * Id number
79          */
80         @Id
81         @GeneratedValue (strategy = GenerationType.IDENTITY)
82         @Column (name = "entry_id", nullable = false, updatable = false)
83         private Long addressbookEntryId;
84
85         /**
86          * Connection to table "contacts" (private contacts)
87          */
88         @JoinColumn (name = "entry_private_contact_id", updatable = false)
89         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
90         private Contact addressbookEntryPrivateContact;
91
92         /**
93          * Connection to table "addressbooks"
94          */
95         @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
96         @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
97         private Addressbook addressbookId;
98
99         @Override
100         public boolean equals (final Object object) {
101                 if (null == object) {
102                         return false;
103                 } else if (this.getClass() != object.getClass()) {
104                         return false;
105                 }
106
107                 final AddressbookEntry other = (AddressbookEntry) object;
108
109                 if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
110                         return false;
111                 } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
112                         return false;
113                 } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
114                         return false;
115                 }
116
117                 return true;
118         }
119
120         @Override
121         public int hashCode () {
122                 int hash = 3;
123
124                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
125                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
126                 hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
127
128                 return hash;
129         }
130
131         @Override
132         public BusinessContact getAddressbookEntryBusinessContact () {
133                 return this.addressbookEntryBusinessContact;
134         }
135
136         @Override
137         public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
138                 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
139         }
140
141         @Override
142         @SuppressWarnings ("ReturnOfDateField")
143         public Calendar getAddressbookEntryCreated () {
144                 return this.addressbookEntryCreated;
145         }
146
147         @Override
148         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
149         public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
150                 this.addressbookEntryCreated = addressbookEntryCreated;
151         }
152
153         @Override
154         public Long getAddressbookEntryId () {
155                 return this.addressbookEntryId;
156         }
157
158         @Override
159         public void setAddressbookEntryId (final Long addressbookEntryId) {
160                 this.addressbookEntryId = addressbookEntryId;
161         }
162
163         @Override
164         public Contact getAddressbookEntryPrivateContact () {
165                 return this.addressbookEntryPrivateContact;
166         }
167
168         @Override
169         public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
170                 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
171         }
172
173         @Override
174         public Addressbook getAddressbookId () {
175                 return this.addressbookId;
176         }
177
178         @Override
179         public void setAddressbookId (final Addressbook addressbookId) {
180                 this.addressbookId = addressbookId;
181         }
182
183 }