X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcontacts%2Fcontact%2FUserContact.java;h=3a368ba1572ff50237129dd61f03ed689f1a5864;hb=71ed253dc44c16897a3c3b4d73455c82ae4da4c9;hp=ae03a05929bf0aa3acf3bfb186c61e926abc40e8;hpb=57c7d6dc385486e3d7362394d703793de7c95cbd;p=jcontacts-core.git diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index ae03a05..3a368ba 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Roland Haeder + * Copyright (C) 2016 Roland Haeder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +26,6 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -48,7 +47,7 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; /** - * A general contact class which should only be extended. + * A general contact class which serves as an entity. *

* @author Roland Haeder * @version 0.0 @@ -68,7 +67,7 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; ) } ) -public class UserContact implements Contact, Comparable { +public class UserContact implements Contact { /** * Serial number @@ -85,13 +84,14 @@ public class UserContact implements Contact, Comparable { /** * Cellphone number */ - @JoinColumn (name = "contact_cellphone_number_id") + @JoinColumn (name = "contact_cellphone_number_id", referencedColumnName = "cellphone_id", unique = true) @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL) private DialableCellphoneNumber contactCellphoneNumber; /** * City */ + @Basic (optional = false) @Column (name = "contact_city", nullable = false, length = 100) private String contactCity; @@ -102,19 +102,11 @@ public class UserContact implements Contact, Comparable { @Column (name = "contact_comment") private String contactComment; - /** - * Id number - */ - @Id - @GeneratedValue (strategy = GenerationType.IDENTITY) - @Column (name = "contact_id", length = 20, updatable = false) - private Long contactId; - /** * Country code */ - @JoinColumn (name = "contact_country_id", nullable = false) - @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.MERGE, optional = false, fetch = FetchType.EAGER) + @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id") + @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false) private Country contactCountry; /** @@ -128,6 +120,7 @@ public class UserContact implements Contact, Comparable { /** * Email address */ + @Basic (optional = false) @Column (name = "contact_email_address", length = 100, nullable = false) private String contactEmailAddress; @@ -141,7 +134,7 @@ public class UserContact implements Contact, Comparable { /** * Fax number */ - @JoinColumn (name = "contact_fax_number_id") + @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true) @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL) private DialableFaxNumber contactFaxNumber; @@ -163,28 +156,45 @@ public class UserContact implements Contact, Comparable { /** * House number */ + @Basic (optional = false) @Column (name = "contact_house_number", length = 5, nullable = false) private Short contactHouseNumber; + /** + * Id number + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "contact_id", length = 20, nullable = false, updatable = false) + private Long contactId; + /** * Flag whether this contact is user's own data */ + @Basic (optional = false) @Column (name = "contact_own_contact", nullable = false) private Boolean contactOwnContact; /** * Phone number */ - @JoinColumn (name = "contact_phone_number_id") + @JoinColumn (name = "contact_phone_number_id", referencedColumnName = "phone_id", unique = true) @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL) private DialableLandLineNumber contactPhoneNumber; /** * Street */ + @Basic (optional = false) @Column (name = "contact_street", nullable = false) private String contactStreet; + /** + * Title (Doctor, etc) + */ + @Column (name = "contact_title") + private String contactTitle; + /** * When the contact has been updated */ @@ -195,17 +205,21 @@ public class UserContact implements Contact, Comparable { /** * ZIP code */ + @Basic (optional = false) @Column (name = "contact_zip_code", nullable = false, length = 6) private Integer contactZipCode; /** * Constructor for contactGender and names *

- * @param contactGender Gender instance - * @param contactFirstName First name + * @param contactGender Gender instance + * @param contactFirstName First name * @param contactFamilyName Family name */ public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) { + // Call other constructor + this(); + // Set all this.contactGender = contactGender; this.contactFirstName = contactFirstName; @@ -216,33 +230,8 @@ public class UserContact implements Contact, Comparable { * Default constructor */ public UserContact () { - } - - /** - * Compares two contacts with each other - *

- * @param contact Contact comparator - *

- * @return Comparison value - */ - @Override - public int compareTo (final Contact contact) { - // contact should not be null - if (null == contact) { - throw new NullPointerException("contact is null"); //NOI18N - } - - // Is the contactId the same? - if (Objects.equals(this.getContactId(), contact.getContactId())) { - // Same contactId, means same contact - return 0; - } else if (this.getContactId() > contact.getContactId()) { - // This contactId is larger than compared to - return -1; - } - - // The other contactId is larger - return 1; + // Default is not user's own contact + this.contactOwnContact = Boolean.FALSE; } @Override @@ -257,7 +246,7 @@ public class UserContact implements Contact, Comparable { this.setContactCountry(contact.getContactCountry()); // - phone, fax, email - this.setContactPhoneNumber(contact.getContactPhoneNumber()); + this.setContactLandLineNumber(contact.getContactLandLineNumber()); this.setContactFaxNumber(contact.getContactFaxNumber()); this.setContactCellphoneNumber(contact.getContactCellphoneNumber()); @@ -288,6 +277,18 @@ public class UserContact implements Contact, Comparable { (this.getContactFamilyName().toLowerCase().equals(contact.getContactFamilyName().toLowerCase()))); } + @Override + public int hashCode () { + // Validate contactGender instance + assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N + + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.getContactFamilyName()); + hash = 79 * hash + this.getContactGender().hashCode(); + hash = 79 * hash + Objects.hashCode(this.getContactFirstName()); + return hash; + } + @Override public Date getContactBirthday () { return this.contactBirthday; @@ -328,16 +329,6 @@ public class UserContact implements Contact, Comparable { this.contactComment = contactComment; } - @Override - public Long getContactId () { - return this.contactId; - } - - @Override - public void setContactId (final Long contactId) { - this.contactId = contactId; - } - @Override public Country getContactCountry () { return this.contactCountry; @@ -419,18 +410,28 @@ public class UserContact implements Contact, Comparable { this.contactHouseNumber = contactHouseNumber; } + @Override + public Long getContactId () { + return this.contactId; + } + + @Override + public void setContactId (final Long contactId) { + this.contactId = contactId; + } + @Override public void setContactOwnContact (final Boolean contactOwnContact) { this.contactOwnContact = contactOwnContact; } @Override - public DialableLandLineNumber getContactPhoneNumber () { + public DialableLandLineNumber getContactLandLineNumber () { return this.contactPhoneNumber; } @Override - public void setContactPhoneNumber (final DialableLandLineNumber contactPhoneNumber) { + public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) { this.contactPhoneNumber = contactPhoneNumber; } @@ -444,6 +445,16 @@ public class UserContact implements Contact, Comparable { this.contactStreet = contactStreet; } + @Override + public String getContactTitle () { + return this.contactTitle; + } + + @Override + public void setContactTitle (final String contactTitle) { + this.contactTitle = contactTitle; + } + @Override public Calendar getContactUpdated () { return this.contactUpdated; @@ -464,18 +475,6 @@ public class UserContact implements Contact, Comparable { this.contactZipCode = contactZipCode; } - @Override - public int hashCode () { - // Validate contactGender instance - assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N - - int hash = 7; - hash = 79 * hash + Objects.hashCode(this.getContactFamilyName()); - hash = 79 * hash + this.getContactGender().hashCode(); - hash = 79 * hash + Objects.hashCode(this.getContactFirstName()); - return hash; - } - /** * Initialization with fake contactGender UNKNOWN */