2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jphone.phonenumbers.landline;
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import org.mxchange.jcountry.data.Country;
36 import org.mxchange.jcountry.data.CountryData;
39 * A POJO for dialable phone numbers
41 * @author Roland Haeder<roland@mxchange.org>
43 @Entity (name = "phone_numbers")
44 @Table (name = "phone_numbers")
46 @NamedQuery (name = "SearchLandLineId", query = "SELECT p FROM phone_numbers AS p WHERE p.phoneId = :phoneId")
48 public class LandLineNumber implements DialableLandLineNumber {
53 private static final long serialVersionUID = 18_563_748_781_956L;
56 * Area code (example: 2151 for Krefeld)
58 @Basic (optional = false)
59 @Column (name = "phone_area_code", length = 10, nullable = false)
60 private Integer phoneAreaCode;
63 * Connection to table "country_data"
65 @JoinColumn (name = "phone_country_id", nullable = false, updatable = false)
66 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
67 private Country phoneCountry;
70 * Timestamp when this entry has been created
72 @Basic (optional = false)
73 @Temporal (TemporalType.TIMESTAMP)
74 @Column (name = "phone_entry_created", nullable = false, updatable = false)
75 private Calendar phoneEntryCreated;
81 @GeneratedValue (strategy = GenerationType.IDENTITY)
82 @Column (name = "phone_id", length = 10, nullable = false, updatable = false)
86 * Phone number with out dial prefix
88 @Basic (optional = false)
89 @Column (name = "phone_number", nullable = false)
90 private Long phoneNumber;
95 public LandLineNumber () {
99 * Constructor with country instance, area code and number
101 * @param phoneCountry Country instance
102 * @param phoneAreaCode Phone area code
103 * @param phoneNumber Phone number
105 public LandLineNumber (final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
106 // Call default constructor
110 this.phoneCountry = phoneCountry;
111 this.phoneAreaCode = phoneAreaCode;
112 this.phoneNumber = phoneNumber;
116 public void copyAll (final DialableLandLineNumber sourceNumber) {
118 this.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
119 this.setPhoneCountry(sourceNumber.getPhoneCountry());
120 this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated());
121 this.setPhoneId(sourceNumber.getPhoneId());
122 this.setPhoneNumber(sourceNumber.getPhoneNumber());
126 public boolean equals (final Object object) {
127 if (null == object) {
129 } else if (this.getClass() != object.getClass()) {
133 final DialableLandLineNumber other = (DialableLandLineNumber) object;
135 if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
137 } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
139 } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
147 public int hashCode () {
149 hash = 47 * hash + Objects.hashCode(this.getPhoneNumber());
150 hash = 47 * hash + Objects.hashCode(this.getPhoneAreaCode());
151 hash = 47 * hash + Objects.hashCode(this.getPhoneCountry());
156 public Integer getPhoneAreaCode () {
157 return this.phoneAreaCode;
161 public void setPhoneAreaCode (final Integer phoneAreaCode) {
162 this.phoneAreaCode = phoneAreaCode;
166 public Country getPhoneCountry () {
167 return this.phoneCountry;
171 public void setPhoneCountry (final Country phoneCountry) {
172 this.phoneCountry = phoneCountry;
176 public Calendar getPhoneEntryCreated () {
177 return this.phoneEntryCreated;
181 public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
182 this.phoneEntryCreated = phoneEntryCreated;
186 public Long getPhoneId () {
191 public void setPhoneId (final Long phoneId) {
192 this.phoneId = phoneId;
196 public Long getPhoneNumber () {
197 return this.phoneNumber;
201 public void setPhoneNumber (final Long phoneNumber) {
202 this.phoneNumber = phoneNumber;