package ua.avk.rest.entity;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author Alex Kononenko
 * @version 1.0.0
 *
 * The contact entity.
 */
@Entity

@NamedQueries({
        @NamedQuery(name = Contact.GET_CONTACT_BY_REGEXP_QUERY, query = "select c from Contact c where c.id = :id"),
        @NamedQuery(name = Contact.GET_CONTACT_BY_LIMIT, query = "select c from Contact c  where c.id >= :id and c.id < :counter"),
        @NamedQuery(name = Contact.GET_ALL_CONTACT_FROM_DATABASE_QUERY, query = "select c from Contact c")
})

@Table(name="CONTACT")
public class Contact implements Serializable{
    private static final long serialVersionUID = -11111110000001L;
    public static final String GET_ALL_CONTACT_FROM_DATABASE_QUERY = "getAllContactFromDatabase";
    public static final String GET_CONTACT_BY_REGEXP_QUERY = "getUserByLogin";
    public static final String GET_CONTACT_BY_LIMIT = "getContactByLimit";

    @Id
    //@GeneratedValue(strategy = GenerationType.TABLE)
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    @Column(name = "ID", unique = true, nullable = false, length = 25)
    private long id;

    @Column(name = "NAME", unique = false, nullable = false, length = 25)
    private String name;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * The method create copy object of the contact
     *
     * @param contact - the object of the contact
     */
    public void copy(Contact contact) {
        this.setName(contact.getName());
    }

    /**
     * Override hashCode for correct work equals
     *
     * @return hashCode
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(). // two randomly chosen prime numbers
                // if deriving: appendSuper(super.hashCode()).
                append(this.name).
                toHashCode();
    }

    /**
     * Compares of the contact
     *
     * @param obj for compare
     * @return true if equals
     */
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Contact))
            return false;
        if (obj == this)
            return true;

        Contact contact = (Contact) obj;
        return new EqualsBuilder().
                // if deriving: appendSuper(super.equals(obj)).
                append(this.name, contact.name).
                isEquals();
    }


}

@@ -304,20 +304,43 @@
 .0.0%0D%0A *
-%0D%0A *
+          %3Cp/%3E%0D%0A *         
  The con
@@ -762,17 +762,19 @@
 ble(name
-=
+ = 
 %22CONTACT
@@ -825,77 +825,10 @@
 able
+ 
 %7B
-%0D%0A    private static final long serialVersionUID = -11111110000001L;
 %0D%0A  
@@ -1084,73 +1084,83 @@
 %22;%0D%0A
-%0D%0A
     
-@Id%0D%0A    //@GeneratedValue(
+private 
 st
-r
 at
-egy = GenerationType.TABLE)
+ic final long serialVersionUID = -11111110000001L;%0D%0A    @Id
 %0D%0A  
@@ -2137,109 +2137,8 @@
 r().
- // two randomly chosen prime numbers%0D%0A                // if deriving: appendSuper(super.hashCode()).
 %0D%0A  
@@ -2425,16 +2425,18 @@
 ontact))
+ %7B
 %0D%0A      
@@ -2452,24 +2452,35 @@
 urn false;%0D%0A
+        %7D%0D%0A
         if (
@@ -2491,16 +2491,18 @@
 == this)
+ %7B
 %0D%0A      
@@ -2520,16 +2520,27 @@
 n true;%0D
+%0A        %7D%0D
 %0A%0D%0A     
@@ -2617,73 +2617,8 @@
 ).%0D%0A
-                // if deriving: appendSuper(super.equals(obj)).%0D%0A
     

Update Contact.java