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