package won.protocol.model;

import javax.persistence.*;
import java.net.URI;
import java.util.Objects;

@Entity
@Table(name = "socket", indexes = { @Index(name = "IDX_UNIQUE_SOCKET", columnList = "socketURI") })
public class Socket {
    @Id
    @GeneratedValue
    @Column(name = "id")
    private Long id;
    /* The uri of the socket's atom object */
    @Column(name = "atomURI")
    @Convert(converter = URIConverter.class)
    private URI atomURI;
    /* The uri of the socket's type */
    @Column(name = "typeURI")
    @Convert(converter = URIConverter.class)
    private URI typeURI;
    /* The uri of the socket - must be defined in the atom's content */
    @Column(name = "socketURI")
    @Convert(converter = URIConverter.class)
    private URI socketURI;
    @Column(name = "defaultSocket")
    @Convert(converter = BooleanTFConverter.class)
    private boolean isDefaultSocket = false;

    public Long getId() {
        return id;
    }

    public URI getAtomURI() {
        return atomURI;
    }

    public void setAtomURI(URI atomURI) {
        this.atomURI = atomURI;
    }

    public URI getTypeURI() {
        return typeURI;
    }

    public void setTypeURI(URI typeURI) {
        this.typeURI = typeURI;
    }

    public URI getSocketURI() {
        return socketURI;
    }

    public void setSocketURI(URI socketURI) {
        this.socketURI = socketURI;
    }

    public boolean isDefaultSocket() {
        return isDefaultSocket;
    }

    public void setDefaultSocket(boolean isDefaultSocket) {
        this.isDefaultSocket = isDefaultSocket;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Socket socket = (Socket) o;
        if (!Objects.equals(id, socket.id))
            return false;
        if (!Objects.equals(atomURI, socket.atomURI))
            return false;
        return Objects.equals(typeURI, socket.typeURI);
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (atomURI != null ? atomURI.hashCode() : 0);
        result = 31 * result + (typeURI != null ? typeURI.hashCode() : 0);
        return result;
    }
}

@@ -685,24 +685,42 @@
  %22socketURI%22
+, nullable = false
 )%0A    @Conve
@@ -1626,140 +1626,163 @@
 lic 
-boolean equals(Object o) %7B%0A        if (this == o)%0A            return true;%0A        if (o == null %7C%7C getClass() != o.getClass())%0A    
+int hashCode() %7B%0A        final int prime = 31;%0A        int result = 1;%0A        result = prime * result + ((socketURI == null) ? 0 : socketURI.hashCode());%0A
     
@@ -1796,302 +1796,312 @@
 urn 
-false
+result
 ;%0A    
+%7D%0A%0A
     
-Socket socket = (Socket) o;%0A        if (!Objects.equals(id, socket.id))%0A            return false;%0A        if (!Objects.equals(atomURI, socket.atomURI))%0A            return false;%0A        return Objects.equals(typeURI, socket.typeURI)
+@Override%0A    public boolean equals(Object obj) %7B%0A        if (this == obj)%0A            return true;%0A        if (obj == null)%0A            return false;%0A        if (getClass() != obj.getClass())%0A            return false;%0A        Socket other = (Socket) obj
 ;%0A    
-%7D%0A%0A
     
-@Override%0A    public int hashCode(
+if (socketURI == null
 ) %7B%0A
@@ -2112,201 +2112,150 @@
     
+  
-int result = id != null ? id.hashCode() : 0;%0A        result = 31 * result + (atomURI != null ? atomURI.hashCode() : 0);%0A        result = 31 * result + (typeURI != null ? typeURI.hashCode() : 0)
+  if (other.socketURI != null)%0A                return false;%0A        %7D else if (!socketURI.equals(other.socketURI))%0A            return false
 ;%0A  
@@ -2259,32 +2259,30 @@
 %0A        return 
-result
+true
 ;%0A    %7D%0A%7D%0A

Fix Socket's equals method