]> git.mxchange.org Git - jcontacts-core.git/blobdiff - src/org/mxchange/jcontacts/contact/UserContact.java
check on user instance
[jcontacts-core.git] / src / org / mxchange / jcontacts / contact / UserContact.java
index b1daf29b463fe388f1b192694e929bd5e749fee3..b176ccf1c526581e2a90357a4a5bfab022c292d8 100644 (file)
@@ -19,7 +19,6 @@ package org.mxchange.jcontacts.contact;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -32,6 +31,8 @@ import javax.persistence.Id;
 import javax.persistence.Index;
 import javax.persistence.JoinColumn;
 import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
@@ -67,7 +68,15 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
                        )
                }
 )
-public class UserContact implements Contact, Comparable<Contact> {
+@NamedQueries (
+               {
+                       @NamedQuery( name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"),
+                       @NamedQuery( name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
+                       @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactCellphoneNumber = :cellPhone ORDER BY c.contactId ASC"),
+                       @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId")
+               }
+)
+public class UserContact implements Contact {
 
        /**
         * Serial number
@@ -165,7 +174,7 @@ public class UserContact implements Contact, Comparable<Contact> {
         */
        @Id
        @GeneratedValue (strategy = GenerationType.IDENTITY)
-       @Column (name = "contact_id", length = 20, nullable = false, updatable = false)
+       @Column (name = "contact_id", nullable = false, updatable = false)
        private Long contactId;
 
        /**
@@ -209,6 +218,17 @@ public class UserContact implements Contact, Comparable<Contact> {
        @Column (name = "contact_zip_code", nullable = false, length = 6)
        private Integer contactZipCode;
 
+       /**
+        * Default constructor
+        */
+       public UserContact () {
+               // Default is not user's own contact
+               this.contactOwnContact = Boolean.FALSE;
+
+               // Unknown gender
+               this.contactGender = Gender.UNKNOWN;
+       }
+
        /**
         * Constructor for contactGender and names
         * <p>
@@ -217,7 +237,7 @@ public class UserContact implements Contact, Comparable<Contact> {
         * @param contactFamilyName Family name
         */
        public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
-               // Call other constructor
+               // Call default constructor
                this();
 
                // Set all
@@ -226,36 +246,14 @@ public class UserContact implements Contact, Comparable<Contact> {
                this.contactFamilyName = contactFamilyName;
        }
 
-       /**
-        * Default constructor
-        */
-       public UserContact () {
-               // Default is not user's own contact
-               this.contactOwnContact = Boolean.FALSE;
-       }
-
        @Override
-       public int compareTo (final Contact contact) {
-               // contact should not be null
+       public void copyAll (final Contact contact) {
+               // Contact should be valid
                if (null == contact) {
+                       // Throw NPE
                        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;
-       }
-
-       @Override
-       public void copyAll (final Contact contact) {
                // Copy all:
                // - base data
                this.setContactFirstName(contact.getContactFirstName());
@@ -495,15 +493,6 @@ public class UserContact implements Contact, Comparable<Contact> {
                this.contactZipCode = contactZipCode;
        }
 
-       /**
-        * Initialization with fake contactGender UNKNOWN
-        */
-       @PostConstruct
-       public void init () {
-               // Fake contactGender
-               this.contactGender = Gender.UNKNOWN;
-       }
-
        @Override
        public Boolean isOwnContact () {
                return this.contactOwnContact;