2 * Copyright (C) 2016 Roland Haeder
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.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 org.mxchange.jcontacts.contact.gender.Gender;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jcountry.data.CountryData;
43 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
51 * A general contact class which serves as an entity.
53 * @author Roland Haeder<roland@mxchange.org>
56 @Entity (name = "contacts")
61 name = "contact_gender",
62 columnList = "contact_gender"
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.contactCellphoneNumber = :cellPhone ORDER BY c.contactId ASC"),
71 @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"),
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 {
81 private static final long serialVersionUID = 58_744_284_981_863L;
86 @Column (name = "contact_birthday")
87 @Temporal (TemporalType.DATE)
88 private Date contactBirthday;
93 @JoinColumn (name = "contact_cellphone_number_id", referencedColumnName = "cellphone_id", unique = true)
94 @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL)
95 private DialableCellphoneNumber contactCellphoneNumber;
100 @Basic (optional = false)
101 @Column (name = "contact_city", nullable = false, length = 100)
102 private String contactCity;
108 @Column (name = "contact_comment")
109 private String contactComment;
114 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
115 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
116 private Country contactCountry;
119 * When the contact has been created
121 @Basic (optional = false)
122 @Temporal (TemporalType.TIMESTAMP)
123 @Column (name = "contact_created", nullable = false)
124 private Calendar contactCreated;
129 @Column (name = "contact_email_address", length = 100, unique = true)
130 private String contactEmailAddress;
135 @Basic (optional = false)
136 @Column (name = "contact_family_name", length = 100, nullable = false)
137 private String contactFamilyName;
142 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
143 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
144 private DialableFaxNumber contactFaxNumber;
149 @Basic (optional = false)
150 @Column (name = "contact_first_name", length = 100, nullable = false)
151 private String contactFirstName;
156 @Basic (optional = false)
157 @Column (name = "contact_gender", nullable = false)
158 @Enumerated (EnumType.STRING)
159 private Gender contactGender;
164 @Basic (optional = false)
165 @Column (name = "contact_house_number", nullable = false)
166 private Short contactHouseNumber;
169 * House number extension
171 @Column (name = "contact_house_number_extension", length = 5)
172 private String contactHouseNumberExtension;
178 @GeneratedValue (strategy = GenerationType.IDENTITY)
179 @Column (name = "contact_id", nullable = false, updatable = false)
180 private Long contactId;
183 * Flag whether this contact is user's own data
185 @Basic (optional = false)
186 @Column (name = "contact_own_contact", nullable = false)
187 private Boolean contactOwnContact;
192 @JoinColumn (name = "contact_phone_number_id", referencedColumnName = "phone_id", unique = true)
193 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
194 private DialableLandLineNumber contactPhoneNumber;
199 @Basic (optional = false)
200 @Column (name = "contact_street", nullable = false)
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 @Basic (optional = false)
220 @Column (name = "contact_zip_code", nullable = false, length = 6)
221 private Integer contactZipCode;
224 * Default constructor
226 public UserContact () {
227 // Default is not user's own contact
228 this.contactOwnContact = Boolean.FALSE;
232 * Constructor for contactGender and names
234 * @param contactGender Gender instance
235 * @param contactFirstName First name
236 * @param contactFamilyName Family name
238 public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
239 // Call default constructor
243 this.contactGender = contactGender;
244 this.contactFirstName = contactFirstName;
245 this.contactFamilyName = contactFamilyName;
249 public void copyAll (final Contact contact) {
250 // Contact should be valid
251 if (null == contact) {
253 throw new NullPointerException("contact is null"); //NOI18N
258 this.setContactGender(contact.getContactGender());
259 this.setContactTitle(contact.getContactTitle());
260 this.setContactFirstName(contact.getContactFirstName());
261 this.setContactFamilyName(contact.getContactFamilyName());
262 this.setContactStreet(contact.getContactStreet());
263 this.setContactHouseNumber(contact.getContactHouseNumber());
264 this.setContactHouseNumberExtension(contact.getContactHouseNumberExtension());
265 this.setContactZipCode(contact.getContactZipCode());
266 this.setContactCity(contact.getContactCity());
267 this.setContactCountry(contact.getContactCountry());
269 // - phone, fax, email
270 this.setContactLandLineNumber(contact.getContactLandLineNumber());
271 this.setContactFaxNumber(contact.getContactFaxNumber());
272 this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
275 this.setContactBirthday(contact.getContactBirthday());
276 this.setContactComment(contact.getContactComment());
277 this.setContactCreated(contact.getContactCreated());
278 this.setContactUpdated(contact.getContactUpdated());
282 public boolean equals (final Object object) {
283 if (this == object) {
285 } else if (null == object) {
287 } else if (this.getClass() != object.getClass()) {
289 } else if (!(object instanceof Contact)) {
290 // Not correct interface
294 final Contact other = (Contact) object;
296 if (!Objects.equals(this.getContactCity(), other.getContactCity())) {
298 } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) {
300 } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) {
302 } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) {
304 } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) {
306 } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) {
308 } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) {
310 } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
312 } else if (this.getContactGender() != other.getContactGender()) {
314 } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
316 } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) {
318 } else if (!Objects.equals(this.getContactId(), other.getContactId())) {
326 @SuppressWarnings ("ReturnOfDateField")
327 public Date getContactBirthday () {
328 return this.contactBirthday;
332 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
333 public void setContactBirthday (final Date contactBirthday) {
334 this.contactBirthday = contactBirthday;
338 public DialableCellphoneNumber getContactCellphoneNumber () {
339 return this.contactCellphoneNumber;
343 public void setContactCellphoneNumber (final DialableCellphoneNumber contactCellphoneNumber) {
344 this.contactCellphoneNumber = contactCellphoneNumber;
348 public String getContactCity () {
349 return this.contactCity;
353 public void setContactCity (final String contactCity) {
354 this.contactCity = contactCity;
358 public String getContactComment () {
359 return this.contactComment;
363 public void setContactComment (final String contactComment) {
364 this.contactComment = contactComment;
368 public Country getContactCountry () {
369 return this.contactCountry;
373 public void setContactCountry (final Country contactCountry) {
374 this.contactCountry = contactCountry;
378 @SuppressWarnings ("ReturnOfDateField")
379 public Calendar getContactCreated () {
380 return this.contactCreated;
384 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
385 public void setContactCreated (final Calendar contactCreated) {
386 this.contactCreated = contactCreated;
390 public String getContactEmailAddress () {
391 return this.contactEmailAddress;
395 public void setContactEmailAddress (final String contactEmailAddress) {
396 this.contactEmailAddress = contactEmailAddress;
400 public String getContactFamilyName () {
401 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
402 return this.contactFamilyName;
406 public void setContactFamilyName (final String contactFamilyName) {
407 this.contactFamilyName = contactFamilyName;
411 public DialableFaxNumber getContactFaxNumber () {
412 return this.contactFaxNumber;
416 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
417 this.contactFaxNumber = contactFaxNumber;
421 public String getContactFirstName () {
422 return this.contactFirstName;
426 public void setContactFirstName (final String contactFirstName) {
427 this.contactFirstName = contactFirstName;
431 public Gender getContactGender () {
432 return this.contactGender;
436 public void setContactGender (final Gender contactGender) {
437 this.contactGender = contactGender;
441 public Short getContactHouseNumber () {
442 return this.contactHouseNumber;
446 public void setContactHouseNumber (final Short contactHouseNumber) {
447 this.contactHouseNumber = contactHouseNumber;
451 public String getContactHouseNumberExtension () {
452 return this.contactHouseNumberExtension;
456 public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
457 this.contactHouseNumberExtension = contactHouseNumberExtension;
461 public Long getContactId () {
462 return this.contactId;
466 public void setContactId (final Long contactId) {
467 this.contactId = contactId;
471 public DialableLandLineNumber getContactLandLineNumber () {
472 return this.contactPhoneNumber;
476 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
477 this.contactPhoneNumber = contactPhoneNumber;
481 public void setContactOwnContact (final Boolean contactOwnContact) {
482 this.contactOwnContact = contactOwnContact;
486 public String getContactStreet () {
487 return this.contactStreet;
491 public void setContactStreet (final String contactStreet) {
492 this.contactStreet = contactStreet;
496 public String getContactTitle () {
497 return this.contactTitle;
501 public void setContactTitle (final String contactTitle) {
502 this.contactTitle = contactTitle;
506 @SuppressWarnings ("ReturnOfDateField")
507 public Calendar getContactUpdated () {
508 return this.contactUpdated;
512 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
513 public void setContactUpdated (final Calendar contactUpdated) {
514 this.contactUpdated = contactUpdated;
518 public Integer getContactZipCode () {
519 return this.contactZipCode;
523 public void setContactZipCode (final Integer contactZipCode) {
524 this.contactZipCode = contactZipCode;
528 public int hashCode () {
531 hash = 29 * hash + Objects.hashCode(this.getContactBirthday());
532 hash = 29 * hash + Objects.hashCode(this.getContactCity());
533 hash = 29 * hash + Objects.hashCode(this.getContactCountry());
534 hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress());
535 hash = 29 * hash + Objects.hashCode(this.getContactFamilyName());
536 hash = 29 * hash + Objects.hashCode(this.getContactFirstName());
537 hash = 29 * hash + Objects.hashCode(this.getContactGender());
538 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber());
539 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension());
540 hash = 29 * hash + Objects.hashCode(this.getContactId());
541 hash = 29 * hash + Objects.hashCode(this.getContactStreet());
542 hash = 29 * hash + Objects.hashCode(this.getContactTitle());
548 public Boolean isOwnContact () {
549 return this.contactOwnContact;