Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.model;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- import org.springframework.beans.factory.annotation.Required;
- import com.google.common.base.Strings;
- @Entity
- @Table(name = "phone_contact")
- public class PhoneContact extends BaseObject {
- private static final long serialVersionUID = 3614259347370445202L;
- private Long id;
- private Customer customer;
- private String phoneNumber;
- private String phoneExtention;
- private PhoneType phoneType;
- public PhoneContact() {
- super();
- }
- public PhoneContact(PhoneType phoneType, String phoneNumber) {
- super();
- this.phoneType = phoneType;
- this.phoneNumber = phoneNumber;
- }
- public PhoneContact(PhoneType phoneType, String phoneNumber, String phoneExtention) {
- super();
- this.phoneType = phoneType;
- this.phoneNumber = phoneNumber;
- if (!Strings.isNullOrEmpty(phoneExtention)) {
- this.phoneExtention = phoneExtention;
- }
- }
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- @ManyToOne
- @Required
- public Customer getCustomer() {
- return customer;
- }
- public void setCustomer(Customer customer) {
- if (this.customer != null && !this.customer.equals(customer)) {
- throw new RuntimeException("Invalid state: Customer cannot be changed on an existing PhoneContact");
- }
- this.customer = customer;
- }
- @Column(name = "phone_number", length = 20)
- @Required
- public String getPhoneNumber() {
- return phoneNumber;
- }
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- @Column(name = "phone_extention", length = 10)
- public String getPhoneExtention() {
- return phoneExtention;
- }
- public void setPhoneExtention(String phoneExtention) {
- this.phoneExtention = phoneExtention;
- }
- @Enumerated(EnumType.STRING)
- @Column(name = "phone_type", length = 10)
- @Required
- public PhoneType getPhoneType() {
- return phoneType;
- }
- public void setPhoneType(PhoneType phoneType) {
- this.phoneType = phoneType;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((customer == null) ? 0 : customer.hashCode());
- result = prime * result + ((phoneExtention == null) ? 0 : phoneExtention.hashCode());
- result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
- result = prime * result + ((phoneType == null) ? 0 : phoneType.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PhoneContact other = (PhoneContact) obj;
- if (customer == null) {
- if (other.customer != null)
- return false;
- } else if (!customer.equals(other.customer))
- return false;
- if (phoneExtention == null) {
- if (other.phoneExtention != null)
- return false;
- } else if (!phoneExtention.equals(other.phoneExtention))
- return false;
- if (phoneNumber == null) {
- if (other.phoneNumber != null)
- return false;
- } else if (!phoneNumber.equals(other.phoneNumber))
- return false;
- if (phoneType != other.phoneType)
- return false;
- return true;
- }
- @Override
- public String toString() {
- return "PhoneContact [id=" + id + ", customer=" + (customer == null ? "null" : customer.getCustomerNumber()) + ", phoneNumber="
- + phoneNumber + ", phoneExtention=" + phoneExtention + ", phoneType=" + phoneType + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement