X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcontacts%2Fcontact%2FUserContact.java;h=51b094709340787b80acb49fc9806c72151e0fda;hb=8d105e1772dbb9a46bc59972fd54421a9e2b0632;hp=bb003eebaaac0103ec22c37ca7aa1619a66fea59;hpb=8f2a3ab722709c074070a2c7d8ea9c540e44d1a7;p=jcontacts-core.git
diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java
index bb003ee..51b0947 100644
--- a/src/org/mxchange/jcontacts/contact/UserContact.java
+++ b/src/org/mxchange/jcontacts/contact/UserContact.java
@@ -19,20 +19,20 @@ 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;
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 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;
@@ -48,7 +48,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 +68,13 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
)
}
)
-public class UserContact implements Contact, Comparable {
+@NamedQueries (
+ {
+ @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
@@ -92,7 +98,7 @@ public class UserContact implements Contact, Comparable {
/**
* City
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@Column (name = "contact_city", nullable = false, length = 100)
private String contactCity;
@@ -107,7 +113,7 @@ public class UserContact implements Contact, Comparable {
* Country code
*/
@JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
- @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.MERGE, optional = false, fetch = FetchType.EAGER)
+ @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
private Country contactCountry;
/**
@@ -121,7 +127,7 @@ public class UserContact implements Contact, Comparable {
/**
* Email address
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@Column (name = "contact_email_address", length = 100, nullable = false)
private String contactEmailAddress;
@@ -157,7 +163,7 @@ public class UserContact implements Contact, Comparable {
/**
* House number
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@Column (name = "contact_house_number", length = 5, nullable = false)
private Short contactHouseNumber;
@@ -166,13 +172,13 @@ public class UserContact implements Contact, Comparable {
*/
@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;
/**
* Flag whether this contact is user's own data
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@Column (name = "contact_own_contact", nullable = false)
private Boolean contactOwnContact;
@@ -186,7 +192,7 @@ public class UserContact implements Contact, Comparable {
/**
* Street
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@Column (name = "contact_street", nullable = false)
private String contactStreet;
@@ -206,10 +212,21 @@ public class UserContact implements Contact, Comparable {
/**
* ZIP code
*/
- @Basic(optional = false)
+ @Basic (optional = false)
@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
*
@@ -218,7 +235,7 @@ public class UserContact implements Contact, Comparable {
* @param contactFamilyName Family name
*/
public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
- // Call other constructor
+ // Call default constructor
this();
// Set all
@@ -227,34 +244,6 @@ public class UserContact implements Contact, Comparable {
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
- 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;
- }
-
@Override
public void copyAll (final Contact contact) {
// Copy all:
@@ -496,15 +485,6 @@ public class UserContact implements Contact, Comparable {
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;