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.Date;
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.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.Index;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.Lob;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import javax.persistence.Transient;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jcountry.model.data.CountryData;
43 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
51 * A general contact class which serves as an entity.
53 * @author Roland Häder<roland@mxchange.org>
56 @Entity (name = "contacts")
61 name = "contact_personal_title",
62 columnList = "contact_personal_title"
68 @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"),
69 @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
70 @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"),
71 @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"),
72 @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"),
73 @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)")
76 @SuppressWarnings ("PersistenceUnitPresent")
77 public class UserContact implements Contact {
83 private static final long serialVersionUID = 58_744_284_981_863L;
88 @Column (name = "contact_birthday")
89 @Temporal (TemporalType.DATE)
90 private Date contactBirthday;
95 @Column (name = "contact_city", length = 100)
96 private String contactCity;
102 @Column (name = "contact_comment")
103 private String contactComment;
108 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
109 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
110 private Country contactCountry;
113 * When the contact has been created
115 @Basic (optional = false)
116 @Temporal (TemporalType.TIMESTAMP)
117 @Column (name = "contact_created", nullable = false)
118 private Date contactCreated;
123 @Column (name = "contact_email_address", length = 100, unique = true)
124 private String contactEmailAddress;
129 @Basic (optional = false)
130 @Column (name = "contact_family_name", length = 100, nullable = false)
131 private String contactFamilyName;
136 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
137 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
138 private DialableFaxNumber contactFaxNumber;
143 @Basic (optional = false)
144 @Column (name = "contact_first_name", length = 100, nullable = false)
145 private String contactFirstName;
150 @Column (name = "contact_house_number")
151 private Short contactHouseNumber;
154 * House number extension
156 @Column (name = "contact_house_number_extension", length = 5)
157 private String contactHouseNumberExtension;
163 @GeneratedValue (strategy = GenerationType.IDENTITY)
164 @Column (name = "contact_id", nullable = false, updatable = false)
165 private Long contactId;
170 @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true)
171 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL)
172 private DialableMobileNumber contactMobileNumber;
175 * Flag whether this contact is user's own data
177 @Basic (optional = false)
178 @Column (name = "contact_own_contact", nullable = false)
179 private Boolean contactOwnContact;
182 * Contact's personal title (Mr./Mrs.)
184 @Basic (optional = false)
185 @Column (name = "contact_personal_title", nullable = false)
186 @Enumerated (EnumType.STRING)
187 private PersonalTitle contactPersonalTitle;
192 @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true)
193 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
194 private DialableLandLineNumber contactPhoneNumber;
199 @Column (name = "contact_street")
200 private String contactStreet;
203 * Title (Doctor, etc)
205 @Column (name = "contact_title")
206 private String contactTitle;
209 * When the contact has been updated
211 @Temporal (TemporalType.TIMESTAMP)
212 @Column (name = "contact_updated")
213 private Date contactUpdated;
218 @Column (name = "contact_zip_code")
219 private Integer contactZipCode;
222 * Default constructor
224 public UserContact () {
225 // Default is not user's own contact
226 this.contactOwnContact = Boolean.FALSE;
230 * Constructor for title and names
232 * @param contactTitle Personal title
233 * @param contactFirstName First name
234 * @param contactFamilyName Family name
236 public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) {
237 // Call default constructor
241 this.contactPersonalTitle = contactTitle;
242 this.contactFirstName = contactFirstName;
243 this.contactFamilyName = contactFamilyName;
247 public boolean equals (final Object object) {
248 if (this == object) {
250 } else if (null == object) {
252 } else if (this.getClass() != object.getClass()) {
254 } else if (!(object instanceof Contact)) {
255 // Not correct interface
259 final Contact other = (Contact) object;
261 if (!Objects.equals(this.getContactId(), other.getContactId())) {
263 } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) {
265 } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) {
267 } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) {
269 } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) {
271 } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) {
273 } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) {
275 } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) {
277 } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
279 } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) {
281 } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
283 } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) {
291 @SuppressWarnings ("ReturnOfDateField")
292 public Date getContactBirthday () {
293 return this.contactBirthday;
297 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
298 public void setContactBirthday (final Date contactBirthday) {
299 this.contactBirthday = contactBirthday;
303 public String getContactCity () {
304 return this.contactCity;
308 public void setContactCity (final String contactCity) {
309 this.contactCity = contactCity;
313 public String getContactComment () {
314 return this.contactComment;
318 public void setContactComment (final String contactComment) {
319 this.contactComment = contactComment;
323 public Country getContactCountry () {
324 return this.contactCountry;
328 public void setContactCountry (final Country contactCountry) {
329 this.contactCountry = contactCountry;
333 @SuppressWarnings ("ReturnOfDateField")
334 public Date getContactCreated () {
335 return this.contactCreated;
339 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
340 public void setContactCreated (final Date contactCreated) {
341 this.contactCreated = contactCreated;
345 public String getContactEmailAddress () {
346 return this.contactEmailAddress;
350 public void setContactEmailAddress (final String contactEmailAddress) {
351 this.contactEmailAddress = contactEmailAddress;
355 public String getContactFamilyName () {
356 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
357 return this.contactFamilyName;
361 public void setContactFamilyName (final String contactFamilyName) {
362 this.contactFamilyName = contactFamilyName;
366 public DialableFaxNumber getContactFaxNumber () {
367 return this.contactFaxNumber;
371 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
372 this.contactFaxNumber = contactFaxNumber;
376 public String getContactFirstName () {
377 return this.contactFirstName;
381 public void setContactFirstName (final String contactFirstName) {
382 this.contactFirstName = contactFirstName;
386 public Short getContactHouseNumber () {
387 return this.contactHouseNumber;
391 public void setContactHouseNumber (final Short contactHouseNumber) {
392 this.contactHouseNumber = contactHouseNumber;
396 public String getContactHouseNumberExtension () {
397 return this.contactHouseNumberExtension;
401 public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
402 this.contactHouseNumberExtension = contactHouseNumberExtension;
406 public Long getContactId () {
407 return this.contactId;
411 public void setContactId (final Long contactId) {
412 this.contactId = contactId;
416 public DialableLandLineNumber getContactLandLineNumber () {
417 return this.contactPhoneNumber;
421 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
422 this.contactPhoneNumber = contactPhoneNumber;
426 public DialableMobileNumber getContactMobileNumber () {
427 return this.contactMobileNumber;
431 public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) {
432 this.contactMobileNumber = contactMobileNumber;
436 public void setContactOwnContact (final Boolean contactOwnContact) {
437 this.contactOwnContact = contactOwnContact;
441 public PersonalTitle getContactPersonalTitle () {
442 return this.contactPersonalTitle;
446 public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) {
447 this.contactPersonalTitle = contactPersonalTitle;
451 public String getContactStreet () {
452 return this.contactStreet;
456 public void setContactStreet (final String contactStreet) {
457 this.contactStreet = contactStreet;
461 public String getContactTitle () {
462 return this.contactTitle;
466 public void setContactTitle (final String contactTitle) {
467 this.contactTitle = contactTitle;
471 @SuppressWarnings ("ReturnOfDateField")
472 public Date getContactUpdated () {
473 return this.contactUpdated;
477 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
478 public void setContactUpdated (final Date contactUpdated) {
479 this.contactUpdated = contactUpdated;
483 public Integer getContactZipCode () {
484 return this.contactZipCode;
488 public void setContactZipCode (final Integer contactZipCode) {
489 this.contactZipCode = contactZipCode;
493 public int hashCode () {
496 hash = 29 * hash + Objects.hashCode(this.getContactBirthday());
497 hash = 29 * hash + Objects.hashCode(this.getContactCity());
498 hash = 29 * hash + Objects.hashCode(this.getContactCountry());
499 hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress());
500 hash = 29 * hash + Objects.hashCode(this.getContactFamilyName());
501 hash = 29 * hash + Objects.hashCode(this.getContactFirstName());
502 hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle());
503 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber());
504 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension());
505 hash = 29 * hash + Objects.hashCode(this.getContactId());
506 hash = 29 * hash + Objects.hashCode(this.getContactStreet());
507 hash = 29 * hash + Objects.hashCode(this.getContactTitle());
513 public Boolean isOwnContact () {
514 return this.contactOwnContact;