package com.demo.demo.model.obj.demo;
import com.demo.demo.model.obj.demo.Order;
import com.demo.demo.model.obj.demo.iface.ICustomer;
import com.demo.demo.services.data.DataLayerDemoImpl;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.proxy.HibernateProxy;
@Entity
@Table(name = "customer", catalog = "demo")
public class Customer implements Cloneable, Serializable, ICustomer {
private static final long serialVersionUID = -559029080L;
private Set<Order> orders = new HashSet<Order>();
private Long id = 0L;
private String name;
private String surname;
public Customer() {
}
public Customer(Long id) {
this.id = id;
}
public Customer(Long id, String name, String surname) {
this.id = id;
this.name = name;
this.surname = surname;
}
@Column( name = "customer_id", nullable = false )
@OneToMany( fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "customer" )
public Set<Order> getOrders() {
return this.orders;
}
public void addOrder(Order order) {
this.orders.add(order);
order.setCustomer(this);
}
public void setOrders(final Set<Order> order) {
this.orders = order;
}
@Id
@Column( name = "customer_id", nullable = false )
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return this.id;
}
public void setId(final Long id) {
this.id = id;
}
@Column( nullable = false, length = 45 )
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
@Column( nullable = false, length = 45 )
public String getSurname() {
return this.surname;
}
public void setSurname(final String surname) {
this.surname = surname;
}
@Override
public Customer clone() throws CloneNotSupportedException {
super.clone(); final Customer copy = new Customer();
copy.getOrders().addAll(this.getOrders());
copy.setId(this.getId());
copy.setName(this.getName());
copy.setSurname(this.getSurname());
return copy;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("id: " + this.getId() + ", ");
sb.append("name: " + this.getName() + ", ");
sb.append("surname: " + this.getSurname());
return sb.toString();
}
@Override
public boolean equals(final Object aThat) {
Object unproxyThat = aThat;
if ( this == aThat ) {
return true;
}
if (aThat instanceof HibernateProxy) {
try {
unproxyThat = DataLayerDemoImpl.getInstance().loadCustomer(((Customer)aThat).getId());
} catch (ClassCastException e) {
return false;
}
}
if ((aThat == null) || ( !(unproxyThat.getClass().equals(this.getClass())))) {
return false;
}
final Customer that = (Customer) unproxyThat;
boolean result = true;
result = result & (((this.getName() == null) && (that.getName() == null)) || (this.getName() != null && this.getName().equals(that.getName())));
result = result & (((this.getSurname() == null) && (that.getSurname() == null)) || (this.getSurname() != null && this.getSurname().equals(that.getSurname())));
return result;
}
@Override
public int hashCode() {
int result = 0;
result = 26 * result + (this.getName() == null ? 0 : this.getName().hashCode());
result = 26 * result + (this.getSurname() == null ? 0 : this.getSurname().hashCode());
return result;
}
}