]> git.mxchange.org Git - jcore.git/blobdiff - src/org/mxchange/jcore/model/contact/BaseContact.java
Temporal values don't like strings, good!
[jcore.git] / src / org / mxchange / jcore / model / contact / BaseContact.java
index b02109eec86d850f94de1f9da80afee2d7f9e3de..0f163b7faf9e89ae0d610219cc3acdb7b8c7bbbe 100644 (file)
  */
 package org.mxchange.jcore.model.contact;
 
-import java.text.MessageFormat;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.Objects;
-import org.mxchange.jcore.BaseFrameworkSystem;
+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;
 
 /**
  * A general contact class which should only be extended.
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  * @version 0.0
  */
-public abstract class BaseContact extends BaseFrameworkSystem implements Contact, Comparable<Contact> {
+@Entity (name = "contact")
+@Table (name = "contacts")
+public abstract class BaseContact implements Contact, Comparable<Contact> {
 
        /**
-        * Id number
+        * Serial number
         */
-       private Long contactId;
+       private static final long serialVersionUID = 58_744_284_981_863L;
 
        /**
         * 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;
 
        /**
-        * Companyname
+        * 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 Calendar 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 Calendar updated;
+
        /**
         * ZIP code
         */
+       @Column (name = "zip_code", nullable = false, length = 6)
        private Long zipCode;
 
        /**
@@ -120,16 +175,63 @@ public abstract class BaseContact extends BaseFrameworkSystem implements Contact
         * 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;
+       }
+
+       @Override
+       public void copyAll (final Contact contact) {
+               // Copy all:
+               // - base data
+               this.setFirstName(contact.getFirstName());
+               this.setFamilyName(contact.getFamilyName());
+               this.setCompanyName(contact.getCompanyName());
+               this.setStreet(contact.getStreet());
+               this.setZipCode(contact.getZipCode());
+               this.setCity(contact.getCity());
+               this.setCountryCode(contact.getCountryCode());
+
+               // - phone, fax, email
+               this.setPhoneNumber(contact.getPhoneNumber());
+               this.setFaxNumber(contact.getFaxNumber());
+               this.setCellphoneNumber(contact.getCellphoneNumber());
+
+               // - other data
+               this.setBirthday(contact.getBirthday());
+               this.setComment(contact.getComment());
+               this.setCreated(contact.getCreated());
+               this.setUpdated(contact.getUpdated());
        }
 
        /**
         * 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) {
@@ -151,335 +253,187 @@ public abstract class BaseContact extends BaseFrameworkSystem implements Contact
                                && (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;
        }
 
-       /**
-        * Companyname
-        *
-        * @return the companyName
-        */
        @Override
        public String getCompanyName () {
                return this.companyName;
        }
 
-       /**
-        * Companyname
-        *
-        * @param companyName the companyName to set
-        */
        @Override
        public void setCompanyName (final String companyName) {
                this.companyName = companyName;
        }
 
-       /**
-        * Id number
-        * @return the contactId
-        */
        @Override
-       public Long getContactId () {
-               return this.contactId;
+       public String getCountryCode () {
+               return this.countryCode;
        }
 
-       /**
-        * Id number
-        * @param contactId the contactId to set
-        */
        @Override
-       public void setContactId (final Long contactId) {
-               this.contactId = contactId;
+       public void setCountryCode (final String countryCode) {
+               this.countryCode = countryCode;
        }
 
-       /**
-        * Country code
-        *
-        * @return the countryCode
-        */
        @Override
-       public String getCountryCode () {
-               return this.countryCode;
+       public Calendar 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 Calendar 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) {
-               /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N
                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;
        }
 
-       /**
-        * Some "getter" for a translated/human-readable gender
-        *
-        * @return gender Human-readable gender
-        */
        @Override
-       public String getTranslatedGender () {
-               // "Translate" it
-               String translated = this.getMessageStringFromKey(this.getGender().getMessageKey());
+       public Calendar getUpdated () {
+               return this.updated;
+       }
 
-               // Return it
-               return translated;
+       @Override
+       public void setUpdated (final Calendar updated) {
+               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;
@@ -497,26 +451,25 @@ public abstract class BaseContact extends BaseFrameworkSystem implements Contact
                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
+        * @deprecated Should not be called here
         */
-       @Override
+       @Deprecated
        public void show (final Client client) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
-
                // The client must be set
                if (null == client) {
                        // Not set
@@ -532,44 +485,4 @@ public abstract class BaseContact extends BaseFrameworkSystem implements Contact
                // Display other data "box"
                client.displayOtherDataBox(this);
        }
-
-       /**
-        * Enables the flag "own data" which signals that this contact is the user's
-        * own data.
-        */
-       protected void enableFlagOwnContact () {
-               this.ownContact = true;
-       }
-
-       /**
-        * Compares two contacts with each other
-        *
-        * @param contact Contact comparator
-        * @return Comparison value
-        */
-       @Override
-       public int compareTo (final Contact contact) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
-               
-               // contact should not be null
-               if (null == contact) {
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("this.id={0},contact.id={1}", this.getContactId(), contact.getContactId())); //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;
-       }
 }