/*
- * 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
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;
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.
* <p>
* @author Roland Haeder<roland@mxchange.org>
* @version 0.0
)
}
)
-public class UserContact implements Contact, Comparable<Contact> {
+public class UserContact implements Contact {
/**
* Serial number
/**
* 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;
@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, 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;
/**
/**
* Email address
*/
+ @Basic (optional = false)
@Column (name = "contact_email_address", length = 100, nullable = false)
private String contactEmailAddress;
/**
* 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;
/**
* 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
*/
/**
* ZIP code
*/
+ @Basic (optional = false)
@Column (name = "contact_zip_code", nullable = false, length = 6)
private Integer contactZipCode;
/**
* Constructor for contactGender and names
* <p>
- * @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;
* Default constructor
*/
public UserContact () {
- }
-
- /**
- * Compares two contacts with each other
- * <p>
- * @param contact Contact comparator
- * <p>
- * @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
this.setContactCountry(contact.getContactCountry());
// - phone, fax, email
- this.setContactPhoneNumber(contact.getContactPhoneNumber());
+ this.setContactLandLineNumber(contact.getContactLandLineNumber());
this.setContactFaxNumber(contact.getContactFaxNumber());
this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
this.setContactUpdated(contact.getContactUpdated());
}
- /**
- * Check if contacts are same or throw an exception
- * <p>
- * @param object Other possible contact class
- * <p>
- * @return Whether both contacts are same TODO Needs a lot improvements
- */
@Override
public boolean equals (final Object object) {
// Is it same type?
(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;
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;
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;
}
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;
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
*/