2 * Copyright (C) 2016, 2017 Free Software Foundation
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 = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)")
75 @SuppressWarnings ("PersistenceUnitPresent")
76 public class UserContact implements Contact {
82 private static final long serialVersionUID = 58_744_284_981_863L;
87 @Column (name = "contact_birthday")
88 @Temporal (TemporalType.DATE)
89 private Date contactBirthday;
94 @Column (name = "contact_city", length = 100)
95 private String contactCity;
101 @Column (name = "contact_comment")
102 private String contactComment;
107 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
108 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
109 private Country contactCountry;
112 * When the contact has been created
114 @Basic (optional = false)
115 @Temporal (TemporalType.TIMESTAMP)
116 @Column (name = "contact_created", nullable = false)
117 private Date contactCreated;
122 @Column (name = "contact_email_address", length = 100, unique = true)
123 private String contactEmailAddress;
128 @Basic (optional = false)
129 @Column (name = "contact_family_name", length = 100, nullable = false)
130 private String contactFamilyName;
135 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
136 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
137 private DialableFaxNumber contactFaxNumber;
142 @Basic (optional = false)
143 @Column (name = "contact_first_name", length = 100, nullable = false)
144 private String contactFirstName;
149 @Column (name = "contact_house_number")
150 private Short contactHouseNumber;
153 * House number extension
155 @Column (name = "contact_house_number_extension", length = 5)
156 private String contactHouseNumberExtension;
162 @GeneratedValue (strategy = GenerationType.IDENTITY)
163 @Column (name = "contact_id", nullable = false, updatable = false)
164 private Long contactId;
169 @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true)
170 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL)
171 private DialableMobileNumber contactMobileNumber;
174 * Flag whether this contact is user's own data
176 @Basic (optional = false)
177 @Column (name = "contact_own_contact", nullable = false)
178 private Boolean contactOwnContact;
181 * Contact's personal title (Mr./Mrs.)
183 @Basic (optional = false)
184 @Column (name = "contact_personal_title", nullable = false)
185 @Enumerated (EnumType.STRING)
186 private PersonalTitle contactPersonalTitle;
191 @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true)
192 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
193 private DialableLandLineNumber contactPhoneNumber;
198 @Column (name = "contact_street")
199 private String contactStreet;
202 * Title (Doctor, etc)
204 @Column (name = "contact_title")
205 private String contactTitle;
208 * When the contact has been updated
210 @Temporal (TemporalType.TIMESTAMP)
211 @Column (name = "contact_updated")
212 private Date contactUpdated;
217 @Column (name = "contact_zip_code")
218 private Integer contactZipCode;
221 * Default constructor
223 public UserContact () {
224 // Default is not user's own contact
225 this.contactOwnContact = Boolean.FALSE;
229 * Constructor for title and names
231 * @param contactTitle Personal title
232 * @param contactFirstName First name
233 * @param contactFamilyName Family name
235 public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) {
236 // Call default constructor
240 this.contactPersonalTitle = contactTitle;
241 this.contactFirstName = contactFirstName;
242 this.contactFamilyName = contactFamilyName;
246 public boolean equals (final Object object) {
247 if (this == object) {
249 } else if (null == object) {
251 } else if (this.getClass() != object.getClass()) {
253 } else if (!(object instanceof Contact)) {
254 // Not correct interface
258 final Contact other = (Contact) object;
260 if (!Objects.equals(this.getContactId(), other.getContactId())) {
262 } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) {
264 } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) {
266 } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) {
268 } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) {
270 } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) {
272 } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) {
274 } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) {
276 } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
278 } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) {
280 } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
282 } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) {
290 @SuppressWarnings ("ReturnOfDateField")
291 public Date getContactBirthday () {
292 return this.contactBirthday;
296 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
297 public void setContactBirthday (final Date contactBirthday) {
298 this.contactBirthday = contactBirthday;
302 public String getContactCity () {
303 return this.contactCity;
307 public void setContactCity (final String contactCity) {
308 this.contactCity = contactCity;
312 public String getContactComment () {
313 return this.contactComment;
317 public void setContactComment (final String contactComment) {
318 this.contactComment = contactComment;
322 public Country getContactCountry () {
323 return this.contactCountry;
327 public void setContactCountry (final Country contactCountry) {
328 this.contactCountry = contactCountry;
332 @SuppressWarnings ("ReturnOfDateField")
333 public Date getContactCreated () {
334 return this.contactCreated;
338 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
339 public void setContactCreated (final Date contactCreated) {
340 this.contactCreated = contactCreated;
344 public String getContactEmailAddress () {
345 return this.contactEmailAddress;
349 public void setContactEmailAddress (final String contactEmailAddress) {
350 this.contactEmailAddress = contactEmailAddress;
354 public String getContactFamilyName () {
355 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
356 return this.contactFamilyName;
360 public void setContactFamilyName (final String contactFamilyName) {
361 this.contactFamilyName = contactFamilyName;
365 public DialableFaxNumber getContactFaxNumber () {
366 return this.contactFaxNumber;
370 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
371 this.contactFaxNumber = contactFaxNumber;
375 public String getContactFirstName () {
376 return this.contactFirstName;
380 public void setContactFirstName (final String contactFirstName) {
381 this.contactFirstName = contactFirstName;
385 public Short getContactHouseNumber () {
386 return this.contactHouseNumber;
390 public void setContactHouseNumber (final Short contactHouseNumber) {
391 this.contactHouseNumber = contactHouseNumber;
395 public String getContactHouseNumberExtension () {
396 return this.contactHouseNumberExtension;
400 public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
401 this.contactHouseNumberExtension = contactHouseNumberExtension;
405 public Long getContactId () {
406 return this.contactId;
410 public void setContactId (final Long contactId) {
411 this.contactId = contactId;
415 public DialableLandLineNumber getContactLandLineNumber () {
416 return this.contactPhoneNumber;
420 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
421 this.contactPhoneNumber = contactPhoneNumber;
425 public DialableMobileNumber getContactMobileNumber () {
426 return this.contactMobileNumber;
430 public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) {
431 this.contactMobileNumber = contactMobileNumber;
435 public void setContactOwnContact (final Boolean contactOwnContact) {
436 this.contactOwnContact = contactOwnContact;
440 public PersonalTitle getContactPersonalTitle () {
441 return this.contactPersonalTitle;
445 public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) {
446 this.contactPersonalTitle = contactPersonalTitle;
450 public String getContactStreet () {
451 return this.contactStreet;
455 public void setContactStreet (final String contactStreet) {
456 this.contactStreet = contactStreet;
460 public String getContactTitle () {
461 return this.contactTitle;
465 public void setContactTitle (final String contactTitle) {
466 this.contactTitle = contactTitle;
470 @SuppressWarnings ("ReturnOfDateField")
471 public Date getContactUpdated () {
472 return this.contactUpdated;
476 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
477 public void setContactUpdated (final Date contactUpdated) {
478 this.contactUpdated = contactUpdated;
482 public Integer getContactZipCode () {
483 return this.contactZipCode;
487 public void setContactZipCode (final Integer contactZipCode) {
488 this.contactZipCode = contactZipCode;
492 public int hashCode () {
495 hash = 29 * hash + Objects.hashCode(this.getContactBirthday());
496 hash = 29 * hash + Objects.hashCode(this.getContactCity());
497 hash = 29 * hash + Objects.hashCode(this.getContactCountry());
498 hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress());
499 hash = 29 * hash + Objects.hashCode(this.getContactFamilyName());
500 hash = 29 * hash + Objects.hashCode(this.getContactFirstName());
501 hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle());
502 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber());
503 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension());
504 hash = 29 * hash + Objects.hashCode(this.getContactId());
505 hash = 29 * hash + Objects.hashCode(this.getContactStreet());
506 hash = 29 * hash + Objects.hashCode(this.getContactTitle());
512 public Boolean isOwnContact () {
513 return this.contactOwnContact;