package org.mxchange.jcore.model.contact;
import java.sql.Timestamp;
+import java.util.Date;
import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import org.mxchange.jcore.client.Client;
import org.mxchange.jcore.model.contact.gender.Gender;
* @author Roland Haeder<roland@mxchange.org>
* @version 0.0
*/
-public class BaseContact implements Contact, Comparable<Contact> {
+@Entity (name = "contact")
+@Table (name = "contacts")
+public abstract class BaseContact implements Contact, Comparable<Contact> {
+
/**
* Serial number
*/
private static final long serialVersionUID = 58_744_284_981_863L;
- /**
- * When the contact has been created
- */
- private Timestamp created;
-
- /**
- * Id number
- */
- private Long id;
-
/**
* Birth day
*/
- private String birthday;
+ @Column
+ @Temporal (TemporalType.DATE)
+ private Date birthday;
/**
* Cellphone number
*/
+ @Column (name = "cellphone_number", length = 100)
private String cellphoneNumber;
/**
* City
*/
+ @Column (nullable = false, length = 100)
private String city;
/**
* Optional comments
*/
+ @Lob
+ @Column
private String comment;
/**
* Company name
*/
+ @Column (name = "company_name", nullable = false)
private String companyName;
/**
* Country code
*/
+ @Column (name = "country_code", length = 2, nullable = false)
private String countryCode;
+ /**
+ * When the contact has been created
+ */
+ @Basic(optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column(nullable = false)
+ private Timestamp created;
+
/**
* Email address
*/
+ @Column (name = "email_address", length = 100, nullable = false)
private String emailAddress;
/**
* Family name
*/
+ @Basic (optional = false)
+ @Column (name = "family_name", length = 100, nullable = false)
private String familyName;
/**
* Fax number
*/
+ @Column (name = "fax_number", length = 100)
private String faxNumber;
/**
* First name
*/
+ @Basic (optional = false)
+ @Column (name = "first_name", length = 100, nullable = false)
private String firstName;
/**
* Gender instance
*/
+ @Basic (optional = false)
+ @Column (nullable = false)
private Gender gender;
/**
* House number
*/
+ @Column (name = "house_number", length = 5, nullable = false)
private Long houseNumber;
+ /**
+ * Id number
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
/**
* Flag whether this contact is user's own data
*/
- private boolean ownContact;
+ @Column (name = "own_contact", nullable = false)
+ private Boolean ownContact;
/**
* Phone number
*/
+ @Column (name = "phone_number", length = 100)
private String phoneNumber;
/**
* Street
*/
+ @Column (nullable = false)
private String street;
/**
* When the contact has been updated
*/
+ @Temporal (TemporalType.TIMESTAMP)
private Timestamp updated;
/**
* ZIP code
*/
+ @Column (name = "zip_code", nullable = false, length = 6)
private Long zipCode;
/**
* and provide proper constructors.
*/
protected BaseContact () {
- // Fake gender
- this.gender = Gender.UNKNOWN;
+ }
+
+ /**
+ * 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 id the same?
+ if (Objects.equals(this.getId(), contact.getId())) {
+ // Same id, means same contact
+ return 0;
+ } else if (this.getId() > contact.getId()) {
+ // This id is larger than compared to
+ return -1;
+ }
+
+ // The other id is larger
+ return 1;
}
/**
* Check if contacts are same or throw an exception
*
* @param object Other possible contact class
- * @return Whether both contacts are same
- * TODO Needs a lot improvements
+ * @return Whether both contacts are same TODO Needs a lot improvements
*/
@Override
public boolean equals (final Object object) {
&& (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
}
- /**
- * Birth day
- *
- * @return the birthday
- */
@Override
- public String getBirthday () {
+ public Date getBirthday () {
return this.birthday;
}
- /**
- * Birth day
- *
- * @param birthday the birthday to set
- */
@Override
- public void setBirthday (final String birthday) {
+ public void setBirthday (final Date birthday) {
this.birthday = birthday;
}
- /**
- * Cellphone number
- *
- * @return the cellphoneNumber
- */
@Override
public String getCellphoneNumber () {
return this.cellphoneNumber;
}
- /**
- * Cellphone number
- *
- * @param cellphoneNumber the cellphoneNumber to set
- */
@Override
public void setCellphoneNumber (final String cellphoneNumber) {
this.cellphoneNumber = cellphoneNumber;
}
- /**
- * City
- *
- * @return the city
- */
@Override
public String getCity () {
return this.city;
}
- /**
- * City
- *
- * @param city the city to set
- */
@Override
public void setCity (final String city) {
this.city = city;
}
- /**
- * Comments
- *
- * @return the comment
- */
@Override
public String getComment () {
return this.comment;
}
- /**
- * Comments
- *
- * @param comment the comment to set
- */
@Override
public void setComment (final String comment) {
this.comment = comment;
}
- /**
- * Company name
- *
- * @return the companyName
- */
@Override
public String getCompanyName () {
return this.companyName;
}
- /**
- * Company name
- *
- * @param companyName the companyName to set
- */
@Override
public void setCompanyName (final String companyName) {
this.companyName = companyName;
}
@Override
- public Timestamp getCreated () {
- return this.created;
- }
-
- @Override
- public void setCreated (final Timestamp created) {
- this.created = created;
- }
-
- /**
- * Id number
- * @return the id
- */
- @Override
- public Long getId () {
- return this.id;
+ public String getCountryCode () {
+ return this.countryCode;
}
- /**
- * Id number
- * @param id the id to set
- */
@Override
- public void setId (final Long id) {
- this.id = id;
+ public void setCountryCode (final String countryCode) {
+ this.countryCode = countryCode;
}
- /**
- * Country code
- *
- * @return the countryCode
- */
@Override
- public String getCountryCode () {
- return this.countryCode;
+ public Timestamp getCreated () {
+ return this.created;
}
- /**
- * Country code
- *
- * @param countryCode the countryCode to set
- */
@Override
- public void setCountryCode (final String countryCode) {
- this.countryCode = countryCode;
+ public void setCreated (final Timestamp created) {
+ this.created = created;
}
- /**
- * Email address
- *
- * @return the emailAddress
- */
@Override
public String getEmailAddress () {
return this.emailAddress;
}
- /**
- * Email address
- *
- * @param emailAddress the emailAddress to set
- */
@Override
public void setEmailAddress (final String emailAddress) {
this.emailAddress = emailAddress;
}
- /**
- * Family name
- *
- * @return the familyName
- */
@Override
public String getFamilyName () {
//* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
return this.familyName;
}
- /**
- * Family name
- *
- * @param familyName the familyName to set
- */
@Override
public void setFamilyName (final String familyName) {
this.familyName = familyName;
}
- /**
- * Fax number
- *
- * @return the faxNumber
- */
@Override
public String getFaxNumber () {
return this.faxNumber;
}
- /**
- * Fax number
- *
- * @param faxNumber the faxNumber to set
- */
@Override
public void setFaxNumber (final String faxNumber) {
this.faxNumber = faxNumber;
}
- /**
- * First name
- *
- * @return the firstName
- */
@Override
public String getFirstName () {
return this.firstName;
}
- /**
- * First name
- *
- * @param firstName the firstName to set
- */
@Override
public void setFirstName (final String firstName) {
this.firstName = firstName;
}
- /**
- * Gender of the contact
- *
- * @return the gender
- */
@Override
public Gender getGender () {
return this.gender;
}
- /**
- * Gender of the contact
- *
- * @param gender the gender to set
- */
@Override
public void setGender (final Gender gender) {
this.gender = gender;
}
- /**
- * House number
- *
- * @return the houseNumber
- */
@Override
public Long getHouseNumber () {
return this.houseNumber;
}
- /**
- * House number
- *
- * @param houseNumber the houseNumber to set
- */
@Override
public void setHouseNumber (final Long houseNumber) {
this.houseNumber = houseNumber;
}
- /**
- * Phone number
- *
- * @return the phoneNumber
- */
+ @Override
+ public Long getId () {
+ return this.id;
+ }
+
+ @Override
+ public void setId (final Long id) {
+ this.id = id;
+ }
+
+ @Override
+ public void setOwnContact (final Boolean ownContact) {
+ this.ownContact = ownContact;
+ }
+
@Override
public String getPhoneNumber () {
return this.phoneNumber;
}
- /**
- * Phone number
- *
- * @param phoneNumber the phoneNumber to set
- */
@Override
public void setPhoneNumber (final String phoneNumber) {
this.phoneNumber = phoneNumber;
}
- /**
- * Street
- *
- * @return the street
- */
@Override
public String getStreet () {
return this.street;
}
- /**
- * Street
- *
- * @param street the street to set
- */
@Override
public void setStreet (final String street) {
this.street = street;
this.updated = updated;
}
- /**
- * ZIP code
- *
- * @return the zipCode
- */
@Override
public Long getZipCode () {
return this.zipCode;
}
- /**
- * ZIP code
- *
- * @param zipCode the zipCode to set
- */
@Override
public void setZipCode (final Long zipCode) {
this.zipCode = zipCode;
return hash;
}
- /**
- * Checks whether the contact is user's own data
- *
- * @return Own data?
- */
+ @PostConstruct
+ public void init () {
+ // Fake gender
+ this.gender = Gender.UNKNOWN;
+ }
+
@Override
- public boolean isOwnContact () {
+ public Boolean isOwnContact () {
return this.ownContact;
}
/**
- * Shows this contact to the user
+ * Shows this contact to the user.
*
* @param client Client instance to use
- * TODO: Maybe needs to be moved to other class
+ * @deprecated Should not be called here
*/
+ @Deprecated
public void show (final Client client) {
// The client must be set
if (null == client) {
// Display other data "box"
client.displayOtherDataBox(this);
}
-
- @Override
- public void setOwnContact (final Boolean ownContact) {
- this.ownContact = ownContact;
- }
-
- /**
- * 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 id the same?
- if (Objects.equals(this.getId(), contact.getId())) {
- // Same id, means same contact
- return 0;
- } else if (this.getId() > contact.getId()) {
- // This id is larger than compared to
- return -1;
- }
-
- // The other id is larger
- return 1;
- }
}