2 * Copyright (C) 2016, 2017 Roland Häder
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.jcontacts.model.contact;
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.EnumType;
27 import javax.persistence.Enumerated;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.Index;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.Lob;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToOne;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40 import javax.persistence.Transient;
41 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jcountry.model.data.CountryData;
44 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
52 * A general contact class which serves as an entity.
54 * @author Roland Häder<roland@mxchange.org>
57 @Entity (name = "contacts")
62 name = "contact_personal_title",
63 columnList = "contact_personal_title"
69 @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"),
70 @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
71 @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"),
72 @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"),
73 @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"),
74 @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)")
77 @SuppressWarnings ("PersistenceUnitPresent")
78 public class UserContact implements Contact {
84 private static final long serialVersionUID = 58_744_284_981_863L;
89 @Column (name = "contact_birthday")
90 @Temporal (TemporalType.DATE)
91 private Date contactBirthday;
96 @Column (name = "contact_city", length = 100)
97 private String contactCity;
103 @Column (name = "contact_comment")
104 private String contactComment;
109 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
110 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
111 private Country contactCountry;
114 * When the contact has been created
116 @Basic (optional = false)
117 @Temporal (TemporalType.TIMESTAMP)
118 @Column (name = "contact_created", nullable = false)
119 private Calendar contactCreated;
124 @Column (name = "contact_email_address", length = 100, unique = true)
125 private String contactEmailAddress;
130 @Basic (optional = false)
131 @Column (name = "contact_family_name", length = 100, nullable = false)
132 private String contactFamilyName;
137 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
138 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
139 private DialableFaxNumber contactFaxNumber;
144 @Basic (optional = false)
145 @Column (name = "contact_first_name", length = 100, nullable = false)
146 private String contactFirstName;
151 @Column (name = "contact_house_number")
152 private Short contactHouseNumber;
155 * House number extension
157 @Column (name = "contact_house_number_extension", length = 5)
158 private String contactHouseNumberExtension;
164 @GeneratedValue (strategy = GenerationType.IDENTITY)
165 @Column (name = "contact_id", nullable = false, updatable = false)
166 private Long contactId;
171 @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true)
172 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL)
173 private DialableMobileNumber contactMobileNumber;
176 * Flag whether this contact is user's own data
178 @Basic (optional = false)
179 @Column (name = "contact_own_contact", nullable = false)
180 private Boolean contactOwnContact;
183 * Contact's personal title (Mr./Mrs.)
185 @Basic (optional = false)
186 @Column (name = "contact_personal_title", nullable = false)
187 @Enumerated (EnumType.STRING)
188 private PersonalTitle contactPersonalTitle;
193 @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true)
194 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
195 private DialableLandLineNumber contactPhoneNumber;
200 @Column (name = "contact_street")
201 private String contactStreet;
204 * Title (Doctor, etc)
206 @Column (name = "contact_title")
207 private String contactTitle;
210 * When the contact has been updated
212 @Temporal (TemporalType.TIMESTAMP)
213 @Column (name = "contact_updated")
214 private Calendar contactUpdated;
219 @Column (name = "contact_zip_code")
220 private Integer contactZipCode;
223 * Default constructor
225 public UserContact () {
226 // Default is not user's own contact
227 this.contactOwnContact = Boolean.FALSE;
231 * Constructor for title and names
233 * @param contactTitle Personal title
234 * @param contactFirstName First name
235 * @param contactFamilyName Family name
237 public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) {
238 // Call default constructor
242 this.contactPersonalTitle = contactTitle;
243 this.contactFirstName = contactFirstName;
244 this.contactFamilyName = contactFamilyName;
248 public boolean equals (final Object object) {
249 if (this == object) {
251 } else if (null == object) {
253 } else if (this.getClass() != object.getClass()) {
255 } else if (!(object instanceof Contact)) {
256 // Not correct interface
260 final Contact other = (Contact) object;
262 if (!Objects.equals(this.getContactId(), other.getContactId())) {
264 } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) {
266 } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) {
268 } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) {
270 } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) {
272 } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) {
274 } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) {
276 } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) {
278 } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
280 } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) {
282 } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
284 } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) {
292 @SuppressWarnings ("ReturnOfDateField")
293 public Date getContactBirthday () {
294 return this.contactBirthday;
298 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
299 public void setContactBirthday (final Date contactBirthday) {
300 this.contactBirthday = contactBirthday;
304 public String getContactCity () {
305 return this.contactCity;
309 public void setContactCity (final String contactCity) {
310 this.contactCity = contactCity;
314 public String getContactComment () {
315 return this.contactComment;
319 public void setContactComment (final String contactComment) {
320 this.contactComment = contactComment;
324 public Country getContactCountry () {
325 return this.contactCountry;
329 public void setContactCountry (final Country contactCountry) {
330 this.contactCountry = contactCountry;
334 @SuppressWarnings ("ReturnOfDateField")
335 public Calendar getContactCreated () {
336 return this.contactCreated;
340 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
341 public void setContactCreated (final Calendar contactCreated) {
342 this.contactCreated = contactCreated;
346 public String getContactEmailAddress () {
347 return this.contactEmailAddress;
351 public void setContactEmailAddress (final String contactEmailAddress) {
352 this.contactEmailAddress = contactEmailAddress;
356 public String getContactFamilyName () {
357 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
358 return this.contactFamilyName;
362 public void setContactFamilyName (final String contactFamilyName) {
363 this.contactFamilyName = contactFamilyName;
367 public DialableFaxNumber getContactFaxNumber () {
368 return this.contactFaxNumber;
372 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
373 this.contactFaxNumber = contactFaxNumber;
377 public String getContactFirstName () {
378 return this.contactFirstName;
382 public void setContactFirstName (final String contactFirstName) {
383 this.contactFirstName = contactFirstName;
387 public Short getContactHouseNumber () {
388 return this.contactHouseNumber;
392 public void setContactHouseNumber (final Short contactHouseNumber) {
393 this.contactHouseNumber = contactHouseNumber;
397 public String getContactHouseNumberExtension () {
398 return this.contactHouseNumberExtension;
402 public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
403 this.contactHouseNumberExtension = contactHouseNumberExtension;
407 public Long getContactId () {
408 return this.contactId;
412 public void setContactId (final Long contactId) {
413 this.contactId = contactId;
417 public DialableLandLineNumber getContactLandLineNumber () {
418 return this.contactPhoneNumber;
422 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
423 this.contactPhoneNumber = contactPhoneNumber;
427 public DialableMobileNumber getContactMobileNumber () {
428 return this.contactMobileNumber;
432 public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) {
433 this.contactMobileNumber = contactMobileNumber;
437 public void setContactOwnContact (final Boolean contactOwnContact) {
438 this.contactOwnContact = contactOwnContact;
442 public PersonalTitle getContactPersonalTitle () {
443 return this.contactPersonalTitle;
447 public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) {
448 this.contactPersonalTitle = contactPersonalTitle;
452 public String getContactStreet () {
453 return this.contactStreet;
457 public void setContactStreet (final String contactStreet) {
458 this.contactStreet = contactStreet;
462 public String getContactTitle () {
463 return this.contactTitle;
467 public void setContactTitle (final String contactTitle) {
468 this.contactTitle = contactTitle;
472 @SuppressWarnings ("ReturnOfDateField")
473 public Calendar getContactUpdated () {
474 return this.contactUpdated;
478 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
479 public void setContactUpdated (final Calendar contactUpdated) {
480 this.contactUpdated = contactUpdated;
484 public Integer getContactZipCode () {
485 return this.contactZipCode;
489 public void setContactZipCode (final Integer contactZipCode) {
490 this.contactZipCode = contactZipCode;
494 public int hashCode () {
497 hash = 29 * hash + Objects.hashCode(this.getContactBirthday());
498 hash = 29 * hash + Objects.hashCode(this.getContactCity());
499 hash = 29 * hash + Objects.hashCode(this.getContactCountry());
500 hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress());
501 hash = 29 * hash + Objects.hashCode(this.getContactFamilyName());
502 hash = 29 * hash + Objects.hashCode(this.getContactFirstName());
503 hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle());
504 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber());
505 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension());
506 hash = 29 * hash + Objects.hashCode(this.getContactId());
507 hash = 29 * hash + Objects.hashCode(this.getContactStreet());
508 hash = 29 * hash + Objects.hashCode(this.getContactTitle());
514 public Boolean isOwnContact () {
515 return this.contactOwnContact;