/******************************************************************************* * Copyright 2012 Christian Ternes and Thorsten Volland * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package org.businessmanager.domain; import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; 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.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.businessmanager.i18n.ResourceBundleAccessor; import org.hibernate.search.annotations.Analyze; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Store; @Entity @Table(name = "CONTACT_ITEM") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING, length = 20) @Indexed public abstract class ContactItem implements HasDefault { public enum Scope { PRIVATE("scope_private"), COMMERCIAL("scope_commercial"), MISC( "scope_misc"); private String label; private Scope(String label) { this.label = label; } public String getLabel() { return ResourceBundleAccessor.getString(label); } } @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column @Enumerated(EnumType.STRING) private Scope scope; @Column @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private String value; @Column private Boolean isDefault; @ManyToOne(targetEntity = Contact.class) private Contact contact; public ContactItem() {} public ContactItem(Long id, Scope scope, String value, Boolean isDefault) { this.id = id; this.scope = scope; this.value = value; this.isDefault = isDefault; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Scope getScope() { return scope; } public void setScope(Scope scope) { this.scope = scope; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public Contact getContact() { return contact; } public void setContact(Contact contact) { this.contact = contact; } public Boolean getIsDefault() { return isDefault; } public void setIsDefault(Boolean isDefault) { this.isDefault = isDefault; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.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; ContactItem other = (ContactItem) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }